You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/04/17 23:57:12 UTC
[PR] feat: support TimestampType join keys in SortMergeJoin [datafusion-comet]
andygrove opened a new pull request, #3986:
URL: https://github.com/apache/datafusion-comet/pull/3986
## Which issue does this PR close?
Closes #3985.
## Rationale for this change
`CometSortMergeJoinExec` rejected `TimestampType` join keys via `supportedSortMergeJoinEqualType`, forcing a fall-back to Spark whenever a SortMergeJoin keyed on a timestamp column. The restriction was historical — `TimestampNTZType` was already allowed but `TimestampType` had never been enabled.
Naively flipping the guard surfaces an upstream limitation: DataFusion's SMJ comparator (`joins/sort_merge_join/stream.rs` `is_join_arrays_equal`, `joins/utils.rs` `compare_join_arrays`) only pattern-matches `Timestamp(_, None)`. Spark's `TimestampType` serializes to `Timestamp(µs, "UTC")`, hitting the fallthrough `not_impl_err!`. Because Spark stores `TimestampType` as UTC-normalized microseconds, casting `Timestamp(µ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?
- **JVM guard**: add `TimestampType` to `supportedSortMergeJoinEqualType` in `operators.scala`.
- **Native planner workaround**: in the `OpStruct::SortMergeJoin` arm of `planner.rs`, introduce a `strip_timestamp_tz` helper that wraps any `Timestamp(_, Some(_))` join-key expression in a `CastExpr` to `Timestamp(_, None)` before handing the keys to `SortMergeJoinExec::try_new`. `sort_options` and the child plans are untouched.
- **Tests**: replace the obsolete "falls back to Spark" test in `CometJoinSuite` with four positive tests exercising the new path:
- Inner join with `Asia/Kathmandu` session timezone.
- `LEFT OUTER`, `RIGHT OUTER`, `FULL OUTER` variants.
- Composite `(string, timestamp)` join key.
- Nullable timestamp keys (both inner and full-outer variants).
## How are these changes tested?
All four new tests use `checkSparkAnswerAndOperator` with `classOf[CometSortMergeJoinExec]` to assert both correctness against Spark and native execution. The full `CometJoinSuite` passes (13/13). `cargo clippy --all-targets --workspace -- -D warnings` is clean and `make format` reports no changes.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support TimestampType join keys in SortMergeJoin [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #3986:
URL: https://github.com/apache/datafusion-comet/pull/3986
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support TimestampType join keys in SortMergeJoin [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #3986:
URL: https://github.com/apache/datafusion-comet/pull/3986#discussion_r3197101448
##########
spark/src/test/scala/org/apache/comet/exec/CometJoinSuite.scala:
##########
@@ -54,21 +54,119 @@ class CometJoinSuite extends CometTestBase {
.toSeq)
}
- test("SortMergeJoin with unsupported key type should fall back to Spark") {
+ test("SortMergeJoin with TimestampType key runs natively") {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> "Asia/Kathmandu",
SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
- SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1") {
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.PREFER_SORTMERGEJOIN.key -> "true") {
withTable("t1", "t2") {
sql("CREATE TABLE t1(name STRING, time TIMESTAMP) USING PARQUET")
- sql("INSERT OVERWRITE t1 VALUES('a', timestamp'2019-01-01 11:11:11')")
+ sql(
Review Comment:
I added a test to cover this case
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support TimestampType join keys in SortMergeJoin [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on code in PR #3986:
URL: https://github.com/apache/datafusion-comet/pull/3986#discussion_r3192128980
##########
spark/src/test/scala/org/apache/comet/exec/CometJoinSuite.scala:
##########
@@ -54,21 +54,119 @@ class CometJoinSuite extends CometTestBase {
.toSeq)
}
- test("SortMergeJoin with unsupported key type should fall back to Spark") {
+ test("SortMergeJoin with TimestampType key runs natively") {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> "Asia/Kathmandu",
SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
- SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1") {
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.PREFER_SORTMERGEJOIN.key -> "true") {
withTable("t1", "t2") {
sql("CREATE TABLE t1(name STRING, time TIMESTAMP) USING PARQUET")
- sql("INSERT OVERWRITE t1 VALUES('a', timestamp'2019-01-01 11:11:11')")
+ sql(
Review Comment:
What happens if table t1 is written with one session timezone and table t2 is written with another session timezone.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support TimestampType join keys in SortMergeJoin [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3986:
URL: https://github.com/apache/datafusion-comet/pull/3986#issuecomment-4313739872
@hsiang-c fyi
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support TimestampType join keys in SortMergeJoin [datafusion-comet]
Posted by "hsiang-c (via GitHub)" <gi...@apache.org>.
hsiang-c commented on code in PR #3986:
URL: https://github.com/apache/datafusion-comet/pull/3986#discussion_r3148735738
##########
spark/src/test/scala/org/apache/comet/exec/CometJoinSuite.scala:
##########
@@ -54,21 +54,119 @@ class CometJoinSuite extends CometTestBase {
.toSeq)
}
- test("SortMergeJoin with unsupported key type should fall back to Spark") {
+ test("SortMergeJoin with TimestampType key runs natively") {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> "Asia/Kathmandu",
SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
- SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1") {
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.PREFER_SORTMERGEJOIN.key -> "true") {
withTable("t1", "t2") {
sql("CREATE TABLE t1(name STRING, time TIMESTAMP) USING PARQUET")
- sql("INSERT OVERWRITE t1 VALUES('a', timestamp'2019-01-01 11:11:11')")
+ sql(
+ "INSERT OVERWRITE t1 VALUES " +
+ "('a', timestamp'2019-01-01 11:11:11'), " +
+ "('b', timestamp'2020-05-05 05:05:05')")
sql("CREATE TABLE t2(name STRING, time TIMESTAMP) USING PARQUET")
- sql("INSERT OVERWRITE t2 VALUES('a', timestamp'2019-01-01 11:11:11')")
+ sql(
+ "INSERT OVERWRITE t2 VALUES " +
+ "('a', timestamp'2019-01-01 11:11:11'), " +
+ "('c', timestamp'2021-07-07 07:07:07')")
+
+ checkSparkAnswerAndOperator(
+ sql("SELECT * FROM t1 JOIN t2 ON t1.time = t2.time"),
+ Seq(classOf[CometSortMergeJoinExec]))
+ }
+ }
+ }
+
+ test("SortMergeJoin with TimestampType key supports outer joins") {
+ withSQLConf(
+ SQLConf.SESSION_LOCAL_TIMEZONE.key -> "Asia/Kathmandu",
+ SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.PREFER_SORTMERGEJOIN.key -> "true") {
+ withTable("t1", "t2") {
+ sql("CREATE TABLE t1(id INT, time TIMESTAMP) USING PARQUET")
+ sql(
+ "INSERT OVERWRITE t1 VALUES " +
+ "(1, timestamp'2019-01-01 11:11:11'), " +
+ "(2, timestamp'2020-05-05 05:05:05'), " +
+ "(3, timestamp'2021-07-07 07:07:07')")
+
+ sql("CREATE TABLE t2(id INT, time TIMESTAMP) USING PARQUET")
+ sql(
+ "INSERT OVERWRITE t2 VALUES " +
+ "(10, timestamp'2019-01-01 11:11:11'), " +
+ "(20, timestamp'2022-02-02 02:02:02')")
+
+ for (joinType <- Seq("LEFT OUTER", "RIGHT OUTER", "FULL OUTER")) {
Review Comment:
👍
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org