Unify temporal field parsing with DatePart - #24906
Open
sdf-jkl wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24906 +/- ##
==========================================
+ Coverage 81.61% 81.63% +0.01%
==========================================
Files 1123 1123
Lines 409562 409685 +123
Branches 409562 409685 +123
==========================================
+ Hits 334284 334447 +163
+ Misses 55647 55587 -60
- Partials 19631 19651 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Temporal functions currently parse field names independently, which produces inconsistent user-visible behavior. For example,
date_partaccepts aliases such asmon,mons,month, andmonths, whiledate_truncaccepts onlymonth.Using Arrow's
DatePartparser as the common representation makes these aliases consistent across temporal functions and SQL unparsing.What changes are included in this PR?
DatePart::from_strdirectly indate_partinstead of parsing throughIntervalUnitand maintaining additional manual mappings.DateTruncGranularityenum and its string parser withDatePart.date_truncto theDatePartvariants that represent valid truncation granularities.dayofweekdirectly todow1instead of adding one to the result expression.DatePartwhen canonicalizing temporal fields in the SQL unparser.What is the testing strategy for this PR?
SQL logic tests cover the newly shared aliases, including:
date_part:QUARTERS,ISOWEEK,DAYOFYEAR, andDAYOFWEEKdate_trunc:mon,months,qtr, andyrsQUARTERS,DAYOFYEAR,MONTHS, andMINSMONSandYRSThe following checks passed:
cargo fmt --allcargo clippy --all-targets --all-features -- -D warningsavro,json,backtrace,extended_tests,recursive_protection,parquet_encryptioncargo test -p datafusion-spark --libAre there any user-facing changes?
Yes. Temporal functions now consistently accept the field-name aliases recognized by Arrow's
DatePartparser. This broadens accepted input spellings without changing existing accepted inputs or truncation behavior.The Spark wrappers inherit these aliases as well, making them slightly more permissive than Spark's exact spelling tables.