Skip to content

Add DatePart enum 1-indexed variants#9965

Open
sdf-jkl wants to merge 3 commits into
apache:mainfrom
sdf-jkl:add-datepart-dow1
Open

Add DatePart enum 1-indexed variants#9965
sdf-jkl wants to merge 3 commits into
apache:mainfrom
sdf-jkl:add-datepart-dow1

Conversation

@sdf-jkl
Copy link
Copy Markdown
Contributor

@sdf-jkl sdf-jkl commented May 12, 2026

Which issue does this PR close?

Rationale for this change

Remove extra computations done on the datafusion side for temporal functions.

What changes are included in this PR?

  • Added two new DatePart variant
  • Closed some tests lists drift

Are these changes tested?

  • Unit tests

Are there any user-facing changes?

No

sdf-jkl and others added 2 commits May 12, 2026 14:36
`DayOfWeekMonday1` (`1..=7`, Mon=1) matches PostgreSQL's `isodow`;
`DayOfWeekSunday1` (`1..=7`, Sun=1) matches Spark's `dayofweek`.
`FromStr` accepts `isodow` and `dayofweek1` for these.

`FromStr` previously rejected `isodow` because mapping it to
`DayOfWeekMonday0` (`0..=6`) would silently shift PostgreSQL's
`1..=7` semantics. The new variants map faithfully, so downstream
wrappers (e.g. datafusion-spark's `date_part`) can drop their
post-hoc `+1` over the result array and reduce to pure alias
remapping.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The three `*_invalid_parts` arrays were hand-maintained spot-check
lists that had drifted from the impls: every `ExtractDatePartExt` for
Time, Interval, and Duration arrays rejects `YearISO` and `WeekISO`,
but the tests never asserted it. Add both variants to all three
arrays so the negative-test coverage matches the actual rejection
contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the arrow Changes to the arrow crate label May 12, 2026
The 0-indexed pair was already `Sun0, Mon0` (Sunday first), but the
1-indexed pair I added landed as `Mon1, Sun1`. Flip the new pair to
match — every match block, alias table, and test array now reads
`Sun0, Mon0, Sun1, Mon1`, so the four variants line up Sunday-first
across both halves.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
"isoweek" => Self::WeekISO,
"d" | "day" | "days" => Self::Day,
"dow" | "dayofweek" => Self::DayOfWeekSunday0,
"dayofweek1" => Self::DayOfWeekSunday1,
Copy link
Copy Markdown
Contributor

@Jefffrey Jefffrey May 20, 2026

Choose a reason for hiding this comment

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

dayofweek1 seems non-standard here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll take a look at similar enums in other projects. The reason to add it here is for upstream DataFusion Spark temporal function support.

sparkdow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

MySQL/BigQuery/SQL Server/Oracle have dow Sunday = 1 as well

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I'll take a look at similar enums in other projects. The reason to add it here is for upstream DataFusion Spark temporal function support.

sparkdow?

How would this look like downstream? As in, would DataFusion need to provide sparkdow or dayofweek1 as a string to be parsed here? Is there no way to provide the enum variant directly, for example?

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

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DatePart 1-indexed variants

2 participants