@@ -220,6 +220,9 @@ set datafusion.execution.batch_size = 4;
220
220
221
221
# Inserting into nullable table with batch_size specified above
222
222
# to prevent creation on single in-memory batch
223
+
224
+ # Test error case: the error case is expected here, as the table c5 is not nullable
225
+ # and the query tries to insert a nullable value
223
226
statement ok
224
227
CREATE TABLE aggregate_test_100_null (
225
228
c2 TINYINT NOT NULL,
@@ -237,6 +240,27 @@ SELECT
237
240
CASE WHEN c1 = 'a' THEN NULL ELSE c11 END as c11
238
241
FROM aggregate_test_100;
239
242
243
+ statement ok
244
+ drop table aggregate_test_100_null;
245
+
246
+ # Test successful insert case which c5 is nullable
247
+ statement ok
248
+ CREATE TABLE aggregate_test_100_null (
249
+ c2 TINYINT NOT NULL,
250
+ c5 INT,
251
+ c3 SMALLINT,
252
+ c11 FLOAT
253
+ );
254
+
255
+ statement ok
256
+ INSERT INTO aggregate_test_100_null
257
+ SELECT
258
+ c2,
259
+ c5,
260
+ CASE WHEN c1 = 'e' THEN NULL ELSE c3 END as c3,
261
+ CASE WHEN c1 = 'a' THEN NULL ELSE c11 END as c11
262
+ FROM aggregate_test_100;
263
+
240
264
# Test count varchar / int / float
241
265
query IIII
242
266
SELECT c2, count(c1), count(c5), count(c11) FROM aggregate_test_100 GROUP BY c2 ORDER BY c2;
@@ -301,11 +325,21 @@ SELECT c2, approx_distinct(c1), approx_distinct(c5) FROM aggregate_test_100 GROU
301
325
query III
302
326
SELECT c2, count(c3), count(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
303
327
----
328
+ 1 19 17
329
+ 2 17 19
330
+ 3 15 13
331
+ 4 16 19
332
+ 5 12 11
304
333
305
334
# Test min / max with nullable fields
306
335
query IIIRR
307
336
SELECT c2, min(c3), max(c3), min(c11), max(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
308
337
----
338
+ 1 -99 125 0.064453244 0.89651865
339
+ 2 -117 122 0.09683716 0.8315913
340
+ 3 -101 123 0.034291923 0.94669616
341
+ 4 -117 123 0.028003037 0.7085086
342
+ 5 -101 118 0.12559289 0.87989986
309
343
310
344
# Test sum with nullable fields
311
345
query IIR
@@ -321,16 +355,31 @@ SELECT c2, sum(c3), sum(c11) FROM aggregate_test_100 GROUP BY c2 ORDER BY c2;
321
355
query IIR
322
356
SELECT c2, median(c3), median(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
323
357
----
358
+ 1 12 0.6067944
359
+ 2 1 0.46076488
360
+ 3 14 0.40154034
361
+ 4 -17 0.48515016
362
+ 5 -35 0.5536642
324
363
325
364
# Test approx_median with nullable fields
326
365
query IIR
327
366
SELECT c2, approx_median(c3), approx_median(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
328
367
----
368
+ 1 12 0.6067944
369
+ 2 1 0.46076488
370
+ 3 14 0.40154034
371
+ 4 -7 0.48515016
372
+ 5 -39 0.5536642
329
373
330
374
# Test approx_distinct with nullable fields
331
375
query II
332
376
SELECT c2, approx_distinct(c3) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
333
377
----
378
+ 1 19
379
+ 2 16
380
+ 3 13
381
+ 4 16
382
+ 5 12
334
383
335
384
# Test avg for tinyint / float
336
385
query TRR
@@ -467,6 +516,11 @@ SELECT c2,
467
516
COUNT(c11) FILTER(WHERE c5 > 0)
468
517
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
469
518
----
519
+ 1 11 6
520
+ 2 6 6
521
+ 3 8 6
522
+ 4 11 14
523
+ 5 8 7
470
524
471
525
# Test avg for tinyint / float
472
526
query TRR
@@ -489,6 +543,11 @@ SELECT c2,
489
543
COUNT(c11) FILTER(WHERE c3 > 0)
490
544
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
491
545
----
546
+ 1 10 9
547
+ 2 7 8
548
+ 3 3 6
549
+ 4 3 7
550
+ 5 6 3
492
551
493
552
# Test min / max with nullable fields and filter
494
553
query IIIRR
@@ -499,6 +558,11 @@ SELECT c2,
499
558
MAX(c11) FILTER (WHERE c5 < 0)
500
559
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
501
560
----
561
+ 1 -99 103 0.2578469 0.89651865
562
+ 2 -48 93 0.09683716 0.8315913
563
+ 3 -76 123 0.034291923 0.94669616
564
+ 4 -117 123 0.06563997 0.57360977
565
+ 5 -94 68 0.12559289 0.75173044
502
566
503
567
# Test min / max with nullable fields and nullable filter
504
568
query III
@@ -507,6 +571,11 @@ SELECT c2,
507
571
MAX(c3) FILTER (WHERE c11 > 0.5)
508
572
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
509
573
----
574
+ 1 -99 125
575
+ 2 -106 122
576
+ 3 -76 73
577
+ 4 -117 47
578
+ 5 -82 118
510
579
511
580
# Test sum with nullable field and nullable / non-nullable filters
512
581
query IIIRR
@@ -517,20 +586,35 @@ SELECT c2,
517
586
SUM(c11) FILTER (WHERE c3 > 0)
518
587
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
519
588
----
589
+ 1 -3 77 7.214695632458 5.085060358047
590
+ 2 100 77 6.197732746601 3.150197088718
591
+ 3 109 211 2.80575042963 2.80632930994
592
+ 4 -171 56 2.10740506649 1.939846396446
593
+ 5 -86 -76 1.8741710186 1.600569307804
520
594
521
595
# Test approx_distinct with nullable fields and filter
522
596
query II
523
597
SELECT c2,
524
598
approx_distinct(c3) FILTER (WHERE c5 > 0)
525
599
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
526
600
----
601
+ 1 11
602
+ 2 6
603
+ 3 6
604
+ 4 11
605
+ 5 8
527
606
528
607
# Test approx_distinct with nullable fields and nullable filter
529
608
query II
530
609
SELECT c2,
531
610
approx_distinct(c3) FILTER (WHERE c11 > 0.5)
532
611
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
533
612
----
613
+ 1 10
614
+ 2 6
615
+ 3 3
616
+ 4 3
617
+ 5 6
534
618
535
619
# Test median with nullable fields and filter
536
620
query IIR
@@ -539,13 +623,23 @@ SELECT c2,
539
623
median(c11) FILTER (WHERE c5 < 0)
540
624
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
541
625
----
626
+ 1 -5 0.6623719
627
+ 2 15 0.52930677
628
+ 3 13 0.32792538
629
+ 4 -38 0.49774808
630
+ 5 -18 0.49842384
542
631
543
632
# Test min / max with nullable fields and nullable filter
544
633
query II
545
634
SELECT c2,
546
635
median(c3) FILTER (WHERE c11 > 0.5)
547
636
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
548
637
----
638
+ 1 33
639
+ 2 -29
640
+ 3 22
641
+ 4 -90
642
+ 5 -22
549
643
550
644
# Test approx_median with nullable fields and filter
551
645
query IIR
@@ -554,13 +648,23 @@ SELECT c2,
554
648
approx_median(c11) FILTER (WHERE c5 < 0)
555
649
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
556
650
----
651
+ 1 -5 0.6623719
652
+ 2 12 0.52930677
653
+ 3 13 0.32792538
654
+ 4 -38 0.49774808
655
+ 5 -21 0.47652745
557
656
558
657
# Test approx_median with nullable fields and nullable filter
559
658
query II
560
659
SELECT c2,
561
660
approx_median(c3) FILTER (WHERE c11 > 0.5)
562
661
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
563
662
----
663
+ 1 35
664
+ 2 -29
665
+ 3 22
666
+ 4 -90
667
+ 5 -32
564
668
565
669
statement ok
566
670
DROP TABLE aggregate_test_100_null;
0 commit comments