Skip to content

fix: return an error instead of panicking on out-of-range date partition values - #27760

Open
marko-k0 wants to merge 4 commits into
apache:mainfrom
marko-k0:fix/date-partition-out-of-range
Open

marko-k0 wants to merge 4 commits into
apache:mainfrom
marko-k0:fix/date-partition-out-of-range

Conversation

@marko-k0

Copy link
Copy Markdown

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.

Which issue does this PR close?

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.

`COPY ... PARTITIONED BY (date_col)` panicked when a Date32/Date64 value
could not be rendered as a date, and Date64 values before the epoch were
placed on the wrong day because milliseconds were divided with truncation.

Use Arrow's date32_to_datetime/date64_to_datetime and return an execution
error naming the offending value.
Add Date32 pre-epoch and Date64 day-boundary unit cases, and sqllogictest
coverage that out-of-range values error from COPY and that a negative
Date64 value lands in the 1969-12-31 partition.
@marko-k0
marko-k0 marked this pull request as ready for review November 25, 2026 19:12
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) datasource Changes to the datasource crate labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datasource Changes to the datasource crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COPY ... PARTITIONED BY a Date32 / Date64 column panics on out-of-range values

1 participant