feat(spark): add Spark-compatible dayofweek #327
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 465 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.368
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #327"
general
weight: 0.35
kosiew
Closes #151.
Summary
Adds a Spark-compatible
dayofweek(date), which returns an INT from 1 (Sunday) to 7 (Saturday). It is ported from Comet'sdatetime_funcs/day_of_week.rs.crates/spark/src/function/datetime/dayofweek.rs. The result comes straight from theDate32epoch day:((days + 4) mod 7) + 1, computed ini64. This matches Spark'sLocalDate.ofEpochDay(days).getDayOfWeek.plus(1).getValue, which is defined for everyInt.invoke_with_argshandles scalar and array inputs, NULL and untyped NULL, and dictionary-encodedDate32. For a dictionary, it maps the values, rewraps the keys, and unpacks the result to plainInt32.date_signature()thatdaynameandmonthnameuse. Strings and timestamps are implicitly cast to DATE, as in Spark.#[user_doc]and registered indatetime/mod.rs.weekdaynow uses the same epoch-day helper instead of arrow'sdate_part(DayOfWeekMonday0). arrow builds a chrono date for each row, so dates outside chrono's range (such asdate_from_unix_date(±2^31)) came back NULL. Spark returns 1 and 4 for those dates, and so doesweekdaynow. Theweekdaysignature is unchanged. Both functions cast aDate64input (also inside a dictionary) to epoch days, so they accept every type their signatures admit.Differences from Comet's version
Signature::any(1)and expects the planner to hand it aDate32. Here the function has a coercible date signature, so strings and timestamps work from SQL. Comet's namespark_dayofweekbecomesdayofweek.return_field_from_argspasses the input's nullability through to the result, the same asweekday.unaryandunary_opt, and the dictionary handling are the same as in Comet. I found no behavioral difference between Comet and Spark 4.2.0 forDate32input.Known differences from Spark, which also apply to the existing
daynameandweekdayand are left as commented-out cases in the.slt:'2009'and'2009-07'as the first day of that year or month, in both ANSI modes. DataFusion's cast rejects them (#88).Testing
date_from_unix_date(-2147483648)= 3 and(2147483647)= 6, NULL and untyped NULL (int), strings, TIMESTAMP_NTZ, TIMESTAMP in UTC and in America/New_York, malformed strings with ANSI on and off, and an INT argument (DATATYPE_MISMATCH).crates/sqllogictest/scripts/pyspark_slt_runner.pyondayofweek.sltandweekday.slt: everydayofweekrecord passes on Spark 4.2.0. Skipped records are thearrow_typeofchecks and the dictionary case, markedskipif spark. The oneweekdaymismatch,weekday('not-a-date'), was already there (strings are not cast forweekday, #41).i32range, agreement withweekdayover a 400-year cycle, dictionary input, non-date input rejected, and scalar input. A nullability test was added.cargo fmt --all,cargo clippy --all-targets --all-features -- -D warnings,cargo test -p datafusion-sparkandcargo test -p datafusion-spark-sqllogictest(249 of 249 files).