Skip to content

[AURON #2128] Implement native function of dayofweek#2129

Merged
slfan1989 merged 1 commit intoapache:masterfrom
weimingdiit:feat/dayofweek-native-function
Mar 31, 2026
Merged

[AURON #2128] Implement native function of dayofweek#2129
slfan1989 merged 1 commit intoapache:masterfrom
weimingdiit:feat/dayofweek-native-function

Conversation

@weimingdiit
Copy link
Copy Markdown
Contributor

@weimingdiit weimingdiit commented Mar 28, 2026

Which issue does this PR close?

Closes ##2128

Rationale for this change

To achieve full compatibility with Spark’s date functions, we should implement dayofweek() with the following characteristics:

Expected behavior

Function name: dayofweek(expr)
Return value: Sunday = 1, Monday = 2, ..., Saturday = 7
Example:

dayofweek('2009-07-30')5

Supports: DATE, TIMESTAMP, and compatible string/date inputs consistent with existing date extraction functions

Null-safe: should return NULL if input is NULL
Array and scalar inputs: consistent with current date extraction function implementations

What changes are included in this PR?

This PR adds native support for the dayofweek() function with Spark-compatible semantics.
The following changes are included:

  • Added native implementation of spark_dayofweek() in the expression layer.
  • Added DayOfWeek expression support in NativeConverters for proper Spark → native translation.
  • Added unit tests to verify correctness.

Are there any user-facing changes?

No.

How was this patch tested?

CI.

@weimingdiit weimingdiit marked this pull request as ready for review March 28, 2026 16:08
@slfan1989 slfan1989 self-requested a review March 29, 2026 03:19
@slfan1989 slfan1989 self-assigned this Mar 29, 2026
@slfan1989 slfan1989 requested a review from Copilot March 30, 2026 01:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds native support for Spark-compatible dayofweek() by wiring a new Spark expression conversion to a native DataFusion extension function and validating results via unit/integration tests.

Changes:

  • Added DayOfWeekSpark_DayOfWeek translation in Spark NativeConverters.
  • Implemented native spark_dayofweek() in spark_dates.rs and registered it in the ext-function factory.
  • Added a Spark-side test case validating dayofweek() output for a DATE column and a string literal.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala Routes Spark’s DayOfWeek expression to the native ext function Spark_DayOfWeek.
spark-extension-shims-spark/src/test/scala/org/apache/auron/AuronFunctionSuite.scala Adds a Spark integration test for dayofweek() on a DATE column and a string literal.
native-engine/datafusion-ext-functions/src/spark_dates.rs Implements spark_dayofweek() (Date32-based) and adds a Rust unit test.
native-engine/datafusion-ext-functions/src/lib.rs Registers Spark_DayOfWeek in the native extension function factory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: weimingdiit <weimingdiit@gmail.com>
@weimingdiit weimingdiit force-pushed the feat/dayofweek-native-function branch from 1b313f9 to 45ada3d Compare March 30, 2026 11:32
@slfan1989 slfan1989 merged commit 0e832f2 into apache:master Mar 31, 2026
123 checks passed
@slfan1989
Copy link
Copy Markdown
Contributor

@weimingdiit Thanks for the contribution! Merged into master.

@weimingdiit weimingdiit deleted the feat/dayofweek-native-function branch April 1, 2026 00:51
@weimingdiit
Copy link
Copy Markdown
Contributor Author

@weimingdiit Thanks for the contribution! Merged into master.
@slfan1989 Thanks for your review and merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants