From 74392915034746111d5a0329bd76ce59cd80966a Mon Sep 17 00:00:00 2001 From: Charles Korn Date: Mon, 18 Nov 2024 15:53:24 +1100 Subject: [PATCH] Fix issue where comparison operations with `bool` modifier and native histograms return histograms rather than 0 or 1 Signed-off-by: Charles Korn --- promql/engine.go | 1 + promql/promqltest/testdata/operators.test | 123 ++++++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/promql/engine.go b/promql/engine.go index 5e0539d8f..8f8206e41 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -2610,6 +2610,7 @@ func (ev *evaluator) VectorBinop(op parser.ItemType, lhs, rhs Vector, matching * } switch { case returnBool: + histogramValue = nil if keep { floatValue = 1.0 } else { diff --git a/promql/promqltest/testdata/operators.test b/promql/promqltest/testdata/operators.test index 9070953ab..52457a5fd 100644 --- a/promql/promqltest/testdata/operators.test +++ b/promql/promqltest/testdata/operators.test @@ -508,3 +508,126 @@ eval instant at 1m 10 atan2 20 eval instant at 1m 10 atan2 NaN NaN + +clear + +load 6m + left_floats 1 2 _ _ 3 stale 4 5 NaN Inf -Inf + right_floats 4 _ _ 5 3 7 -1 20 NaN Inf -Inf + left_histograms {{schema:3 sum:4 count:4 buckets:[1 2 1]}} {{schema:3 sum:4.5 count:5 buckets:[1 3 1]}} _ _ {{schema:3 sum:4.5 count:5 buckets:[1 3 1]}} + right_histograms {{schema:3 sum:4 count:4 buckets:[1 2 1]}} {{schema:3 sum:4 count:4 buckets:[1 2 1]}} {{schema:3 sum:4 count:4 buckets:[1 2 1]}} _ _ + right_floats_for_histograms 0 -1 2 3 4 + +# Vector/vector combinations +eval range from 0 to 60m step 6m left_floats == right_floats + left_floats _ _ _ _ 3 _ _ _ _ Inf -Inf + +eval range from 0 to 60m step 6m left_floats == bool right_floats + {} 0 _ _ _ 1 _ 0 0 0 1 1 + +eval range from 0 to 60m step 6m left_floats == does_not_match + # No results. + +eval range from 0 to 24m step 6m left_histograms == right_histograms + left_histograms {{schema:3 sum:4 count:4 buckets:[1 2 1]}} _ _ _ _ + +eval range from 0 to 24m step 6m left_histograms == bool right_histograms + {} 1 0 _ _ _ + +eval range from 0 to 24m step 6m left_histograms == right_floats_for_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms == bool right_floats_for_histograms + {} 0 0 _ _ 0 + +eval range from 0 to 60m step 6m left_floats != right_floats + left_floats 1 _ _ _ _ _ 4 5 NaN _ _ + +eval range from 0 to 60m step 6m left_floats != bool right_floats + {} 1 _ _ _ 0 _ 1 1 1 0 0 + +eval range from 0 to 24m step 6m left_histograms != right_histograms + left_histograms _ {{schema:3 sum:4.5 count:5 buckets:[1 3 1]}} _ _ _ + +eval range from 0 to 24m step 6m left_histograms != bool right_histograms + {} 0 1 _ _ _ + +eval range from 0 to 24m step 6m left_histograms != right_floats_for_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms != bool right_floats_for_histograms + {} 0 0 _ _ 0 + +eval range from 0 to 60m step 6m left_floats > right_floats + left_floats _ _ _ _ _ _ 4 _ _ _ _ + +eval range from 0 to 60m step 6m left_floats > bool right_floats + {} 0 _ _ _ 0 _ 1 0 0 0 0 + +eval range from 0 to 24m step 6m left_histograms > right_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms > bool right_histograms + {} 0 0 _ _ _ + +eval range from 0 to 24m step 6m left_histograms > right_floats_for_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms > bool right_floats_for_histograms + {} 0 0 _ _ 0 + +eval range from 0 to 60m step 6m left_floats >= right_floats + left_floats _ _ _ _ 3 _ 4 _ _ Inf -Inf + +eval range from 0 to 60m step 6m left_floats >= bool right_floats + {} 0 _ _ _ 1 _ 1 0 0 1 1 + +eval range from 0 to 24m step 6m left_histograms >= right_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms >= bool right_histograms + {} 0 0 _ _ _ + +eval range from 0 to 24m step 6m left_histograms >= right_floats_for_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms >= bool right_floats_for_histograms + {} 0 0 _ _ 0 + +eval range from 0 to 60m step 6m left_floats < right_floats + left_floats 1 _ _ _ _ _ _ 5 _ _ _ + +eval range from 0 to 60m step 6m left_floats < bool right_floats + {} 1 _ _ _ 0 _ 0 1 0 0 0 + +eval range from 0 to 24m step 6m left_histograms < right_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms < bool right_histograms + {} 0 0 _ _ _ + +eval range from 0 to 24m step 6m left_histograms < right_floats_for_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms < bool right_floats_for_histograms + {} 0 0 _ _ 0 + +eval range from 0 to 60m step 6m left_floats <= right_floats + left_floats 1 _ _ _ 3 _ _ 5 _ Inf -Inf + +eval range from 0 to 60m step 6m left_floats <= bool right_floats + {} 1 _ _ _ 1 _ 0 1 0 1 1 + +eval range from 0 to 24m step 6m left_histograms <= right_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms <= bool right_histograms + {} 0 0 _ _ _ + +eval range from 0 to 24m step 6m left_histograms <= right_floats_for_histograms + # No results. + +eval range from 0 to 24m step 6m left_histograms <= bool right_floats_for_histograms + {} 0 0 _ _ 0 + +clear