[SPARK-57501][SQL] Add +/- ANSI day-time interval support for TIMESTAMP_NTZ/LTZ(p)#56562
Open
MaxGekk wants to merge 8 commits into
Open
[SPARK-57501][SQL] Add +/- ANSI day-time interval support for TIMESTAMP_NTZ/LTZ(p)#56562MaxGekk wants to merge 8 commits into
MaxGekk wants to merge 8 commits into
Conversation
…stamp nanos types Enable TIMESTAMP_NTZ(p)/TIMESTAMP_LTZ(p) (p in [7, 9]) to participate in +/- ANSI day-time interval arithmetic with analyzer and expression parity to microsecond timestamps. Preserve nanosWithinMicro during interval arithmetic and add catalyst/SQL coverage with regenerated golden files.
Remove AnyTimestampFamilyType and AnyTimestampFamilyTypeExpression and reuse existing timestamp type collections/matchers in the nanos ANSI day-time interval path. Keep subtract-timestamps resolver/type checks unchanged to keep this PR scoped to interval arithmetic parity.
…stamp arithmetic Restrict TIMESTAMP_NTZ/LTZ(p) interval arithmetic in TimestampAddInterval to ANSI day-time intervals and return an analysis-time type mismatch for CalendarIntervalType inputs. Add catalyst checks that nanos timestamp operands reject calendar intervals.
…ches Drop the remaining CalendarIntervalType nanos eval/codegen branches in TimestampAddInterval now that nanos + calendar interval is rejected during analysis. Keep runtime/codegen paths aligned with the enforced type-check behavior.
…ranch Collapse the CalendarIntervalType timestampAddInterval call to a single line to keep this hunk closer to the original code layout while preserving behavior.
…helper The nanos calendar-interval eval/codegen branches were dropped once nanos + calendar interval became a type-check error, leaving DateTimeUtils.timestampNanosAddInterval without any callers. Remove the dead helper. Co-authored-by: Isaac
…mestamp adds Keep TimestampAddInterval's new nanos support while restoring the historical requiredType wording for non-timestamp left operands. This avoids unrelated analyzer golden churn (for example interval.sql_analyzer_test) while still rejecting nanos + calendar intervals.
…rval add errors Make TimestampAddInterval type-check errors report both micro and nanos timestamp families for invalid left operands. Regenerate interval analyzer goldens to match the corrected requiredType text in ansi and nonansi variants.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR adds support for
TIMESTAMP_NTZ(p)/TIMESTAMP_LTZ(p)(p in [7, 9]) in+/- ANSI day-time intervalarithmetic.Concretely:
TimestampAddIntervalinput typing to accept nanos timestamp types alongside existing microsecond timestamp types.nanosWithinMicrowhile applying interval arithmetic on epoch micros.CalendarIntervalTypewith nanos timestamps now reports a type mismatch.DateTimeUtilsto keep nanos remainder unchanged during timestamp +/- day-time interval operations.requiredTypenow correctly reports both micro and nanos timestamp families.A small follow-up commit in this branch removes temporary helper abstractions (
AnyTimestampFamilyType/AnyTimestampFamilyTypeExpression) and keeps the change scoped without wideningSubtractTimestampshandling.Why are the changes needed?
Spark already supports timestamp +/- ANSI day-time interval for microsecond timestamp families, but nanos timestamp families (
TIMESTAMP_NTZ(p)/TIMESTAMP_LTZ(p),p in [7, 9]) lacked parity. This left valid datetime arithmetic unsupported for nanos types.These changes close that parity gap while preserving nanos precision semantics and existing LTZ/NTZ timezone behavior.
Does this PR introduce any user-facing change?
Yes.
TIMESTAMP_NTZ(p)/TIMESTAMP_LTZ(p)(p in [7, 9]) now support+/- ANSI day-time intervalarithmetic.For nanos timestamps,
CalendarIntervalTypeis rejected with a type mismatch and users should use ANSI day-time intervals.Examples:
TIMESTAMP_NTZ '2020-01-02 03:04:05.123456789' + INTERVAL '2 00:03:00.000456' DAY TO SECONDTIMESTAMP_LTZ '2020-01-02 03:04:05.123456789 UTC' - INTERVAL '1 00:04:00.000321' DAY TO SECONDHow was this patch tested?
build/sbt 'catalyst/testOnly org.apache.spark.sql.catalyst.expressions.DateExpressionsSuite'SPARK_GENERATE_GOLDEN_FILES=1 build/sbt 'sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "timestamp-ntz-nanos"'SPARK_GENERATE_GOLDEN_FILES=1 build/sbt 'sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "timestamp-ltz-nanos"'SPARK_GENERATE_GOLDEN_FILES=1 build/sbt 'sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "interval"'./dev/scalastyle./build/mvn scalafmt:format -Dscalafmt.skip=false -Dscalafmt.validateOnly=false -Dscalafmt.changedOnly=false -pl sql/api -pl sql/connect/common -pl sql/connect/server -pl sql/connect/shims -pl sql/connect/client/jvmWas this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor Codex 5.3