Skip to content

Commit 296b90d

Browse files
authored
Compact histograms after scalar operations (#597)
1 parent b56f750 commit 296b90d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

engine/engine_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,16 @@ avg by (storage_info) (
22602260
end: time.UnixMilli(0),
22612261
step: 0,
22622262
},
2263+
{
2264+
name: "native histogram scalar compact",
2265+
load: `load 2m
2266+
http_request_duration_seconds{pod="nginx-1"} {{schema:0 count:3 sum:14.00 buckets:[1 2]}}+{{schema:0 count:20 buckets:[1 2 17]}}x20
2267+
http_request_duration_seconds{pod="nginx-2"} {{schema:0 count:2 sum:14.00 buckets:[2]}}+{{schema:0 count:38 buckets:[2 2 34]}}x20`,
2268+
query: `({__name__="http_request_duration_seconds"} offset -2s * pi())`,
2269+
start: time.UnixMilli(0),
2270+
end: time.UnixMilli(300000),
2271+
step: 15 * time.Second,
2272+
},
22632273
}
22642274

22652275
disableOptimizerOpts := []bool{true, false}

execution/binary/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ func undefinedHistogramOp(_ context.Context, _ *histogram.FloatHistogram, _ floa
121121

122122
var lhsHistogramOperations = map[string]histogramFloatOperation{
123123
"*": func(ctx context.Context, hist *histogram.FloatHistogram, float float64) *histogram.FloatHistogram {
124-
return hist.Copy().Mul(float)
124+
return hist.Copy().Mul(float).Compact(0)
125125
},
126126
"/": func(ctx context.Context, hist *histogram.FloatHistogram, float float64) *histogram.FloatHistogram {
127-
return hist.Copy().Div(float)
127+
return hist.Copy().Div(float).Compact(0)
128128
},
129129
"+": func(ctx context.Context, hist *histogram.FloatHistogram, float float64) *histogram.FloatHistogram {
130130
warnings.AddToContext(annotations.NewIncompatibleTypesInBinOpInfo("histogram", "+", "float", posrange.PositionRange{}), ctx)
@@ -174,7 +174,7 @@ var lhsHistogramOperations = map[string]histogramFloatOperation{
174174

175175
var rhsHistogramOperations = map[string]histogramFloatOperation{
176176
"*": func(ctx context.Context, hist *histogram.FloatHistogram, float float64) *histogram.FloatHistogram {
177-
return hist.Copy().Mul(float)
177+
return hist.Copy().Mul(float).Compact(0)
178178
},
179179
"+": func(ctx context.Context, hist *histogram.FloatHistogram, float float64) *histogram.FloatHistogram {
180180
warnings.AddToContext(annotations.NewIncompatibleTypesInBinOpInfo("float", "+", "histogram", posrange.PositionRange{}), ctx)

0 commit comments

Comments
 (0)