From 18833ecd658994078292951f46dfccf69e1aa85b Mon Sep 17 00:00:00 2001 From: jx2lee Date: Sun, 17 May 2026 22:18:09 +0900 Subject: [PATCH 1/3] return None not panic --- datafusion/expr-common/src/interval_arithmetic.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/datafusion/expr-common/src/interval_arithmetic.rs b/datafusion/expr-common/src/interval_arithmetic.rs index e2f8198c92845..8f727ea7f23d1 100644 --- a/datafusion/expr-common/src/interval_arithmetic.rs +++ b/datafusion/expr-common/src/interval_arithmetic.rs @@ -944,7 +944,7 @@ impl Interval { // Cardinality calculations are not implemented for this data type yet: None } - .map(|result| result + 1) + .and_then(|result| result.checked_add(1)) } /// Reflects an [`Interval`] around the point zero. @@ -4157,6 +4157,16 @@ mod tests { ScalarValue::TimestampNanosecond(Some(2_000_000_000), None), )?; assert_eq!(interval.cardinality().unwrap(), 1_000_000_001); + Ok(()) + } + + #[test] + fn test_cardinality_full_i64_range_does_not_overflow() -> Result<()> { + let interval = Interval::try_new( + ScalarValue::Int64(Some(i64::MIN)), + ScalarValue::Int64(Some(i64::MAX)), + )?; + assert_eq!(interval.cardinality(), None); Ok(()) } From 98ce8fc1f27043d199acade3b8509b055191fb7a Mon Sep 17 00:00:00 2001 From: jx2lee Date: Wed, 20 May 2026 06:37:52 +0900 Subject: [PATCH 2/3] add query --- datafusion/sqllogictest/test_files/select.slt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/datafusion/sqllogictest/test_files/select.slt b/datafusion/sqllogictest/test_files/select.slt index 3e97dc4588655..762f5c11333d2 100644 --- a/datafusion/sqllogictest/test_files/select.slt +++ b/datafusion/sqllogictest/test_files/select.slt @@ -960,6 +960,12 @@ physical_plan 01)ProjectionExec: expr=[c1@0 >= 2 AND c1@0 <= 3 as select_between_data.c1 BETWEEN Int64(2) AND Int64(3)] 02)--DataSourceExec: partitions=1, partition_sizes=[1] +# regression test: full i64 BETWEEN bounds should not overflow +query I +SELECT * FROM (VALUES (1)) AS t(x) +WHERE x BETWEEN -9223372036854775808 AND 9223372036854775807 +---- +1 # TODO: query_get_indexed_field From 615665c2d315ac3ce7ef3c954729b532bb78870b Mon Sep 17 00:00:00 2001 From: jx2lee Date: Wed, 27 May 2026 22:45:07 +0900 Subject: [PATCH 3/3] rename test and testcase for u64 --- datafusion/expr-common/src/interval_arithmetic.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/datafusion/expr-common/src/interval_arithmetic.rs b/datafusion/expr-common/src/interval_arithmetic.rs index 8f727ea7f23d1..51858be538f5a 100644 --- a/datafusion/expr-common/src/interval_arithmetic.rs +++ b/datafusion/expr-common/src/interval_arithmetic.rs @@ -4161,13 +4161,18 @@ mod tests { } #[test] - fn test_cardinality_full_i64_range_does_not_overflow() -> Result<()> { + fn test_cardinality_full_integer_range_does_not_overflow() -> Result<()> { let interval = Interval::try_new( ScalarValue::Int64(Some(i64::MIN)), ScalarValue::Int64(Some(i64::MAX)), )?; assert_eq!(interval.cardinality(), None); + let interval = Interval::try_new( + ScalarValue::UInt64(Some(0)), + ScalarValue::UInt64(Some(u64::MAX)), + )?; + assert_eq!(interval.cardinality(), None); Ok(()) }