Skip to content

Commit e74b83a

Browse files
haohuaijinalamb
andauthored
fix: date overflow panic (#21233)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #21234 ## Rationale for this change - see #21234 ## What changes are included in this PR? handle Date32 and Date64 in `get_extreme_value` function ## Are these changes tested? yes, add test case ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent c473c18 commit e74b83a

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

datafusion/expr-common/src/interval_arithmetic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ macro_rules! get_extreme_value {
4949
DataType::Int64 => ScalarValue::Int64(Some(i64::$extreme)),
5050
DataType::Float32 => ScalarValue::Float32(Some(f32::$extreme)),
5151
DataType::Float64 => ScalarValue::Float64(Some(f64::$extreme)),
52+
DataType::Date32 => ScalarValue::Date32(Some(i32::$extreme)),
53+
DataType::Date64 => ScalarValue::Date64(Some(i64::$extreme)),
5254
DataType::Duration(TimeUnit::Second) => {
5355
ScalarValue::DurationSecond(Some(i64::$extreme))
5456
}

datafusion/sqllogictest/test_files/datetime/arith_date_interval.slt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ query T
3535
SELECT arrow_typeof('2001-09-28'::date - interval '25 hour')
3636
----
3737
Date32
38+
39+
query error Arrow error: Compute error: Date arithmetic overflow
40+
SELECT arrow_cast('2020-01-01', 'Date32') + INTERVAL '999999' YEAR
41+
42+
query error Arrow error: Compute error: Date arithmetic overflow
43+
SELECT arrow_cast('2020-01-01', 'Date32') - INTERVAL '999999' YEAR
44+
45+
query error Arrow error: Compute error: Date arithmetic overflow
46+
SELECT arrow_cast('2020-01-01', 'Date64') + INTERVAL '999999' YEAR
47+
48+
query error Arrow error: Compute error: Date arithmetic overflow
49+
SELECT arrow_cast('2020-01-01', 'Date64') - INTERVAL '999999' YEAR

0 commit comments

Comments
 (0)