sdf-jkl opened a new pull request, #24906:
URL: https://github.com/apache/datafusion/pull/24906

   ## Which issue does this PR close?
   
   - Closes #22033.
   
   ## Rationale for this change
   
   Temporal functions currently parse field names independently, which produces 
inconsistent user-visible behavior. For example, `date_part` accepts aliases 
such as `mon`, `mons`, `month`, and `months`, while `date_trunc` accepts only 
`month`.
   
   Using Arrow's `DatePart` parser as the common representation makes these 
aliases consistent across temporal functions and SQL unparsing.
   
   ## What changes are included in this PR?
   
   - Use `DatePart::from_str` directly in `date_part` instead of parsing 
through `IntervalUnit` and maintaining additional manual mappings.
   - Replace the private `DateTruncGranularity` enum and its string parser with 
`DatePart`.
   - Restrict `date_trunc` to the `DatePart` variants that represent valid 
truncation granularities.
   - Update the Spark wrappers to delegate field parsing to the shared 
implementation while retaining their function-specific semantic restrictions.
   - Map Spark's Sunday-based `dayofweek` directly to `dow1` instead of adding 
one to the result expression.
   - Use `DatePart` when 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`, and `DAYOFWEEK`
   - `date_trunc`: `mon`, `months`, `qtr`, and `yrs`
   - Spark wrappers: `QUARTERS`, `DAYOFYEAR`, `MONTHS`, and `MINS`
   - Unparser canonicalization of aliases such as `MONS` and `YRS`
   
   The following checks passed:
   
   - `cargo fmt --all`
   - `cargo clippy --all-targets --all-features -- -D warnings`
   - Extended workspace tests with 
`avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption`
   - Spark datetime SQL logic tests
   - `cargo test -p datafusion-spark --lib`
   
   ## Are there any user-facing changes?
   
   Yes. Temporal functions now consistently accept the field-name aliases 
recognized by Arrow's `DatePart` parser. 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.
   


-- 
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