You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: logicalplan/distribute_test.go
+68-25Lines changed: 68 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -83,19 +83,13 @@ sum(
83
83
remote(count by (pod, region) (metric_a)))))`,
84
84
},
85
85
{
86
-
name: "avg in binary expression with outer sum distributes avg independently",
86
+
name: "avg in binary expression with outer sum pushes entire expression",
87
87
expr: `sum(metric_a * avg by (region) (metric_b))`,
88
88
expected: `
89
89
sum(
90
-
dedup(remote(metric_a), remote(metric_a))
91
-
*
92
-
sum by (region) (dedup(
93
-
remote(sum by (region) (metric_b)),
94
-
remote(sum by (region) (metric_b))))
95
-
/ on (region)
96
-
sum by (region) (dedup(
97
-
remote(count by (region) (metric_b)),
98
-
remote(count by (region) (metric_b)))))`,
90
+
dedup(
91
+
remote(sum by (region) (metric_a * avg by (region) (metric_b))),
92
+
remote(sum by (region) (metric_a * avg by (region) (metric_b)))))`,
99
93
},
100
94
{
101
95
name: "selector",
@@ -171,21 +165,12 @@ sum by (pod) (
171
165
)`,
172
166
},
173
167
{
174
-
name: "avg with without-grouping",
168
+
name: "avg with without-grouping preserving partition labels",
175
169
expr: `avg without (pod) (http_requests_total)`,
176
170
expected: `
177
-
sum without (pod) (
178
-
dedup(
179
-
remote(sum without (pod) (http_requests_total)),
180
-
remote(sum without (pod) (http_requests_total))
181
-
)
182
-
) / ignoring (pod)
183
-
sum without (pod) (
184
-
dedup(
185
-
remote(count without (pod) (http_requests_total)),
186
-
remote(count without (pod) (http_requests_total))
187
-
)
188
-
)`,
171
+
dedup(
172
+
remote(avg without (pod) (http_requests_total)),
173
+
remote(avg without (pod) (http_requests_total)))`,
189
174
},
190
175
{
191
176
name: "avg with prior aggregation",
@@ -218,6 +203,57 @@ sum by (pod) (
218
203
)
219
204
)`,
220
205
},
206
+
{
207
+
name: "avg by partition label pushes as-is",
208
+
expr: `avg by (region) (http_requests_total)`,
209
+
expected: `
210
+
dedup(
211
+
remote(avg by (region) (http_requests_total)),
212
+
remote(avg by (region) (http_requests_total)))`,
213
+
},
214
+
{
215
+
name: "avg by partition label defers to distributive ancestor",
216
+
expr: `max(avg by (region) (http_requests_total))`,
217
+
expected: `
218
+
max(
219
+
dedup(
220
+
remote(max by (region) (avg by (region) (http_requests_total))),
221
+
remote(max by (region) (avg by (region) (http_requests_total)))))`,
222
+
},
223
+
{
224
+
name: "avg over subquery with inner aggregations pushes entire expression",
225
+
expr: `avg by (region) (quantile_over_time(0.9, (sum by (region) (rate(metric_a[2m])) / sum by (region) (metric_b))[1h:1m]))`,
226
+
expected: `
227
+
dedup(
228
+
remote(avg by (region) (quantile_over_time(0.9, (sum by (region) (rate(metric_a[2m])) / sum by (region) (metric_b))[1h:1m]))),
229
+
remote(avg by (region) (quantile_over_time(0.9, (sum by (region) (rate(metric_a[2m])) / sum by (region) (metric_b))[1h:1m]))))`,
230
+
},
231
+
{
232
+
name: "quantile by partition label pushes as-is",
233
+
expr: `quantile by (region) (0.9, http_requests_total)`,
234
+
expected: `
235
+
dedup(
236
+
remote(quantile by (region) (0.9, http_requests_total)),
237
+
remote(quantile by (region) (0.9, http_requests_total)))`,
238
+
},
239
+
{
240
+
name: "quantile by non-partition label is not distributed",
241
+
expr: `quantile by (pod) (0.9, http_requests_total)`,
242
+
expected: `quantile by (pod) (0.9, dedup(remote(http_requests_total), remote(http_requests_total)))`,
243
+
},
244
+
{
245
+
name: "stddev by partition label pushes as-is",
246
+
expr: `stddev by (region) (http_requests_total)`,
247
+
expected: `
248
+
dedup(
249
+
remote(stddev by (region) (http_requests_total)),
250
+
remote(stddev by (region) (http_requests_total)))`,
251
+
},
252
+
{
253
+
name: "stddev by non-partition label is not distributed",
254
+
expr: `stddev by (pod) (http_requests_total)`,
255
+
expected: `stddev by (pod) (dedup(remote(http_requests_total), remote(http_requests_total)))`,
256
+
},
221
257
{
222
258
name: "two-level aggregation",
223
259
expr: `max by (pod) (sum by (pod) (http_requests_total))`,
@@ -518,15 +554,22 @@ count by (cluster) (
518
554
{
519
555
name: "skip binary pushdown with nested aggregation",
520
556
expr: `sum(metric_a * group by (region) (metric_b))`,
521
-
expected: `sum(dedup(remote(metric_a), remote(metric_a)) * group by (region) (dedup(remote(group by (region) (metric_b)), remote(group by (region) (metric_b)))))`,
557
+
expected: `sum(dedup(remote(metric_a), remote(metric_a)) * dedup(remote(group by (region) (metric_b)), remote(group by (region) (metric_b))))`,
522
558
skipBinopPushdown: true,
523
559
},
524
560
{
525
561
name: "skip binary pushdown with outer aggregation",
526
562
expr: `max(metric_a + sum by (region, pod) (metric_b))`,
527
-
expected: `max(dedup(remote(metric_a), remote(metric_a)) + sum by (region, pod) (dedup(remote(sum by (pod, region) (metric_b)), remote(sum by (pod, region) (metric_b)))))`,
563
+
expected: `max(dedup(remote(metric_a), remote(metric_a)) + dedup(remote(sum by (region, pod) (metric_b)), remote(sum by (region, pod) (metric_b))))`,
528
564
skipBinopPushdown: true,
529
565
},
566
+
{
567
+
// When the RHS of unless has an aggregation that drops the partition label,
568
+
// both sides should still be distributed independently.
569
+
name: "unless with aggregation that drops partition label distributes both sides",
570
+
expr: `group by (region, instance) (metric_a unless on (region, instance) max by (instance) (metric_b))`,
571
+
expected: `group by (region, instance) (dedup(remote(metric_a), remote(metric_a)) unless on (region, instance) max by (instance) (dedup(remote(max by (instance, region) (metric_b)), remote(max by (instance, region) (metric_b)))))`,
572
+
},
530
573
{
531
574
// group_left/group_right with partition label cannot be distributed because
532
575
// match cardinality changes when each partition only sees one value for that label.
0 commit comments