marko-k0 opened a new pull request, #27760:
URL: https://github.com/apache/datafusion/pull/27760

   > [!IMPORTANT]
   >
   > **Fork CI setup:** For pull requests from a fork to `main`, enable 
workflows in your fork's **Actions** tab before you push.
   > See the [fork CI setup 
guide](https://datafusion.apache.org/contributor-guide/#pull-requests-from-forks).
   
   ## Which issue does this PR close?
   
   - Closes #24907.
   
   ## Rationale for this change
   
   `COPY ... PARTITIONED BY (date_col)` panicked inside the write task when a 
`Date32`/`Date64` value could not be rendered as a `yyyy-mm-dd` path segment, 
instead of failing the query. The same code also put `Date64` values before the 
epoch on the wrong day: milliseconds were divided by 86,400,000 with 
truncation, so `-1` was written as `1970-01-01` instead of `1969-12-31`.
   
   ## What changes are included in this PR?
   
   - Use Arrow's `date32_to_datetime` / `date64_to_datetime` instead of 
hand-rolled epoch arithmetic. These are the conversions Arrow uses to display 
and cast dates, their internal math is `i64` so `Date32` cannot overflow, and 
they already floor negative `Date64` milliseconds.
   - Return an execution error naming the column and value instead of 
unwrapping.
   - Remove the now-unused `EPOCH_DAYS_FROM_CE` constant and `NaiveDate` import 
(`chrono` is still used elsewhere in the crate).
   
   ## What is the testing strategy for this PR?
   
   Unit tests in `demux.rs`:
   
   - `partition_keys_error_on_out_of_range_date32` / 
`partition_keys_error_on_out_of_range_date64`
   - `partition_keys_date64_uses_calendar_day_of_millis` (day boundaries either 
side of the epoch)
   - `partition_keys_date32_negative_day_uses_previous_day`
   - `partition_keys_date32_epoch_and_next_day`
   - `partition_keys_far_future_dates` (9999-12-31 is still accepted)
   - `partition_keys_reject_null_values` now also covers `Date32`/`Date64`
   
   `copy.slt`:
   
   - both out-of-range values return an execution error from `COPY`
   - a `Date64` value of `-1` is written to `.../column2=1969-12-31` and reads 
back as that date
   
   ## Are there any user-facing changes?
   
   Yes: out-of-range date partition values now fail with an execution error 
instead of panicking, and pre-epoch `Date64` values go to the correct 
partition. No API changes.
   
   


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