feat: support TimestampType join keys in SortMergeJoin#3986
Open
andygrove wants to merge 5 commits intoapache:mainfrom
Open
feat: support TimestampType join keys in SortMergeJoin#3986andygrove wants to merge 5 commits intoapache:mainfrom
andygrove wants to merge 5 commits intoapache:mainfrom
Conversation
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.
Which issue does this PR close?
Closes #3985.
Rationale for this change
CometSortMergeJoinExecrejectedTimestampTypejoin keys viasupportedSortMergeJoinEqualType, forcing a fall-back to Spark whenever a SortMergeJoin keyed on a timestamp column. The restriction was historical —TimestampNTZTypewas already allowed butTimestampTypehad never been enabled.Naively flipping the guard surfaces an upstream limitation: DataFusion's SMJ comparator (
joins/sort_merge_join/stream.rsis_join_arrays_equal,joins/utils.rscompare_join_arrays) only pattern-matchesTimestamp(_, None). Spark'sTimestampTypeserializes toTimestamp(µs, "UTC"), hitting the fallthroughnot_impl_err!. Because Spark storesTimestampTypeas UTC-normalized microseconds, castingTimestamp(µs, Some(_))→Timestamp(µs, None)is a metadata-only operation that preserves both equality and row order, so it is safe to apply at the join-key level.What changes are included in this PR?
TimestampTypetosupportedSortMergeJoinEqualTypeinoperators.scala.OpStruct::SortMergeJoinarm ofplanner.rs, introduce astrip_timestamp_tzhelper that wraps anyTimestamp(_, Some(_))join-key expression in aCastExprtoTimestamp(_, None)before handing the keys toSortMergeJoinExec::try_new.sort_optionsand the child plans are untouched.CometJoinSuitewith four positive tests exercising the new path:Asia/Kathmandusession timezone.LEFT OUTER,RIGHT OUTER,FULL OUTERvariants.(string, timestamp)join key.How are these changes tested?
All four new tests use
checkSparkAnswerAndOperatorwithclassOf[CometSortMergeJoinExec]to assert both correctness against Spark and native execution. The fullCometJoinSuitepasses (13/13).cargo clippy --all-targets --workspace -- -D warningsis clean andmake formatreports no changes.