-
Notifications
You must be signed in to change notification settings - Fork 32
/
aggregation.test
1113 lines (1113 loc) · 25.7 KB
/
aggregation.test
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
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
====
---- QUERY
# test a larger dataset, includes nulls
# the exact result could vary slightly due to numeric instability
# 0.001 is a conservative upperbound on the possible difference in results
SELECT abs(cast(variance(tinyint_col) as double) - 6.66741) < 0.001,
abs(cast(variance(double_col) as double) - 8470806.708) < 0.001
from alltypesagg
---- RESULTS
true,true
---- TYPES
boolean, boolean
====
---- QUERY
# No tuples processed (should return null)
SELECT variance(tinyint_col), stddev(smallint_col), variance_pop(int_col),
stddev_pop(bigint_col)
from alltypesagg WHERE id = -9999999
---- RESULTS
NULL,NULL,NULL,NULL
---- TYPES
double, double, double, double
====
---- QUERY
# exactly 1 tuple processed (variance & stddev are 0)
SELECT variance(tinyint_col), stddev(smallint_col), variance_pop(int_col),
stddev_pop(bigint_col)
from alltypesagg WHERE id = 1006
---- RESULTS
0,0,0,0
---- TYPES
double, double, double, double
====
---- QUERY
# Includes one row which is null, and test the aliases for variance() as well
SELECT variance(tinyint_col), variance(smallint_col), variance(int_col),
variance(bigint_col), variance(float_col), variance(double_col),
var_samp(double_col), variance_samp(double_col)
from alltypesagg WHERE id >= 1000 AND id < 1006
---- RESULTS
2.5,2.5,2.5,250,3.025,255.025,255.025,255.025
---- TYPES
double, double, double, double, double, double,double, double
====
---- QUERY
# Test population variance (including the var_pop() alias)
SELECT variance_pop(tinyint_col), variance_pop(smallint_col), variance_pop(int_col),
variance_pop(bigint_col), variance_pop(float_col), variance_pop(double_col),
var_pop(double_col)
from alltypesagg WHERE id >= 1000 AND id < 1006
---- RESULTS
2,2,2,200,2.42,204.02,204.02
---- TYPES
double, double, double, double, double, double, double
====
---- QUERY
SELECT round(stddev(tinyint_col), 5),
round(stddev(smallint_col), 5),
round(stddev(int_col), 5),
round(stddev(bigint_col), 5),
round(stddev(float_col), 5),
round(stddev(double_col), 5),
round(stddev_samp(double_col), 5)
from alltypesagg WHERE id >= 1000 AND id < 1006
---- RESULTS
1.58114,1.58114,1.58114,15.81139,1.73925,15.96950,15.96950
---- TYPES
double, double, double, double, double, double, double
====
---- QUERY
# no grouping exprs, cols contain nulls except for bool cols
SELECT round(stddev_pop(tinyint_col), 5),
round(stddev_pop(smallint_col), 5),
round(stddev_pop(int_col), 5),
round(stddev_pop(bigint_col), 5),
round(stddev_pop(float_col), 5),
round(stddev_pop(double_col), 5)
from alltypesagg WHERE id >= 1000 AND id < 1006
---- RESULTS
1.41421,1.41421,1.41421,14.14214,1.55563,14.28356
---- TYPES
double, double, double, double, double, double
====
---- QUERY
# no grouping exprs, cols contain nulls except for bool cols
select count(bool_col), min(bool_col), max(bool_col)
from alltypesagg where day is not null
---- RESULTS
10000,false,true
---- TYPES
bigint, boolean, boolean
====
---- QUERY
# no grouping exprs, cols contain nulls
select count(*), count(tinyint_col), min(tinyint_col), max(tinyint_col), sum(tinyint_col),
avg(tinyint_col)
from alltypesagg where day is not null
---- RESULTS
10000,9000,1,9,45000,5
---- TYPES
bigint, bigint, tinyint, tinyint, bigint, double
====
---- QUERY
select count(*), count(smallint_col), min(smallint_col), max(smallint_col), sum(smallint_col),
avg(smallint_col)
from alltypesagg where day is not null
---- RESULTS
10000,9900,1,99,495000,50
---- TYPES
bigint, bigint, smallint, smallint, bigint, double
====
---- QUERY
select count(*), count(int_col), min(int_col), max(int_col), sum(int_col), avg(int_col)
from alltypesagg where day is not null
---- RESULTS
10000,9990,1,999,4995000,500
---- TYPES
bigint, bigint, int, int, bigint, double
====
---- QUERY
select count(*), count(bigint_col), min(bigint_col), max(bigint_col), sum(bigint_col),
avg(bigint_col)
from alltypesagg where day is not null
---- RESULTS
10000,9990,10,9990,49950000,5000
---- TYPES
bigint, bigint, bigint, bigint, bigint, double
====
---- QUERY
select count(*), count(float_col), min(float_col), max(float_col), sum(float_col),
avg(float_col)
from alltypesagg where day is not null
---- RESULTS
10000,9990,1.100000023841858,1098.900024414062,5494499.999767542,549.9999999767309
---- TYPES
bigint, bigint, float, float, double, double
====
---- QUERY
select count(*), count(double_col), min(double_col), max(double_col), round(sum(double_col), 0),
round(avg(double_col), 0)
from alltypesagg where day is not null
---- RESULTS
10000,9990,10.1,10089.9,50449500,5050
---- TYPES
bigint, bigint, double, double, double, double
====
---- QUERY
select count(*), min(string_col), max(string_col), min(date_string_col),
max(date_string_col)
from alltypesagg where day is not null
---- RESULTS
10000,'0','999','01/01/10','01/10/10'
---- TYPES
bigint, string, string, string, string
====
---- QUERY
# grouping by different data types, with NULLs
select tinyint_col, count(*) from alltypesagg where day is not null group by 1 order by 1
---- RESULTS
1,1000
2,1000
3,1000
4,1000
5,1000
6,1000
7,1000
8,1000
9,1000
NULL,1000
---- TYPES
tinyint, bigint
====
---- QUERY
# grouping by different data types, with NULLs, grouping expr missing from select list
select bool_col,min(bool_col),max(bool_col) from alltypesagg where day is not null group by 1
---- RESULTS
false,false,false
true,true,true
---- TYPES
boolean,boolean,boolean
====
---- QUERY
select count(*) from alltypesagg where day is not null group by tinyint_col
---- RESULTS
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
---- TYPES
bigint
====
---- QUERY
select smallint_col % 10, count(*) from alltypesagg where day is not null group by 1
---- RESULTS
3,1000
NULL,100
8,1000
7,1000
0,900
6,1000
9,1000
5,1000
4,1000
1,1000
2,1000
---- TYPES
smallint, bigint
====
---- QUERY
select count(*) from alltypesagg where day is not null group by smallint_col % 10
---- RESULTS
1000
100
1000
1000
900
1000
1000
1000
1000
1000
1000
---- TYPES
bigint
====
---- QUERY
select int_col % 10, count(*) from alltypesagg where day is not null group by 1
---- RESULTS
4,1000
9,1000
NULL,10
6,1000
5,1000
2,1000
0,990
1,1000
3,1000
8,1000
7,1000
---- TYPES
int, bigint
====
---- QUERY
select count(*) from alltypesagg where day is not null group by int_col % 10
---- RESULTS
1000
1000
10
1000
1000
1000
990
1000
1000
1000
1000
---- TYPES
bigint
====
---- QUERY
# Check that ALL inside aggregates is correct
select count(ALL *) from alltypesagg where day is not null group by int_col % 10
---- RESULTS
1000
1000
10
1000
1000
1000
990
1000
1000
1000
1000
---- TYPES
bigint
====
---- QUERY
select bigint_col % 100, count(*) from alltypesagg where day is not null group by 1
---- RESULTS
60,1000
70,1000
20,1000
NULL,10
40,1000
80,1000
30,1000
0,990
50,1000
90,1000
10,1000
---- TYPES
bigint, bigint
====
---- QUERY
select count(*) from alltypesagg where day is not null group by bigint_col % 100
---- RESULTS
1000
1000
1000
10
1000
1000
1000
990
1000
1000
1000
---- TYPES
bigint
====
---- QUERY
select float_col, float_col * 2, count(*) from alltypes group by 1, 2
---- RESULTS
0,0,730
3.299999952316284,6.599999904632568,730
8.800000190734863,17.60000038146973,730
6.599999904632568,13.19999980926514,730
7.699999809265137,15.39999961853027,730
2.200000047683716,4.400000095367432,730
5.5,11,730
1.100000023841858,2.200000047683716,730
9.899999618530273,19.79999923706055,730
4.400000095367432,8.800000190734863,730
---- TYPES
float, double, bigint
====
---- QUERY
select count(*) from alltypes group by float_col
---- RESULTS
730
730
730
730
730
730
730
730
730
730
---- TYPES
bigint
====
---- QUERY
select float_col, count(*) from alltypesagg where float_col is null and day is not null group by 1
---- RESULTS
NULL,10
---- TYPES
float, bigint
====
---- QUERY
select double_col, double_col * 2, count(*) from alltypes group by 1, 2
---- RESULTS
0,0,730
90.90000000000001,181.8,730
40.4,80.8,730
20.2,40.4,730
80.8,161.6,730
10.1,20.2,730
70.7,141.4,730
50.5,101,730
30.3,60.6,730
60.6,121.2,730
---- TYPES
double, double, bigint
====
---- QUERY
select count(*) from alltypes group by double_col
---- RESULTS
730
730
730
730
730
730
730
730
730
730
---- TYPES
bigint
====
---- QUERY
select double_col, count(*) from alltypesagg where double_col is null and day is not null group by 1
---- RESULTS
NULL,10
---- TYPES
double, bigint
====
---- QUERY
select date_string_col, count(*) from alltypesagg where day is not null group by 1
---- RESULTS
'01/08/10',1000
'01/09/10',1000
'01/02/10',1000
'01/06/10',1000
'01/01/10',1000
'01/03/10',1000
'01/04/10',1000
'01/10/10',1000
'01/07/10',1000
'01/05/10',1000
---- TYPES
string, bigint
====
---- QUERY
select count(*) from alltypesagg where day is not null group by date_string_col
---- RESULTS
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
---- TYPES
bigint
====
---- QUERY
# grouping by multiple exprs, with nulls
select tinyint_col % 3, smallint_col % 3, count(*) from alltypesagg
where day = 1 group by 1, 2
---- RESULTS
0,0,120
0,1,90
0,2,90
1,0,90
1,1,120
1,2,90
2,0,90
2,1,90
2,2,120
NULL,0,30
NULL,1,30
NULL,2,30
NULL,NULL,10
---- TYPES
tinyint, smallint, bigint
====
---- QUERY
select count(*) from alltypesagg
where day = 1 group by tinyint_col % 3, smallint_col % 3
---- RESULTS
10
120
120
120
30
30
30
90
90
90
90
90
90
---- TYPES
bigint
====
---- QUERY
# same result as previous query
select tinyint_col % 3, smallint_col % 3, count(*) from alltypesagg where day = 1 group by 2, 1
---- RESULTS
0,0,120
0,1,90
0,2,90
1,0,90
1,1,120
1,2,90
2,0,90
2,1,90
2,2,120
NULL,0,30
NULL,1,30
NULL,2,30
NULL,NULL,10
---- TYPES
tinyint, smallint, bigint
====
---- QUERY
select tinyint_col % 2, smallint_col % 2, int_col % 2, bigint_col % 2, date_string_col, count(*)
from alltypesagg
where (date_string_col = '01/01/10' or date_string_col = '01/02/10') and day is not null
group by 1, 2, 3, 4, 5
---- RESULTS
1,1,1,0,'01/02/10',500
0,0,0,0,'01/02/10',400
NULL,NULL,0,0,'01/02/10',9
NULL,NULL,NULL,NULL,'01/02/10',1
0,0,0,0,'01/01/10',400
NULL,NULL,0,0,'01/01/10',9
NULL,NULL,NULL,NULL,'01/01/10',1
NULL,0,0,0,'01/02/10',90
1,1,1,0,'01/01/10',500
NULL,0,0,0,'01/01/10',90
---- TYPES
tinyint, smallint, int, bigint, string, bigint
====
---- QUERY
select count(*)
from alltypesagg
where (date_string_col = '01/01/10' or date_string_col = '01/02/10') and day is not null
group by tinyint_col % 2, smallint_col % 2, int_col % 2, bigint_col % 2, date_string_col
---- RESULTS
500
400
9
1
400
9
1
90
500
90
---- TYPES
bigint
====
---- QUERY
# no grouping cols, no matching rows
select count(*), min(tinyint_col), max(tinyint_col), sum(tinyint_col), avg(tinyint_col)
from alltypesagg
where tinyint_col = -1 and day is not null
---- RESULTS
0,NULL,NULL,NULL,NULL
---- TYPES
bigint, tinyint, tinyint, bigint, double
====
---- QUERY
select count(*), min(smallint_col), max(smallint_col), sum(smallint_col), avg(smallint_col)
from alltypesagg
where smallint_col = -1 and day is not null
---- RESULTS
0,NULL,NULL,NULL,NULL
---- TYPES
bigint, smallint, smallint, bigint, double
====
---- QUERY
select count(*), min(int_col), max(int_col), sum(int_col), avg(int_col)
from alltypesagg
where int_col = -1 and day is not null
---- RESULTS
0,NULL,NULL,NULL,NULL
---- TYPES
bigint, int, int, bigint, double
====
---- QUERY
select count(*), min(bigint_col), max(bigint_col), sum(bigint_col), avg(bigint_col)
from alltypesagg
where bigint_col = -1 and day is not null
---- RESULTS
0,NULL,NULL,NULL,NULL
---- TYPES
bigint, bigint, bigint, bigint, double
====
---- QUERY
select count(*), min(float_col), max(float_col), sum(float_col), avg(float_col)
from alltypesagg
where float_col < -1.0 and day is not null
---- RESULTS
0,NULL,NULL,NULL,NULL
---- TYPES
bigint, float, float, double, double
====
---- QUERY
select count(*), min(double_col), max(double_col), sum(double_col), avg(double_col)
from alltypesagg
where double_col < -1.0 and day is not null
---- RESULTS
0,NULL,NULL,NULL,NULL
---- TYPES
bigint, double, double, double, double
====
---- QUERY
# HAVING clauses over all aggregation functions, plus compound HAVING clauses
select int_col % 7, count(*), max(int_col) from alltypesagg where day is not null group by 1
---- RESULTS
4,1430,998
NULL,10,NULL
6,1420,993
5,1430,999
2,1430,996
0,1420,994
1,1430,995
3,1430,997
---- TYPES
int, bigint, int
====
---- QUERY
select int_col % 7, count(*) from alltypesagg where day is not null group by 1 having max(int_col) > 991
---- RESULTS
4,1430
6,1420
5,1430
2,1430
0,1420
1,1430
3,1430
---- TYPES
int, bigint
====
---- QUERY
select int_col % 7, count(*) from alltypesagg where day is not null group by 1
having max(int_col) > 991 and count(*) > 1420
---- RESULTS
4,1430
5,1430
2,1430
1,1430
3,1430
---- TYPES
int, bigint
====
---- QUERY
select int_col % 7, count(*) from alltypesagg where day is not null group by 1
having min(int_col) < 7
---- RESULTS
4,1430
6,1420
5,1430
2,1430
1,1430
3,1430
---- TYPES
int, bigint
====
---- QUERY
select int_col % 7, count(*) from alltypesagg where day is not null group by 1
having min(int_col) < 7 and count(*) > 1420
---- RESULTS
4,1430
5,1430
2,1430
1,1430
3,1430
---- TYPES
int, bigint
====
---- QUERY
select int_col % 7, count(*), sum(int_col) from alltypesagg where day is not null group by 1
---- RESULTS
4,1430,716430
NULL,10,NULL
6,1420,709290
5,1430,717860
2,1430,713570
0,1420,710710
1,1430,712140
3,1430,715000
---- TYPES
int, bigint, bigint
====
---- QUERY
select int_col % 7, count(*), sum(int_col) from alltypesagg where day is not null group by 1
having sum(int_col) >= 715000
---- RESULTS
4,1430,716430
5,1430,717860
3,1430,715000
---- TYPES
int, bigint, bigint
====
---- QUERY
select int_col % 7, count(*), sum(int_col) from alltypesagg where day is not null group by 1
having sum(int_col) >= 715000 or count(*) > 1420
---- RESULTS
4,1430,716430
5,1430,717860
2,1430,713570
1,1430,712140
3,1430,715000
---- TYPES
int, bigint, bigint
====
---- QUERY
select int_col % 7, count(*), sum(int_col) from alltypesagg where day is not null group by 1
having sum(int_col) is null
---- RESULTS
NULL,10,NULL
---- TYPES
int, bigint, bigint
====
---- QUERY
select int_col % 7, count(*), avg(int_col) from alltypesagg where day is not null group by 1
---- RESULTS
4,1430,501
NULL,10,NULL
6,1420,499.5
5,1430,502
2,1430,499
0,1420,500.5
1,1430,498
3,1430,500
---- TYPES
int, bigint, double
====
---- QUERY
select int_col % 7, count(*), avg(int_col) from alltypesagg where day is not null group by 1
having avg(int_col) > 500
---- RESULTS
4,1430,501
5,1430,502
0,1420,500.5
---- TYPES
int, bigint, double
====
---- QUERY
select int_col % 7, count(*), avg(int_col) from alltypesagg where day is not null group by 1
having avg(int_col) > 500 or count(*) = 10
---- RESULTS
4,1430,501
NULL,10,NULL
5,1430,502
0,1420,500.5
---- TYPES
int, bigint, double
====
---- QUERY
select timestamp_col, count(*) from alltypesagg where day is not null
group by timestamp_col having timestamp_col < cast('2010-01-01 01:05:20' as timestamp)
---- RESULTS
2010-01-01 00:49:11.760000000,1
2010-01-01 01:01:18.300000000,1
2010-01-01 00:17:01.360000000,1
2010-01-01 00:58:16.530000000,1
2010-01-01 00:09:00.360000000,1
2010-01-01 00:00:00,1
2010-01-01 01:00:17.700000000,1
2010-01-01 00:57:15.960000000,1
2010-01-01 00:24:02.760000000,1
2010-01-01 00:23:02.530000000,1
2010-01-01 00:45:09.900000000,1
2010-01-01 00:39:07.410000000,1
2010-01-01 00:33:05.280000000,1
2010-01-01 00:03:00.300000000,1
2010-01-01 00:20:01.900000000,1
2010-01-01 00:36:06.300000000,1
2010-01-01 00:44:09.460000000,1
2010-01-01 00:14:00.910000000,1
2010-01-01 00:31:04.650000000,1
2010-01-01 00:48:11.280000000,1
2010-01-01 01:03:19.530000000,1
2010-01-01 00:29:04.600000000,1
2010-01-01 01:02:18.910000000,1
2010-01-01 00:16:01.200000000,1
2010-01-01 00:47:10.810000000,1
2010-01-01 00:51:12.750000000,1
2010-01-01 00:55:14.850000000,1
2010-01-01 00:42:08.610000000,1
2010-01-01 00:56:15.400000000,1
2010-01-01 00:05:00.100000000,1
2010-01-01 00:43:09.300000000,1
2010-01-01 00:28:03.780000000,1
2010-01-01 00:04:00.600000000,1
2010-01-01 00:54:14.310000000,1
2010-01-01 00:26:03.250000000,1
2010-01-01 00:32:04.960000000,1
2010-01-01 00:46:10.350000000,1
2010-01-01 00:37:06.660000000,1
2010-01-01 00:50:12.250000000,1
2010-01-01 00:27:03.510000000,1
2010-01-01 00:19:01.710000000,1
2010-01-01 00:40:07.800000000,1
2010-01-01 00:07:00.210000000,1
2010-01-01 00:22:02.310000000,1
2010-01-01 00:21:02.100000000,1
2010-01-01 00:18:01.530000000,1
2010-01-01 00:11:00.550000000,1
2010-01-01 00:35:05.950000000,1
2010-01-01 00:30:04.350000000,1
2010-01-01 00:08:00.280000000,1
2010-01-01 00:34:05.610000000,1
2010-01-01 00:15:01.500000000,1
2010-01-01 00:41:08.200000000,1
2010-01-01 00:02:00.100000000,1
2010-01-01 00:01:00,1
2010-01-01 00:10:00.450000000,1
2010-01-01 00:52:13.260000000,1
2010-01-01 01:04:20.160000000,1
2010-01-01 00:12:00.660000000,1
2010-01-01 00:38:07.300000000,1
2010-01-01 00:53:13.780000000,1
2010-01-01 00:25:03,1
2010-01-01 00:59:17.110000000,1
2010-01-01 00:06:00.150000000,1
2010-01-01 00:13:00.780000000,1
---- TYPES
timestamp, bigint
====
---- QUERY
# Test NULLs in aggregate functions
select count(NULL), min(NULL), max(NULL), sum(NULL), avg(NULL) from alltypesagg
where day is not null
---- RESULTS
0,NULL,NULL,NULL,NULL
---- TYPES
bigint, boolean, boolean, bigint, double
====
---- QUERY
# Test ignored distinct in MIN and MAX with NULLs
select min(distinct NULL), max(distinct NULL) from alltypesagg
where day is not null
---- RESULTS
NULL,NULL
---- TYPES
boolean, boolean
====
---- QUERY
# Test group_concat with default delimiter. Use a subquery with an ORDER BY to
# ensure group_concat results are in a deterministic order.
select day, group_concat(string_col)
from (select * from alltypesagg where id % 100 = day order by id limit 99999) a
group by day
---- RESULTS: VERIFY_IS_EQUAL_SORTED
3,'3, 103, 203, 303, 403, 503, 603, 703, 803, 903'
5,'5, 105, 205, 305, 405, 505, 605, 705, 805, 905'
8,'8, 108, 208, 308, 408, 508, 608, 708, 808, 908'
4,'4, 104, 204, 304, 404, 504, 604, 704, 804, 904'
9,'9, 109, 209, 309, 409, 509, 609, 709, 809, 909'
2,'2, 102, 202, 302, 402, 502, 602, 702, 802, 902'
6,'6, 106, 206, 306, 406, 506, 606, 706, 806, 906'
10,'10, 110, 210, 310, 410, 510, 610, 710, 810, 910'
7,'7, 107, 207, 307, 407, 507, 607, 707, 807, 907'
1,'1, 101, 201, 301, 401, 501, 601, 701, 801, 901'
---- TYPES
int, string
====
---- QUERY
# Test group_concat with NULL (default) delimiter
select day, group_concat(string_col, NULL)
from (select * from alltypesagg where id % 100 = day order by id limit 99999) a
group by day
---- RESULTS: VERIFY_IS_EQUAL_SORTED
3,'3, 103, 203, 303, 403, 503, 603, 703, 803, 903'
5,'5, 105, 205, 305, 405, 505, 605, 705, 805, 905'
8,'8, 108, 208, 308, 408, 508, 608, 708, 808, 908'
4,'4, 104, 204, 304, 404, 504, 604, 704, 804, 904'
9,'9, 109, 209, 309, 409, 509, 609, 709, 809, 909'
2,'2, 102, 202, 302, 402, 502, 602, 702, 802, 902'
6,'6, 106, 206, 306, 406, 506, 606, 706, 806, 906'
10,'10, 110, 210, 310, 410, 510, 610, 710, 810, 910'
7,'7, 107, 207, 307, 407, 507, 607, 707, 807, 907'
1,'1, 101, 201, 301, 401, 501, 601, 701, 801, 901'
---- TYPES
int, string
====
---- QUERY
# Test group_concat with both args as NULL
select day, group_concat(NULL, NULL)
from (select * from alltypesagg where id % 100 = day order by id limit 99999) a
group by day
---- RESULTS: VERIFY_IS_EQUAL_SORTED
3,'NULL'
5,'NULL'
8,'NULL'
4,'NULL'
9,'NULL'
2,'NULL'
6,'NULL'
10,'NULL'
7,'NULL'
1,'NULL'
---- TYPES
int, string
====
---- QUERY
# Test group_concat with arrow delimiter
select day, group_concat(string_col, "->")
from (select * from alltypesagg where id % 100 = day order by id limit 99999) a
group by day
---- RESULTS: VERIFY_IS_EQUAL_SORTED
3,'3->103->203->303->403->503->603->703->803->903'
5,'5->105->205->305->405->505->605->705->805->905'
8,'8->108->208->308->408->508->608->708->808->908'
4,'4->104->204->304->404->504->604->704->804->904'
9,'9->109->209->309->409->509->609->709->809->909'
2,'2->102->202->302->402->502->602->702->802->902'
6,'6->106->206->306->406->506->606->706->806->906'
10,'10->110->210->310->410->510->610->710->810->910'
7,'7->107->207->307->407->507->607->707->807->907'
1,'1->101->201->301->401->501->601->701->801->901'
---- TYPES
int, string
====
---- QUERY
# Test group_concat with column delimiter
# Will cause all columns save first to be duplicated
select day, group_concat(trim(string_col), trim(string_col))
from (select * from alltypesagg where id % 200 = day order by id limit 99999) a
group by day
---- RESULTS: VERIFY_IS_EQUAL_SORTED
3,'3203203403403603603803803'
5,'5205205405405605605805805'
8,'8208208408408608608808808'
4,'4204204404404604604804804'
9,'9209209409409609609809809'
2,'2202202402402602602802802'
6,'6206206406406606606806806'
10,'10210210410410610610810810'
7,'7207207407407607607807807'
1,'1201201401401601601801801'
---- TYPES
int, string
====
---- QUERY
# Test group_concat with multiple agg columns
select day, group_concat(string_col, '->'), group_concat(date_string_col)
from (select * from alltypesagg where id % 250 = day order by id limit 99999) a
group by day
---- RESULTS: VERIFY_IS_EQUAL_SORTED
3,'3->253->503->753','01/03/10, 01/03/10, 01/03/10, 01/03/10'
5,'5->255->505->755','01/05/10, 01/05/10, 01/05/10, 01/05/10'
8,'8->258->508->758','01/08/10, 01/08/10, 01/08/10, 01/08/10'
4,'4->254->504->754','01/04/10, 01/04/10, 01/04/10, 01/04/10'
9,'9->259->509->759','01/09/10, 01/09/10, 01/09/10, 01/09/10'
2,'2->252->502->752','01/02/10, 01/02/10, 01/02/10, 01/02/10'
6,'6->256->506->756','01/06/10, 01/06/10, 01/06/10, 01/06/10'
10,'10->260->510->760','01/10/10, 01/10/10, 01/10/10, 01/10/10'
7,'7->257->507->757','01/07/10, 01/07/10, 01/07/10, 01/07/10'
1,'1->251->501->751','01/01/10, 01/01/10, 01/01/10, 01/01/10'
---- TYPES
int, string, string
====
---- QUERY
# Test group_concat with null result
select group_concat(string_col) from alltypesagg where string_col = NULL;
---- RESULTS
'NULL'
---- TYPES
string
====
---- QUERY
# Test group_concat with merge node
select group_concat(string_col) from alltypesagg where int_col = 1
---- RESULTS
'1, 1, 1, 1, 1, 1, 1, 1, 1, 1'
---- TYPES
STRING
====
---- QUERY
# Test merge phase uses correct separator (IMPALA-1110). The query needs to load data
# from multiple nodes in order to exercise this path, however the merge order is
# non-deterministic. So, aggregate a string literal to make the result deterministic.
select group_concat('abc', 'xy') from functional.alltypesagg where id % 1000 = day
---- RESULTS
'abcxyabcxyabcxyabcxyabcxyabcxyabcxyabcxyabcxyabc'
---- TYPES
string
====
---- QUERY
# Test group_concat when separator varies by row.
select group_concat(cast(id as string), cast ((10 - id) as string))
from functional.alltypesagg
where id < 10 and day != null
group by day
---- RESULTS
'0918273645546372819'
---- TYPES
string
====
---- QUERY
# Test correct removal of redundant group-by expressions (IMPALA-817)
select int_col * int_col, int_col + int_col
from functional.alltypesagg
group by int_col * int_col, int_col + int_col, int_col * int_col
having (int_col + int_col) < 5 order by 1 limit 10
---- RESULTS
1,2
4,4
---- TYPES
bigint,bigint
====
---- QUERY
# Test that binding predicates on an aggregation properly trigger materialization of
# slots in the agg tuple and the slots needed for evaluating the corresponding agg funcs
# (IMPALA-822).
select 1 from
(select count(bigint_col) c from functional.alltypesagg
having min(int_col) is not null) as t
where c is not null
---- RESULTS
1
---- TYPES
tinyint
====
---- QUERY
# Regression test for subexpr elimination in codegen. IMPALA-765
select count(tinyint_col), sum(tinyint_col * tinyint_col) from alltypesagg
---- RESULTS
9000,285000
---- TYPES
bigint,bigint