feat: add support for next_day expression#3148
Conversation
Adds native Comet support for Spark's next_day function which returns the first date after a given date that falls on the specified day of the week. Supports full day names (Sunday, Monday, etc.) and abbreviations (Sun, Mon, etc.). Closes apache#3092 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3148 +/- ##
============================================
+ Coverage 56.12% 59.87% +3.74%
- Complexity 976 1414 +438
============================================
Files 119 168 +49
Lines 11743 15587 +3844
Branches 2251 2589 +338
============================================
+ Hits 6591 9332 +2741
- Misses 4012 4946 +934
- Partials 1140 1309 +169 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
comphead
left a comment
There was a problem hiding this comment.
Can we use next_day from DataFusion? https://github.com/apache/datafusion/blob/main/datafusion/spark/src/function/datetime/next_day.rs
# Conflicts: # docs/source/user-guide/latest/configs.md # native/spark-expr/src/comet_scalar_funcs.rs # native/spark-expr/src/lib.rs # spark/src/main/scala/org/apache/comet/serde/datetime.scala # spark/src/test/scala/org/apache/comet/CometTemporalExpressionSuite.scala
|
Moving this to draft until #3328 is merged |
# Conflicts: # native/spark-expr/src/comet_scalar_funcs.rs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace our custom SparkNextDay with the upstream datafusion-spark version, which also handles LargeUtf8 and Utf8View string types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Thanks, I have updated to use the implementation from DF now. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds native Comet support for Spark's next_day function, which returns the first date after a given start date that falls on a specified day of the week. The implementation leverages the SparkNextDay function from the datafusion-spark crate (version 51.0.0).
Changes:
- Added Scala serialization support for the
NextDayexpression using the standardCometScalarFunctionpattern - Registered the function in both Scala and Rust layers to enable end-to-end execution
- Added comprehensive SQL tests covering full day names, abbreviations, literals, and null handling
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| spark/src/main/scala/org/apache/comet/serde/datetime.scala | Added CometNextDay object using CometScalarFunction pattern and imported NextDay class |
| spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala | Registered NextDay expression in the temporalExpressions map |
| native/core/src/execution/jni_api.rs | Imported SparkNextDay and registered it as a UDF in the DataFusion session context |
| spark/src/test/resources/sql-tests/expressions/datetime/next_day.sql | Added SQL tests for all 7 days (full and abbreviated names), literals, and null handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mbutrovich
left a comment
There was a problem hiding this comment.
LGTM, thanks @andygrove!
Summary
next_dayfunctionTest Plan
CometTemporalExpressionSuiteCloses #3092