sjhddh opened a new pull request, #22740:
URL: https://github.com/apache/datafusion/pull/22740

   ## Which issue does this PR close?
   
   - Closes #22599.
   
   ## Rationale for this change
   
   Implements the Spark `weekday` function as part of the datafusion-spark 
function library (#15914). Spark's `weekday` returns the day-of-week as a 
0-indexed integer with Monday = 0 .. Sunday = 6, which differs from the 
existing `dayofweek` (1-indexed, Sunday = 1). This fills a gap for 
Spark-compatibility consumers.
   
   ## What changes are included in this PR?
   
   - New `SparkWeekDay` scalar UDF in 
`datafusion/spark/src/function/datetime/weekday.rs`, modeled on the sibling 
`monthname` function.
   - Accepts Date and (implicitly coerced) Timestamp input; returns `Int32`.
   - Uses Arrow's `DatePart::DayOfWeekMonday0` kernel, which is exactly 
0=Monday .. 6=Sunday — a direct match for Spark semantics.
   - Null input propagates to null output for both scalar and array paths.
   - Registered in the datetime function `mod.rs` (UDF macro, doc export, 
`functions()` list).
   
   ## Are these changes tested?
   
   Yes:
   - Rust unit tests: return-field nullability, scalar evaluation (incl. null), 
and array evaluation.
   - sqllogictest coverage in 
`datafusion/sqllogictest/test_files/spark/datetime/weekday.slt`: scalar dates 
for all 7 weekdays, array input, TIMESTAMP / TIMESTAMP_NTZ / LTZ coercion, null 
handling, and argument-type / zero-argument error cases. The original PySpark 
3.5.5 reference (`weekday('2009-07-30') = 3`) is preserved and validated.
   
   ## Are there any user-facing changes?
   
   Adds the new Spark-compatible scalar function `weekday`. No breaking changes.
   
   ---
   
   Note: I noticed there is an existing draft PR #22601 for the same function 
(last updated 2026-05-28). It appears to be a stale draft, so I've opened this 
as a complete, tested implementation — happy to defer or collaborate if the 
draft author is still active.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to