Skip to content

Commit

Permalink
Fix issue where comparison operations with bool modifier and native…
Browse files Browse the repository at this point in the history
… histograms return histograms rather than 0 or 1

Signed-off-by: Charles Korn <[email protected]>
  • Loading branch information
charleskorn committed Nov 18, 2024
1 parent 101b1c3 commit 7439291
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
123 changes: 123 additions & 0 deletions promql/promqltest/testdata/operators.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7439291

Please sign in to comment.