Skip to content

Commit 07077ff

Browse files
authored
Add tests fpr nullability of AND/OR expressions (apache#26164)
Fixes apache#25978 This PR fixes an internal error where the physical input schema mismatches the logical input schema due to incorrect nullability propagation for AND/OR expressions in CommonSubexprEliminate. It adds robust contains_is_not_null and contains_is_null helper functions to accurately determine if binary expressions are nullable. cc @alamb @jayzhan211
1 parent 0eb098a commit 07077ff

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎datafusion/sqllogictest/test_files/aggregate.slt‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10295,3 +10295,35 @@ SELECT avg(DISTINCT v ORDER BY v), var(DISTINCT v ORDER BY v) FROM agg_order_by_
1029510295

1029610296
statement ok
1029710297
DROP TABLE agg_order_by_t;
10298+
10299+
##########
10300+
# Regression test for https://github.com/apache/datafusion/issues/25978
10301+
# A GROUP BY aggregate over a UNION ALL fails to plan when one branch
10302+
# projects coalesce(<nullable boolean expression>, FALSE).
10303+
# The CSE optimizer rewrites this into an AND/OR pattern whose
10304+
# nullability was incorrectly reported, causing a physical vs logical
10305+
# schema mismatch.
10306+
##########
10307+
10308+
statement ok
10309+
CREATE TABLE a (k VARCHAR NOT NULL, x VARCHAR) AS VALUES ('k1', 'y'), ('k2', NULL);
10310+
10311+
statement ok
10312+
CREATE TABLE b (k VARCHAR NOT NULL) AS VALUES ('k3');
10313+
10314+
query TB rowsort
10315+
SELECT k, bool_or(f) AS f FROM (
10316+
SELECT k, coalesce(x = 'y', FALSE) AS f FROM a
10317+
UNION ALL
10318+
SELECT k, TRUE AS f FROM b
10319+
) u GROUP BY k;
10320+
----
10321+
k1 true
10322+
k2 false
10323+
k3 true
10324+
10325+
statement ok
10326+
DROP TABLE a;
10327+
10328+
statement ok
10329+
DROP TABLE b;

0 commit comments

Comments
 (0)