Repository navigation
Downcast nanosecond timestamps before partitioning - #4479
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
Partition values were computed on timestamp[ns] input before the writer downcast it, so identity partitions duplicated or lost rows, hour partitions failed, and negative year/month/day partitions disagreed with the stored values. Cast each nanosecond partition source to timestamp[us] before its transform when downcast-ns-timestamp-to-us-on-write is set. Co-authored-by: Isaac <no-reply@databricks.com>
This branch has not been deployed
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.
Rationale for this change
Bug: with
downcast-ns-timestamp-to-us-on-writeon (non-default; set here withPYICEBERG_DOWNCAST_NS_TIMESTAMP_TO_US_ON_WRITE=true), an hour partition on atimestamp[ns]column fails. The partition values are computed on the nanosecond input, and the writer only downcasts afterwards. The hour transform has no nanosecond kernel:For an identity partition on the same column, main duplicates the aligned row when it shares a microsecond with an unaligned one (1000 and 1500 ns give IDs
[0, 0]), and raisesZeroDivisionErrorfor an unaligned value on its own.Fix: when the option is on, cast each nanosecond partition source to microseconds with the writer's safe=False cast before applying its transform. The writer still downcasts the data, so partition values match stored values. Refs #1619, the same conversion-order problem for the day transform, closed as stale.
Java's v1/v2 partition transforms receive microseconds: Spark supplies them directly, and the generic Kafka writer uses InternalRecordWrapper to convert timestamps first. This PR applies PyIceberg's existing downcast before partitioning.
Are these changes tested?
Yes. Four tests in
tests/io/test_pyarrow.py, next to the existing downcast tests:test_append_hour_partition_with_ns_timestamp_downcast(top-level and struct-child hour partitions),test_append_identity_partition_with_ns_timestamp_downcast(1000 and 1500 ns share one partition, IDs [0, 1]),test_append_year_month_day_partition_negative_ns_timestamp_downcast(-1 ns and a null row, for year, month, day and a UTC day; partitions 0 and null), andtest_determine_partitions_native_ns_timestamp_is_not_downcast(v3 nanosecond sources keep -1 ns). The first three fail on main with theFeatureUnsupportederror above, IDs [0, 0], and partition -1, and pass with this change. The fourth fails if the native-type check is removed.Are there any user-facing changes?
With the option on, hour and identity partitions accept timestamp[ns]. Year, month and day partitions now follow the stored microseconds at negative boundaries (-1 ns becomes 0 us, so partition -1 becomes 0). Existing files retain their old partition values.
Please add the
changeloglabel.This pull request and its description were written by Isaac.