kosiew opened a new pull request, #18761: URL: https://github.com/apache/datafusion/pull/18761
## Which issue does this PR close? * Closes #17534. ## Rationale for this change This change ensures that casting from `Date32` or `Date64` to timestamp types behaves safely and predictably. Previously, extreme date values (e.g., `9999-12-31`) could cause integer overflow during unit conversion, leading to panics in debug mode and silent incorrect results in release mode. This patch introduces explicit bounds checking so these cases return clear, user-facing errors instead of panicking. ## What changes are included in this PR? * Introduces `date_to_timestamp_multiplier` and `ensure_timestamp_in_bounds` to centralize safe conversion logic. * Adds bounds validation for both scalar and array-based casts, preventing overflow when multiplying date values. * Enhances error messages with consistent timestamp type formatting. * Integrates bounds checks into `ScalarValue::cast_to` and `ColumnarValue::cast_to`. * Adds comprehensive tests covering formatting, overflow detection, scalar casts, array casts, and SQL-level behavior. ## Are these changes tested? Yes. The PR includes new unit tests validating: * Formatting of timestamp types in error messages. * Overflow detection for both `Date32` and `Date64` to nanoseconds. * Array-based overflow handling. * SQL-level behavior for casting large date literals. ## Are there any user-facing changes? Yes. Users now receive clear and consistent error messages when attempting to cast dates that exceed the representable timestamp range (approximately ±2262 years). Instead of panics or silent overflow, a descriptive execution error is returned. ## LLM-generated code disclosure This pull request includes LLM-generated content that has been manually reviewed and tested. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
