Skip to content

[SPARK-57577][SQL] Surface timestamp constructor overflow as Spark error condition#56906

Draft
michaelmitchell-bit wants to merge 1 commit into
apache:masterfrom
michaelmitchell-bit:SPARK-57577-timestamp-function-overflow
Draft

[SPARK-57577][SQL] Surface timestamp constructor overflow as Spark error condition#56906
michaelmitchell-bit wants to merge 1 commit into
apache:masterfrom
michaelmitchell-bit:SPARK-57577-timestamp-function-overflow

Conversation

@michaelmitchell-bit

@michaelmitchell-bit michaelmitchell-bit commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR routes timestamp constructor overflow through DATETIME_OVERFLOW instead of raw ArithmeticException for overflowing timestamp_seconds and timestamp_millis inputs.

It adds a shared QueryExecutionErrors helper for timestamp constructor overflow, uses it from interpreted and code-generated expression paths, and keeps the existing non-overflow decimal rounding behavior unchanged. timestamp_micros already accepts microseconds directly and has no unit-scaling overflow path, so this PR preserves its existing max/min input behavior.

Why are the changes needed?

The existing overflow paths can surface raw Java arithmetic errors such as long overflow or Overflow, which do not carry a Spark error condition or SQLSTATE. These timestamp constructor overflow cases should report a Spark error condition, consistent with other datetime overflow handling.

Does this PR introduce any user-facing change?

Yes. Overflowing timestamp_seconds and timestamp_millis inputs now fail with DATETIME_OVERFLOW / SQLSTATE 22008 instead of a raw ArithmeticException.

How was this patch tested?

./build/sbt "catalyst/testOnly org.apache.spark.sql.catalyst.expressions.DateExpressionsSuite -- -z TIMESTAMP_SECONDS -z TIMESTAMP_MILLIS -z TIMESTAMP_MICROS"
./build/sbt "sql/testOnly org.apache.spark.sql.errors.QueryExecutionErrorsSuite -- -z constructors"

Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex

@michaelmitchell-bit michaelmitchell-bit force-pushed the SPARK-57577-timestamp-function-overflow branch from cafd05e to e0308aa Compare June 30, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant