You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "0lai0 (via GitHub)" <gi...@apache.org> on 2026/03/20 16:37:35 UTC
[PR] feat: Support Spark expression days [datafusion-comet]
0lai0 opened a new pull request, #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #3124
## Rationale for this change
Comet previously did not support the Spark Days expression. It is used internally by Spark for daily partitioning in Iceberg/Delta tables. Since Comet did not recognize this expression, queries involving Days would fall back to JVM execution.
## What changes are included in this PR?
This change adds a Serde handler for Days that reuses the existing Cast protobuf and Rust implementation, requiring no new native code paths.
- For `DateType` input: dates are internally stored as days since epoch, so a simple Cast(Date → Int) suffices (same approach as `CometUnixDate`).
- For `TimestampType` input: uses a timezone-aware Cast(Timestamp → Date) via `CometCast.castToProto `(which respects the session timezone for correct date boundary determination), followed by Cast(Date → Int).
The `Date → Int `cast is constructed directly as protobuf (bypassing `CometCast.castToProto`) because Spark's `isAlwaysCastToNull` intercepts `Date → Int` in LEGACY mode and would incorrectly return null.
`datetime.scala` : Added CometDays handler
`QueryPlanSerde.scala` : Registered the handler in temporalExpressions map
`CometTemporalExpressionSuite.scala` : Added days test
## How are these changes tested?
`./mvnw test -pl spark -Dsuites="org.apache.comet.CometTemporalExpressionSuite" -Dtest="none" -DfailIfNoTests=false
`
`./mvnw scalastyle:check -pl spark
`
--
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 Spark expression days [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on PR #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746#issuecomment-4105535276
Thanks @andygrove for the review! All three comments have been addressed and also fixed the Spark 4.0 compilation failures.
The root cause was two removed APIs in Spark 4:
- Column(Expression) constructor → replaced with getColumnFromExpression() shim
- Column.expr property → replaced with UnresolvedAttribute to construct column references directly in test code
Both Spark 3.5 (tests pass) and Spark 4.0 (compilation verified) are working in local.
`./mvnw test -pl spark \
-Dsuites="org.apache.comet.CometTemporalExpressionSuite" \
-Dtest="none" -DfailIfNoTests=false
`
`./mvnw test-compile -Pspark-4.0
`
--
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 Spark expression days [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746#issuecomment-4101145175
Thanks @0lai0. I took a first pass through and this is looking good so far. Could you take a look at the Spark 4 compilation issues?
--
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 Spark expression days [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746#discussion_r2968129038
##########
spark/src/test/scala/org/apache/comet/CometTemporalExpressionSuite.scala:
##########
@@ -395,4 +395,93 @@ class CometTemporalExpressionSuite extends CometTestBase with AdaptiveSparkPlanH
// Test null handling
checkSparkAnswerAndOperator("SELECT unix_date(NULL)")
}
+
+ test("days") {
Review Comment:
nit: there are many different tests within this one test function. I wonder if it would make sense to split them out into separate tests.
--
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 Spark expression days [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746#discussion_r2968123382
##########
docs/source/user-guide/latest/expressions.md:
##########
@@ -98,6 +98,7 @@ Expressions that are not Spark-compatible will fall back to Spark by default and
| DateDiff | `datediff` | Yes | |
| DateFormat | `date_format` | Yes | Partial support. Only specific format patterns are supported. |
| DateSub | `date_sub` | Yes | |
+| Days | `days` | Yes | V2 partition transform. Supports DateType and TimestampType inputs. |
Review Comment:
`Days` should appear after `DatePart`
--
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 Spark expression days [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746#discussion_r2971439894
##########
spark/src/test/scala/org/apache/comet/CometTemporalExpressionSuite.scala:
##########
@@ -395,4 +395,93 @@ class CometTemporalExpressionSuite extends CometTestBase with AdaptiveSparkPlanH
// Test null handling
checkSparkAnswerAndOperator("SELECT unix_date(NULL)")
}
+
+ test("days") {
Review Comment:
Sure, I'll split them. Thanks
--
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 Spark expression days [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746#discussion_r2968125840
##########
spark/src/test/scala/org/apache/comet/CometTemporalExpressionSuite.scala:
##########
@@ -395,4 +395,93 @@ class CometTemporalExpressionSuite extends CometTestBase with AdaptiveSparkPlanH
// Test null handling
checkSparkAnswerAndOperator("SELECT unix_date(NULL)")
}
+
+ test("days") {
+ import org.apache.spark.sql.Column
+ import org.apache.spark.sql.DataFrame
+ import org.apache.spark.sql.catalyst.expressions.{Days, Literal}
+ import org.apache.spark.sql.functions.col
Review Comment:
nit: it is unusual to have imports within the test
--
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 Spark expression days [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #3746:
URL: https://github.com/apache/datafusion-comet/pull/3746
--
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