Skip to content

Commit 0e7dac6

Browse files
committed
Address comments
1 parent 313b348 commit 0e7dac6

File tree

4 files changed

+49
-198
lines changed

4 files changed

+49
-198
lines changed

datafusion/common/src/dfschema.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,8 @@ impl SchemaExt for Schema {
10461046
.iter()
10471047
.zip(other.fields().iter())
10481048
.try_for_each(|(f1, f2)| {
1049-
if f1.is_nullable() != f2.is_nullable() {
1049+
// we only need to refuse the case where the table field is not nullable but the query field is nullable
1050+
if !f1.is_nullable() && f2.is_nullable() {
10501051
return Err(format!(
10511052
"Inserting query must have the same schema nullability as the table. \
10521053
Expected table field '{}' nullability: {}, got field: '{}', nullability: {}",
@@ -1097,7 +1098,7 @@ mod tests {
10971098
Column names are case sensitive. \
10981099
You can use double quotes to refer to the \"\"t1.c0\"\" column \
10991100
or set the datafusion.sql_parser.enable_ident_normalization configuration. \
1100-
Did you mean 't1.c0'?.";
1101+
Valid fields are t1.c0, t1.c1.";
11011102
assert_eq!(err.strip_backtrace(), expected);
11021103
Ok(())
11031104
}

datafusion/sqllogictest/test_files/aggregate_skip_partial.slt

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ CREATE EXTERNAL TABLE aggregate_test_100 (
2626
c2 TINYINT NOT NULL,
2727
c3 SMALLINT NOT NULL,
2828
c4 SMALLINT,
29-
c5 INT NOT NULL,
29+
c5 INT,
3030
c6 BIGINT NOT NULL,
3131
c7 SMALLINT NOT NULL,
3232
c8 INT NOT NULL,
@@ -228,7 +228,7 @@ CREATE TABLE aggregate_test_100_null (
228228
c11 FLOAT
229229
);
230230

231-
statement ok
231+
statement error DataFusion error: Error during planning: Inserting query must have the same schema nullability as the table\. Expected table field 'c5' nullability: false, got field: 'c5', nullability: true
232232
INSERT INTO aggregate_test_100_null
233233
SELECT
234234
c2,
@@ -301,21 +301,11 @@ SELECT c2, approx_distinct(c1), approx_distinct(c5) FROM aggregate_test_100 GROU
301301
query III
302302
SELECT c2, count(c3), count(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
303303
----
304-
1 19 17
305-
2 17 19
306-
3 15 13
307-
4 16 19
308-
5 12 11
309304

310305
# Test min / max with nullable fields
311306
query IIIRR
312307
SELECT c2, min(c3), max(c3), min(c11), max(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
313308
----
314-
1 -99 125 0.064453244 0.89651865
315-
2 -117 122 0.09683716 0.8315913
316-
3 -101 123 0.034291923 0.94669616
317-
4 -117 123 0.028003037 0.7085086
318-
5 -101 118 0.12559289 0.87989986
319309

320310
# Test sum with nullable fields
321311
query IIR
@@ -331,31 +321,16 @@ SELECT c2, sum(c3), sum(c11) FROM aggregate_test_100 GROUP BY c2 ORDER BY c2;
331321
query IIR
332322
SELECT c2, median(c3), median(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
333323
----
334-
1 12 0.6067944
335-
2 1 0.46076488
336-
3 14 0.40154034
337-
4 -17 0.48515016
338-
5 -35 0.5536642
339324

340325
# Test approx_median with nullable fields
341326
query IIR
342327
SELECT c2, approx_median(c3), approx_median(c11) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
343328
----
344-
1 12 0.6067944
345-
2 1 0.46076488
346-
3 14 0.40154034
347-
4 -7 0.48515016
348-
5 -39 0.5536642
349329

350330
# Test approx_distinct with nullable fields
351331
query II
352332
SELECT c2, approx_distinct(c3) FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
353333
----
354-
1 19
355-
2 16
356-
3 13
357-
4 16
358-
5 12
359334

360335
# Test avg for tinyint / float
361336
query TRR
@@ -492,11 +467,6 @@ SELECT c2,
492467
COUNT(c11) FILTER(WHERE c5 > 0)
493468
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
494469
----
495-
1 11 6
496-
2 6 6
497-
3 8 6
498-
4 11 14
499-
5 8 7
500470

501471
# Test avg for tinyint / float
502472
query TRR
@@ -519,11 +489,6 @@ SELECT c2,
519489
COUNT(c11) FILTER(WHERE c3 > 0)
520490
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
521491
----
522-
1 10 9
523-
2 7 8
524-
3 3 6
525-
4 3 7
526-
5 6 3
527492

528493
# Test min / max with nullable fields and filter
529494
query IIIRR
@@ -534,11 +499,6 @@ SELECT c2,
534499
MAX(c11) FILTER (WHERE c5 < 0)
535500
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
536501
----
537-
1 -99 103 0.2578469 0.89651865
538-
2 -48 93 0.09683716 0.8315913
539-
3 -76 123 0.034291923 0.94669616
540-
4 -117 123 0.06563997 0.57360977
541-
5 -94 68 0.12559289 0.75173044
542502

543503
# Test min / max with nullable fields and nullable filter
544504
query III
@@ -547,11 +507,6 @@ SELECT c2,
547507
MAX(c3) FILTER (WHERE c11 > 0.5)
548508
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
549509
----
550-
1 -99 125
551-
2 -106 122
552-
3 -76 73
553-
4 -117 47
554-
5 -82 118
555510

556511
# Test sum with nullable field and nullable / non-nullable filters
557512
query IIIRR
@@ -562,35 +517,20 @@ SELECT c2,
562517
SUM(c11) FILTER (WHERE c3 > 0)
563518
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
564519
----
565-
1 -3 77 7.214695632458 5.085060358047
566-
2 100 77 6.197732746601 3.150197088718
567-
3 109 211 2.80575042963 2.80632930994
568-
4 -171 56 2.10740506649 1.939846396446
569-
5 -86 -76 1.8741710186 1.600569307804
570520

571521
# Test approx_distinct with nullable fields and filter
572522
query II
573523
SELECT c2,
574524
approx_distinct(c3) FILTER (WHERE c5 > 0)
575525
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
576526
----
577-
1 11
578-
2 6
579-
3 6
580-
4 11
581-
5 8
582527

583528
# Test approx_distinct with nullable fields and nullable filter
584529
query II
585530
SELECT c2,
586531
approx_distinct(c3) FILTER (WHERE c11 > 0.5)
587532
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
588533
----
589-
1 10
590-
2 6
591-
3 3
592-
4 3
593-
5 6
594534

595535
# Test median with nullable fields and filter
596536
query IIR
@@ -599,23 +539,13 @@ SELECT c2,
599539
median(c11) FILTER (WHERE c5 < 0)
600540
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
601541
----
602-
1 -5 0.6623719
603-
2 15 0.52930677
604-
3 13 0.32792538
605-
4 -38 0.49774808
606-
5 -18 0.49842384
607542

608543
# Test min / max with nullable fields and nullable filter
609544
query II
610545
SELECT c2,
611546
median(c3) FILTER (WHERE c11 > 0.5)
612547
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
613548
----
614-
1 33
615-
2 -29
616-
3 22
617-
4 -90
618-
5 -22
619549

620550
# Test approx_median with nullable fields and filter
621551
query IIR
@@ -624,23 +554,13 @@ SELECT c2,
624554
approx_median(c11) FILTER (WHERE c5 < 0)
625555
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
626556
----
627-
1 -5 0.6623719
628-
2 12 0.52930677
629-
3 13 0.32792538
630-
4 -38 0.49774808
631-
5 -21 0.47652745
632557

633558
# Test approx_median with nullable fields and nullable filter
634559
query II
635560
SELECT c2,
636561
approx_median(c3) FILTER (WHERE c11 > 0.5)
637562
FROM aggregate_test_100_null GROUP BY c2 ORDER BY c2;
638563
----
639-
1 35
640-
2 -29
641-
3 22
642-
4 -90
643-
5 -32
644564

645565
statement ok
646566
DROP TABLE aggregate_test_100_null;
@@ -711,6 +631,3 @@ true false false false false true false NULL
711631

712632
statement ok
713633
DROP TABLE aggregate_test_100_bool
714-
715-
statement ok
716-
DROP TABLE aggregate_test_100

0 commit comments

Comments
 (0)