-
Notifications
You must be signed in to change notification settings - Fork 525
/
agg.yaml
888 lines (886 loc) · 25.7 KB
/
agg.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
- sql: |
values(sum(1));
expected_outputs:
- binder_error
- sql: |
values(count(1));
expected_outputs:
- binder_error
- sql: |
values(min(1));
expected_outputs:
- binder_error
- sql: |
values(1 + max(1));
expected_outputs:
- binder_error
- sql: |
create table t (v1 int);
select v1 from t where min(v1);
expected_outputs:
- binder_error
- sql: |
create table t(v1 int, v2 int, v3 int);
select v1, min(v2) + max(v3) * count(v1) as agg from t group by v1;
expected_outputs:
- stream_plan
- batch_plan
- batch_local_plan
- sql: |
create table t(v1 int, v2 int, v3 int);
select min(v1) + max(v2) * count(v3) as agg from t;
expected_outputs:
- batch_plan
- batch_local_plan
- stream_plan
- sql: |
create table t(v1 int, v2 int);
select v1 from t group by v2;
expected_outputs:
- planner_error
- sql: |
create table t(v1 int, v2 int);
select sum(v1), v1 from t group by v2, v2;
expected_outputs:
- planner_error
- sql: |
create table t(v1 int, v2 int, v3 int);
select v3, min(v1) * avg(v1+v2) as agg from t group by v3;
expected_outputs:
- batch_plan
- batch_local_plan
- stream_plan
- name: test logical_agg with complex group expression
sql: |
create table t(v1 int, v2 int);
select min(v1), sum(v1 + v2) from t group by v1 + v2;
expected_outputs:
- logical_plan
- name: test logical_agg with complex group expression
sql: |
create table t(v1 int, v2 int, v3 int);
select v1, sum(v1 * v2) as sum from t group by (v1 + v2) / v3, v1;
expected_outputs:
- logical_plan
- name: test logical_agg with complex group expression
sql: |
create table t(v1 int, v2 int);
select v1 + v2 from t group by v1 + v2;
expected_outputs:
- logical_plan
- name: "test logical_agg with complex group expression \nshould complain about nested agg call \n"
sql: |
create table t(v1 int, v2 int);
select avg(sum(v1 + v2)) from t group by v1 + v2;
expected_outputs:
- planner_error
- name: test logical_agg with complex select expression
sql: |
create table t(v1 int, v2 int);
select v1 + v2 from t group by v1, v2;
expected_outputs:
- logical_plan
- sql: |
create table t(v1 int, v2 int);
select v1 from t group by v1 + v2;
expected_outputs:
- planner_error
- name: group by output column ordinal ok
sql: |
select 4 + 5 group by 1;
expected_outputs:
- logical_plan
- name: group by const int expr
sql: |
select 4 + 5 group by 3 - 2; -- not folded
expected_outputs:
- logical_plan
- name: group by output column ordinal of agg
sql: |
select sum(2) group by 1;
expected_outputs:
- planner_error
- name: group by output column ordinal non-integer const
sql: |
select 4 + 5 group by null; -- no implicit cast
expected_outputs:
- binder_error
- name: group by output column ordinal bigint
sql: |
select 4 + 5 group by 2147483648;
expected_outputs:
- binder_error
- name: group by output column ordinal negative
sql: |
select 4 + 5 group by -2147483648;
expected_outputs:
- binder_error
- name: group by output column ordinal zero
sql: |
select 4 + 5 group by 0;
expected_outputs:
- binder_error
- name: group by output column ordinal out of bound (excl extra order by exprs)
sql: |
select 4 + 5 group by 2 order by 7 + 8, 3 + 2;
expected_outputs:
- binder_error
- name: group by output column name ok
sql: |
select 4 + 5 as a group by a;
expected_outputs:
- logical_plan
- name: group by output column name ambiguous 2
sql: |
select 4 + 5 as a, 2 + 3 as a group by a;
expected_outputs:
- binder_error
- name: group by output column name ambiguous 3
sql: |
select 4 + 5 as a, 2 + 3 as a, 3 + 4 as a group by a;
expected_outputs:
- binder_error
- name: group by output column name not ambiguous when unused
sql: |
select 4 + 5 as a, 2 + 3 as a, 3 + 4 as b group by b;
expected_outputs:
- logical_plan
- name: group by output column name not ambiguous when input preferred
sql: |
create table t (a int);
select 4 + 5 as a, 2 + 3 as a from t group by a;
expected_outputs:
- logical_plan
- name: group by output column name expr disallowed
sql: |
select 4 + 5 as a group by a + 1;
expected_outputs:
- binder_error
- name: group by prefers input while order by prefers output
sql: |
create table t (a int);
select 4 + 5 as a from t group by a order by a;
expected_outputs:
- batch_plan
- name: group by column not found
sql: |
select 4 + 5 as a group by b;
expected_outputs:
- binder_error
- sql: |
create table t(v1 int, v2 int);
select count(v1 + v2) as cnt, sum(v1 + v2) as sum from t;
expected_outputs:
- batch_local_plan
- stream_plan
- batch_plan
- sql: |
create table t(v1 int, v2 int, v3 int);
select v1, sum(v2 + v3) / count(v2 + v3) + max(v1) as agg from t group by v1;
expected_outputs:
- batch_plan
- stream_plan
- sql: |
create table t (v1 real);
select v1, count(*) from t group by v1;
expected_outputs:
- batch_plan
- name: Use BatchSortAgg, when input provides order
sql: |
create table t(v1 int, v2 int);
create materialized view mv as select * from t order by v1 desc;
select v1, max(v2) from mv group by v1;
expected_outputs:
- batch_plan
- name: Use BatchSortAgg, when output requires order
sql: |
create table t(v1 int, v2 int);
select v1, max(v2) from t group by v1 order by v1 desc;
expected_outputs:
- batch_plan
- name: Use BatchSortAgg, when required order satisfies input order
sql: |
create table t(k1 int, k2 int, v1 int);
SELECT max(v1), k1, k2 from t group by k1, k2 order by k1;
expected_outputs:
- batch_plan
- name: Use BatchSortAgg, when output requires order with swapped output
sql: |
create table t(v1 int, v2 int);
select max(v2), v1 from t group by v1 order by v1 desc;
expected_outputs:
- batch_plan
- name: Not use BatchSortAgg, when input provides order
sql: |
create table t(v1 int, v2 int);
create materialized view mv as select * from t order by v1 desc;
select v1, max(v2) from mv group by v1;
with_config_map:
RW_BATCH_ENABLE_SORT_AGG: 'false'
expected_outputs:
- batch_plan
- name: Not use BatchSortAgg, when output requires order
sql: |
create table t(v1 int, v2 int);
select v1, max(v2) from t group by v1 order by v1 desc;
with_config_map:
RW_BATCH_ENABLE_SORT_AGG: 'false'
expected_outputs:
- batch_plan
- name: Not use BatchSortAgg, when required order satisfies input order
sql: |
create table t(k1 int, k2 int, v1 int);
SELECT max(v1), k1, k2 from t group by k1, k2 order by k1;
with_config_map:
RW_BATCH_ENABLE_SORT_AGG: 'false'
expected_outputs:
- batch_plan
- name: Not use BatchSortAgg, when output requires order with swapped output
sql: |
create table t(v1 int, v2 int);
select max(v2), v1 from t group by v1 order by v1 desc;
with_config_map:
RW_BATCH_ENABLE_SORT_AGG: 'false'
expected_outputs:
- batch_plan
- sql: |
create table t (v1 real);
select count(*) from t;
expected_outputs:
- batch_plan
- name: having with agg call
sql: |
create table t (v1 real);
select 1 from t having sum(v1) > 5;
expected_outputs:
- batch_plan
- name: having with group column
sql: |
create table t (v1 real);
select 1 from t group by v1 having v1 > 5;
expected_outputs:
- logical_plan
- name: having with non-group column
sql: |
create table t (v1 real, v2 int);
select 1 from t group by v1 having v2 > 5;
expected_outputs:
- planner_error
- name: distinct without agg
sql: |
create table t (v1 int, v2 int);
select distinct v1 from t;
expected_outputs:
- logical_plan
- name: distinct with agg
sql: |
create table t (v1 int, v2 int);
select distinct sum(v1) from t group by v2;
expected_outputs:
- logical_plan
- name: distinct on
sql: |
create table t (v1 int, v2 int, v3 int);
select distinct on (v1, v3) v1, v2 from t order by v3, v1;
expected_outputs:
- logical_plan
- batch_plan
- name: distinct on
sql: |
create table t (v1 int, v2 int, v3 int);
select distinct on (v1, v3) v1, v2 from t order by v1, v3;
expected_outputs:
- logical_plan
- batch_plan
- name: distinct on
sql: |
create table t (v1 int, v2 int);
select distinct on (v1) v1, v2 from t order by v1;
expected_outputs:
- logical_plan
- name: distinct on
sql: |
create table t (v1 int, v2 int, v3 int);
select distinct on(v1) v2 + v3 from t order by v1;
expected_outputs:
- batch_plan
- logical_plan
- name: arguments out-of-order
sql: |
create table t(v1 int, v2 int, v3 int);
select count(v3), min(v2), max(v1) from t;
expected_outputs:
- optimized_logical_plan_for_batch
- batch_plan
- logical_plan
- name: simple-agg arguments out-of-order
sql: |
create table t(v1 int, v2 int, v3 int);
select min(v1) + max(v3) * count(v2) as agg from t;
expected_outputs:
- batch_plan
- stream_plan
- optimized_logical_plan_for_batch
- logical_plan
- name: dup group key
sql: |
create table t(v1 int) with (appendonly = false);
select v1 from t group by v1, v1;
expected_outputs:
- logical_plan
- optimized_logical_plan_for_batch
- stream_plan
- name: dup group key
sql: |
create table t(v1 int, v2 int, v3 int) with (appendonly = false);
select v2, min(v1) as min_v1, v3, max(v1) as max_v1 from t group by v3, v2, v2;
expected_outputs:
- stream_plan
- logical_plan
- optimized_logical_plan_for_batch
- name: order by agg input
sql: |
create table t(v1 int);
select sum(v1 order by v1) as s1 from t;
expected_outputs:
- stream_plan
- logical_plan
- optimized_logical_plan_for_batch
- name: order by other columns
sql: |
create table t(v1 int, v2 varchar);
select sum(v1 order by v2) as s1 from t;
expected_outputs:
- optimized_logical_plan_for_batch
- logical_plan
- stream_plan
- name: order by ASC/DESC and default
sql: |
create table t(v1 int, v2 varchar, v3 int);
select sum(v1 order by v1, v2 ASC, v3 DESC) as s1 from t;
expected_outputs:
- logical_plan
- stream_plan
- optimized_logical_plan_for_batch
- name: filter clause
sql: |
create table t(v1 int);
select sum(v1) FILTER (WHERE v1 > 0) AS sa from t;
expected_outputs:
- logical_plan
- stream_plan
- optimized_logical_plan_for_batch
- name: |
filter clause
extra calculation, should reuse result from project
sql: |
create table t(a int, b int);
select sum(a * b) filter (where a * b > 0) as sab from t;
expected_outputs:
- optimized_logical_plan_for_batch
- logical_plan
- name: complex filter clause
sql: |
create table t(a int, b int);
select max(a * b) FILTER (WHERE a < b AND a + b < 100 AND a * b != a + b - 1) AS sab from t;
expected_outputs:
- optimized_logical_plan_for_batch
- stream_plan
- logical_plan
- name: avg filter clause + group by
sql: |
create table t(a int, b int);
select avg(a) FILTER (WHERE a > b) AS avga from t group by b ;
expected_outputs:
- optimized_logical_plan_for_batch
- logical_plan
- stream_plan
- name: count filter clause
sql: |
create table t(a int, b int);
select count(*) FILTER (WHERE a > b) AS cnt_agb from t;
expected_outputs:
- optimized_logical_plan_for_batch
- logical_plan
- stream_plan
- name: filter clause + non-boolean function
sql: |
create table t(a int, b int);
select avg(a) FILTER (WHERE abs(a)) AS avga from t;
expected_outputs:
- binder_error
- name: filter clause + subquery
sql: |
create table t(a int, b int);
select avg(a) FILTER (WHERE 0 < (select max(a) from t)) AS avga from t;
expected_outputs:
- binder_error
- name: aggregation in filter clause
sql: |
create table t(a int, b int);
select avg(a) FILTER (WHERE a < avg(b)) AS avga from t;
expected_outputs:
- binder_error
- name: filter clause + non-boolean function
sql: |
create table t(a int, b int);
select abs(a) FILTER (WHERE a > 0) AS avga from t;
expected_outputs:
- binder_error
- name: prune column before filter
sql: |
create table t(v1 int, v2 int);
with sub(a, b) as (select min(v1), sum(v2) filter (where v2 < 5) from t) select b from sub;
expected_outputs:
- stream_plan
- batch_plan
- name: only distinct agg
sql: |
create table t(a int, b int, c int);
select a, count(distinct b) as distinct_b_num, sum(distinct c) filter(where c < 100) as distinct_c_sum from t group by a;
expected_outputs:
- optimized_logical_plan_for_batch
- name: single distinct agg and non-disintct agg
sql: |
create table t(a int, b int, c int);
select a, count(distinct b) as distinct_b_num, sum(c) as sum_c from t group by a;
expected_outputs:
- batch_plan
- stream_plan
- optimized_logical_plan_for_batch
- name: distinct agg and non-disintct agg with intersected argument
sql: |
create table t(a int, b int, c int);
select a, count(distinct b) as distinct_b_num, count(distinct c) as distinct_c_sum, sum(c) as sum_c from t group by a;
expected_outputs:
- optimized_logical_plan_for_batch
- stream_plan
- batch_plan
- name: distinct agg with filter
sql: |
create table t(a int, b int, c int);
select a, count(distinct b) filter(where b < 100), sum(c) from t group by a;
expected_outputs:
- batch_plan
- optimized_logical_plan_for_batch
- stream_plan
- name: non-distinct agg with filter
sql: |
create table t(a int, b int, c int);
select a, count(distinct b), sum(c) filter(where b < 100) from t group by a;
expected_outputs:
- optimized_logical_plan_for_batch
- name: combined order by & filter clauses
sql: |
create table t(a varchar, b int);
select sum(length(a) * b order by length(a) + b) filter (where b < 100 AND b * 2 > 10) as s1 from t;
expected_outputs:
- logical_plan
- stream_plan
- optimized_logical_plan_for_batch
- sql: |
create table t(x int, y varchar);
select string_agg(y, ',' order by y), count(distinct x) from t;
expected_outputs:
- planner_error
- sql: |
create table t(v1 int, v2 int);
with z(a, b) as (select count(distinct v1), count(v2) from t) select a from z;
expected_outputs:
- optimized_logical_plan_for_batch
- name: input is sharded by group key
sql: |
create table t(x int);
create index i on t(x);
select count(*) as cnt from i group by x;
expected_outputs:
- batch_plan
- stream_plan
- name: distinct aggregates only have one distinct argument doesn't need expand
sql: |
create table t(x int, y int);
select count(x), sum(distinct y), sum(distinct y) from t;
expected_outputs:
- optimized_logical_plan_for_batch
- optimized_logical_plan_for_stream
with_config_map:
RW_FORCE_SPLIT_DISTINCT_AGG: 'true'
- sql: |
create table t(x int, y int);
select count(y), sum(distinct y) from t;
expected_outputs:
- optimized_logical_plan_for_batch
- optimized_logical_plan_for_stream
with_config_map:
RW_FORCE_SPLIT_DISTINCT_AGG: 'true'
- sql: |
create table t(x int, y int);
select count(distinct x), sum(distinct y) from t;
expected_outputs:
- optimized_logical_plan_for_batch
- optimized_logical_plan_for_stream
with_config_map:
RW_FORCE_SPLIT_DISTINCT_AGG: 'true'
- sql: |
create table t(x varchar, y int);
select string_agg(x, ','), count(distinct y) from t;
expected_outputs:
- planner_error
- name: remove unnecessary distinct for max and min
sql: |
create table t(x int, y int);
select max(distinct x), min(distinct y) from t;
expected_outputs:
- optimized_logical_plan_for_batch
- optimized_logical_plan_for_stream
with_config_map:
RW_FORCE_SPLIT_DISTINCT_AGG: 'true'
- name: agg filter - subquery
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
select count(a1) filter (where (select true)) from a;
expected_outputs:
- binder_error
- name: agg filter - agg
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
create table b (b1 int, b2 int);
select 1 from a having exists(
select count(b1) filter (where min(a1) < 3) from b
);
expected_outputs:
- binder_error
- name: agg filter - table function
sql: |
/* This case is NOT valid in PostgreSQL */
create table a (a1 int, a2 int);
select count(a1) filter (where unnest(array[1]) < 1) from a;
expected_outputs:
- binder_error
- name: agg order by - subquery
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
select string_agg('', '' order by (select true)) from a;
expected_outputs:
- planner_error
- name: agg order by - agg (correlated in having)
sql: |
create table a (a1 int, a2 int);
create table sb (b1 varchar, b2 varchar);
select 1 from a having exists(
select string_agg(b1, '' order by min(a1)) from sb -- valid in PostgreSQL
-- select string_agg('', '' order by min(a1)) from sb -- NOT valid in PostgreSQL
);
expected_outputs:
- planner_error
- name: agg order by - agg (correlated in where)
sql: |
/* This case is NOT valid in PostgreSQL */
create table a (a1 int, a2 int);
create table sb (b1 varchar, b2 varchar);
select 1 from a where exists(
select string_agg(b1, '' order by min(a1)) from sb
);
expected_outputs:
- planner_error
- name: agg order by - table function
sql: |
/* This case is NOT valid in PostgreSQL */
create table a (a1 int, a2 int);
select string_agg('', '' order by unnest(array[1])) from a;
expected_outputs:
- planner_error
- name: agg input - subquery
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
select count(a1 + (select 1)) from a;
expected_outputs:
- planner_error
- name: agg input - agg
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
create table b (b1 int, b2 int);
select 1 from a having exists(
select count(b1 + min(a1)) from b
);
expected_outputs:
- planner_error
- name: agg input - table function
sql: |
/* This case is NOT valid in PostgreSQL */
create table a (a1 int, a2 int);
select count(a1 + unnest(array[1])) from a;
expected_outputs:
- planner_error
- name: group by - subquery
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
select count(a1) from a group by (select true);
expected_outputs:
- planner_error
- name: group by - agg
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
create table b (b1 int, b2 int);
select 1 from a having exists(
select count(b1) from b group by min(a1)
);
expected_outputs:
- planner_error
- name: group by - table function
sql: |
/* This case is valid in PostgreSQL */
create table a (a1 int, a2 int);
select count(a1) from a group by unnest(array[1]);
expected_outputs:
- planner_error
- name: post-agg project set - ok
sql: |
create table t (v1 int, v2 int);
select min(v1), unnest(array[2, max(v2)]) from t;
expected_outputs:
- logical_plan
- name: post-agg project set - error
sql: |
create table t (v1 int, v2 int);
select min(v1), unnest(array[2, v2]) from t;
expected_outputs:
- planner_error
- name: post-agg project set - grouped
sql: |
create table t (v1 int, v2 int);
select min(v1), unnest(array[2, v2]) from t group by v2;
expected_outputs:
- logical_plan
- name: min/max on index
sql: |
create table t (v1 varchar, v2 int);
create index idx on t(v2 desc);
select max(v2) from t;
expected_outputs:
- optimized_logical_plan_for_batch
- logical_plan
- name: min/max on index with group by, shall NOT optimize
sql: |
create table t (v1 int, v2 int);
create index idx on t(v2 desc);
select max(v2) from t group by v1;
expected_outputs:
- optimized_logical_plan_for_batch
- logical_plan
- name: min/max on primary key
sql: |
create table t (v1 int primary key);
select min(v1) from t;
expected_outputs:
- logical_plan
- optimized_logical_plan_for_batch
- name: stddev_samp
sql: |
create table t (v1 int);
select stddev_samp(v1), stddev_pop(v1) from t;
expected_outputs:
- batch_plan
- batch_local_plan
- stream_plan
- logical_plan
- name: stddev_samp with other columns
sql: |
select count(''), stddev_samp(1);
expected_outputs:
- logical_plan
- name: stddev_samp with group
sql: |
create table t(v int, w float);
select stddev_samp(v) from t group by w;
expected_outputs:
- logical_plan
- name: force two phase aggregation should succeed with UpstreamHashShard and SomeShard (batch only).
sql: |
SET QUERY_MODE TO DISTRIBUTED;
SET RW_FORCE_TWO_PHASE_AGG=true;
create table t(v1 int, v2 smallint, v3 varchar);
select min(v3), sum(v1) from t group by v1, v3, v2;
expected_outputs:
- stream_plan
- batch_plan
- name: enable two phase aggregation with simple agg should have two phase agg
sql: |
SET QUERY_MODE TO DISTRIBUTED;
SET RW_ENABLE_TWO_PHASE_AGG=true;
create table t(v1 int, v2 int);
select min(v1), sum(v2) from t;
expected_outputs:
- stream_plan
- batch_plan
- name: disable two phase aggregation with simple agg
sql: |
SET QUERY_MODE TO DISTRIBUTED;
SET RW_ENABLE_TWO_PHASE_AGG=false;
create table t(v1 int, v2 int);
select min(v1), sum(v2) from t;
expected_outputs:
- batch_plan
- stream_plan
- name: force two phase agg with different distributions on inner and outer agg should have exchange
sql: |
set QUERY_MODE to DISTRIBUTED;
set RW_FORCE_TWO_PHASE_AGG to TRUE;
CREATE TABLE lineitem (
l_orderkey BIGINT,
l_tax NUMERIC,
l_commitdate DATE,
l_shipinstruct VARCHAR,
PRIMARY KEY (l_orderkey)
);
SELECT
max(sq_1.col_2) as col_0
FROM
(
SELECT
t_0.l_commitdate AS col_2
FROM
lineitem AS t_0
GROUP BY
t_0.l_tax,
t_0.l_shipinstruct,
t_0.l_orderkey,
t_0.l_commitdate
) AS sq_1
GROUP BY
sq_1.col_2;
expected_outputs:
- stream_plan
- batch_plan
- name: two phase agg on hop window input should use two phase agg
sql: |
SET QUERY_MODE TO DISTRIBUTED;
SET RW_FORCE_TWO_PHASE_AGG=true;
create table bid(date_time TIMESTAMP, auction int);
SELECT
max(CountBids.num) AS maxn,
CountBids.starttime_c
FROM (
SELECT
count(*) AS num,
window_start AS starttime_c
FROM HOP(bid, date_time, INTERVAL '2' SECOND, INTERVAL '10' SECOND)
GROUP BY
bid.auction,
window_start
) as CountBids
GROUP BY
CountBids.starttime_c;
expected_outputs:
- batch_plan
- stream_plan
- name: two phase agg with stream SomeShard (via index) but pk satisfies output dist should use shuffle agg
sql: |
SET QUERY_MODE TO DISTRIBUTED;
SET RW_FORCE_TWO_PHASE_AGG=true;
create table t (id int primary key, col int);
create index idx on t(col);
with sq as (select id from idx) select count(*) from sq group by sq.id;
expected_outputs:
- batch_plan
- stream_plan
- name: two phase agg with stream SomeShard (via index) but pk does not satisfy output dist should use two phase agg
sql: |
SET QUERY_MODE TO DISTRIBUTED;
SET RW_FORCE_TWO_PHASE_AGG=true;
create table t (id int primary key, col1 int, col2 int);
create index idx on t(id);
with sq as (select col1, col2 from idx) select count(*) from sq group by sq.col1;
expected_outputs:
- batch_plan
- stream_plan
- name: sort agg on an ascending index
sql: |
create table t (a int, b int);
create index idx_asc on t(a asc);
create index idx_desc on t(a desc);
select a, count(*) cnt from t group by a order by a asc;
expected_outputs:
- batch_plan
- name: sort agg on a descending index
sql: |
create table t (a int, b int);
create index idx_asc on t(a asc);
create index idx_desc on t(a desc);
select a, count(*) cnt from t group by a order by a desc;
expected_outputs:
- batch_plan
- sql: |
create table t (x int, y int);
select percentile_cont(x) within group (order by y) from t;
expected_outputs:
- binder_error
- sql: |
create table t (x int, y int);
select percentile_cont('abc') within group (order by y) from t;
expected_outputs:
- binder_error
- sql: |
create table t (x int, y int);
select percentile_cont(1.3) within group (order by y) from t;
expected_outputs:
- binder_error
- sql: |
create table t (x int, y int);
select percentile_cont(0, 0) within group (order by y) from t;
expected_outputs:
- binder_error
- sql: |
create table t (x int, y varchar);
select percentile_cont(0) within group (order by y) from t;
expected_outputs:
- binder_error
- sql: |
create table t (x int, y int);
select percentile_cont(0) within group (order by y desc) from t;
expected_outputs:
- batch_plan
- sql: |
create table t (x int, y varchar);
select percentile_disc(1) within group (order by y desc) from t;
expected_outputs:
- batch_plan
- sql: |
create table t (x int, y varchar);
select mode() within group (order by y desc) from t;
expected_outputs:
- batch_plan
- sql: |
create table t (x int, y varchar);
select mode(1) within group (order by y desc) from t;
expected_outputs:
- binder_error
- sql: |
create table t (x int, y int);
select first_value(x) from t;
expected_outputs:
- planner_error
- sql: |
create table t (x int, y int);
select last_value(x) from t;
expected_outputs:
- planner_error
- sql: |
create table t (x int, y int);
select first_value(x order by y asc) from t;
expected_outputs:
- batch_plan
- stream_plan
- sql: |
create table t (x int, y int);
select last_value(x order by y desc nulls last) from t;
expected_outputs:
- batch_plan
- stream_plan