Skip to content

Apache DataFusion SQL Query Engine

Add tests fpr nullability of AND/OR expressions (#26164)

siddu07077ff83ffe
diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt
index ee341880f7..fd7a6256a1 100644
--- a/datafusion/sqllogictest/test_files/aggregate.slt
+++ b/datafusion/sqllogictest/test_files/aggregate.slt
@@ -10295,3 +10295,35 @@ SELECT avg(DISTINCT v ORDER BY v), var(DISTINCT v ORDER BY v) FROM agg_order_by_
statement ok
DROP TABLE agg_order_by_t;
+
+##########
+# Regression test for https://github.com/apache/datafusion/issues/25978
+# A GROUP BY aggregate over a UNION ALL fails to plan when one branch
+# projects coalesce(<nullable boolean expression>, FALSE).
+# The CSE optimizer rewrites this into an AND/OR pattern whose
+# nullability was incorrectly reported, causing a physical vs logical
+# schema mismatch.
+##########
+
+statement ok
+CREATE TABLE a (k VARCHAR NOT NULL, x VARCHAR) AS VALUES ('k1', 'y'), ('k2', NULL);
+
+statement ok
+CREATE TABLE b (k VARCHAR NOT NULL) AS VALUES ('k3');
+
+query TB rowsort
+SELECT k, bool_or(f) AS f FROM (
+ SELECT k, coalesce(x = 'y', FALSE) AS f FROM a
+ UNION ALL
+ SELECT k, TRUE AS f FROM b
+) u GROUP BY k;
+----
+k1 true
+k2 false
+k3 true
+
+statement ok
+DROP TABLE a;
+
+statement ok
+DROP TABLE b;