From 1d7049e4f6f33844bdde9ef2e83881ce9bc9a182 Mon Sep 17 00:00:00 2001 From: Kartik Gupta Date: Sat, 7 Mar 2026 22:02:19 +0530 Subject: [PATCH 1/4] fix/substrait-lambda-rextype-0.62.3+ --- datafusion/substrait/src/logical_plan/consumer/expr/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs b/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs index 5d98850c72cca..ddbfbc6978302 100644 --- a/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs +++ b/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs @@ -93,6 +93,13 @@ pub async fn from_substrait_rex( RexType::DynamicParameter(expr) => { consumer.consume_dynamic_parameter(expr, input_schema).await } + RexType::Lambda(_) => { + not_impl_err!("Lambda expressions are not yet supported") + } + RexType::LambdaInvocation(_) => { + not_impl_err!("LambdaInvocation expressions are not yet supported") + } + }, }, None => substrait_err!("Expression must set rex_type: {expression:?}"), } From f1474fed840c4395f30b069ab6d32a731e593c99 Mon Sep 17 00:00:00 2001 From: Kartik Gupta Date: Sun, 8 Mar 2026 15:15:30 +0530 Subject: [PATCH 2/4] fix/issue-20779-subtract-overflow --- datafusion/physical-plan/src/joins/utils.rs | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/datafusion/physical-plan/src/joins/utils.rs b/datafusion/physical-plan/src/joins/utils.rs index cf4bf2cd163fd..d9098cfd9673a 100644 --- a/datafusion/physical-plan/src/joins/utils.rs +++ b/datafusion/physical-plan/src/joins/utils.rs @@ -721,12 +721,13 @@ fn max_distinct_count( Some(non_null_count) => Precision::Inexact(non_null_count), } } - Precision::Exact(count) => { - let count = count - stats.null_count.get_value().unwrap_or(&0); + Precision::Exact(count) => { + let null_count = *stats.null_count.get_value().unwrap_or(&0); + let non_null_count = count.checked_sub(null_count).unwrap_or(0); if stats.null_count.is_exact().unwrap_or(false) { - Precision::Exact(count) + Precision::Exact(non_null_count) } else { - Precision::Inexact(count) + Precision::Inexact(non_null_count) } } }; @@ -2939,4 +2940,19 @@ mod tests { Ok(()) } -} + #[test] + fn test_max_distinct_count_no_overflow_when_null_count_exceeds_num_rows() { + let num_rows = Precision::Exact(2); + let stats = ColumnStatistics { + distinct_count: Precision::Absent, + null_count: Precision::Exact(5), + min_value: Precision::Absent, + max_value: Precision::Absent, + sum_value: Precision::Absent, + byte_size: Precision::Absent, + }; + let result = max_distinct_count(&num_rows, &stats); + assert_eq!(result, Precision::Exact(0)); + } + +} \ No newline at end of file From 36d156bbcf1491f1f9570b13463862ba921be11c Mon Sep 17 00:00:00 2001 From: Kartik Gupta Date: Sun, 8 Mar 2026 15:23:30 +0530 Subject: [PATCH 3/4] fix/issue-20779 --- datafusion/substrait/src/logical_plan/consumer/expr/mod.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs b/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs index ddbfbc6978302..5d98850c72cca 100644 --- a/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs +++ b/datafusion/substrait/src/logical_plan/consumer/expr/mod.rs @@ -93,13 +93,6 @@ pub async fn from_substrait_rex( RexType::DynamicParameter(expr) => { consumer.consume_dynamic_parameter(expr, input_schema).await } - RexType::Lambda(_) => { - not_impl_err!("Lambda expressions are not yet supported") - } - RexType::LambdaInvocation(_) => { - not_impl_err!("LambdaInvocation expressions are not yet supported") - } - }, }, None => substrait_err!("Expression must set rex_type: {expression:?}"), } From bf2bdc2aad70ad44de54d51a570fe2205740c51d Mon Sep 17 00:00:00 2001 From: Kartik Gupta Date: Mon, 9 Mar 2026 10:45:53 +0530 Subject: [PATCH 4/4] sqllogic test updated --- datafusion/sqllogictest/test_files/joins.slt | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/datafusion/sqllogictest/test_files/joins.slt b/datafusion/sqllogictest/test_files/joins.slt index 228918c3855f2..3e81527738091 100644 --- a/datafusion/sqllogictest/test_files/joins.slt +++ b/datafusion/sqllogictest/test_files/joins.slt @@ -5361,3 +5361,26 @@ DROP TABLE t1; statement count 0 DROP TABLE t2; + +statement ok +CREATE TABLE t1(a INT, b INT) AS VALUES + (NULL, 1), (NULL, 2), (NULL, 3), (NULL, 4), (NULL, 5); + +statement ok +CREATE TABLE t2(c INT) AS VALUES (1), (2); + +# This query panicked before the fix: the ORDER BY forces a SortExec, +# the LIMIT gets pushed into SortExec.fetch, and the HashJoinExec +# calls partition_statistics() on the SortExec child during execution. +query II +SELECT sub.a, sub.b FROM ( + SELECT * FROM t1 ORDER BY b LIMIT 1 +) sub +JOIN t2 ON sub.a = t2.c; +---- + +statement ok +DROP TABLE t1; + +statement ok +DROP TABLE t2; \ No newline at end of file