Skip to content

[1047] Parse DATE and TIMESTAMP partition values that Hudi writes as dates and times - #1052

Draft
yihua wants to merge 1 commit into
apache:mainfrom
yihua:xt-1047-date-timestamp-partitions
Draft

yihua wants to merge 1 commit into
apache:mainfrom
yihua:xt-1047-date-timestamp-partitions

Conversation

@yihua

@yihua yihua commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Important Read

Closes #1047, part of #722.

What is the purpose of the pull request

The path based partition values extractor parses DATE partition paths written as ISO dates and TIMESTAMP paths written as escaped dates and times, instead of failing with a NumberFormatException. Since Hudi's SQL key generator truncates a TIMESTAMP path to whole seconds, a data file whose column stats show a value other than its path value is refused rather than published with a wrong partition value.

Brief change log

  • PathBasedPartitionValuesExtractor parses both forms into the field's precision; numbers are read as before.
  • HudiDataFileExtractor checks the stats of identity TIMESTAMP partition columns.
  • A file without stats for the column is kept, since the column may be outside the indexed columns.

Known limitations:

  • behavior change for all targets: a Hudi table partitioned by a TIMESTAMP column with sub-second values, or several values per second, now fails its sync.
  • An escaped timestamp path without an offset is read in the JVM's default time zone, which has to match the writer's.

Verify this pull request

This change added tests and can be verified as follows:

  • TestHudiPartitionValuesExtractor parses twelve paths: dates before and after the epoch as dates and as numbers, and timestamps that are escaped, carry a fraction or an offset, are numbers, or have millis, micros or no declared precision, with and without a time zone; invalid values fail with a PartitionValuesExtractorException. TestHudiDataFileExtractor keeps a file whose only value is the path value, a null partition and a file without stats for the column, and refuses a value with fractional seconds and two values of one second.
  • Run locally on JDK 11: 611 xtable-core unit tests pass (3 skipped), the xtable-core Iceberg ITs pass, and the Iceberg table format's 26 unit tests and 46 ITs pass (1 skipped).

…dates and times

Hudi writes the partition path of a DATE column as an ISO date such as
2024-02-29. Its SQL key generator writes a TIMESTAMP column as a date and
time in the default time zone of the writer's JVM with the colons escaped,
such as 2024-02-29 10%3A30%3A00. The path based extractor read both as
numbers, so the first commit of a table partitioned by such a column
failed with a NumberFormatException.

A DATE value that is not a number is now parsed as an ISO date into days
since epoch. A TIMESTAMP value that is not a number is unescaped and
parsed as a date and time with an optional offset, into the precision of
the field, or micros when the field declares none. A value without an
offset is read in the JVM's default time zone for TIMESTAMP and in UTC for
TIMESTAMP_NTZ. Numbers are read as before.

The tests parse twelve paths: dates before and after the epoch as dates
and as numbers, and timestamps that are escaped, carry a fraction or an
offset, are numbers, or have millis, micros or no declared precision, with
and without a time zone. Another test expects an invalid date and a
timestamp without a time to fail with a PartitionValuesExtractorException.

Hudi's SQL key generator truncates the partition path of a TIMESTAMP
column to whole seconds, so rows whose values differ below the second
share a path and a file group. The value parsed from the path is then not
the value of every row of the file. A target that fills an identity
partition column from the partition value, as Iceberg does, returned the
truncated value for every row and pruned filters on the column by it.

No single partition value is right for a file that holds several, and a
value taken from the column stats would differ from the one the file is
later removed under, which is parsed from the path again. The data file
extractor therefore keeps the path value and checks every file it adds
stats to: for an identity partition on a TIMESTAMP or TIMESTAMP_NTZ column
with a non-null value, the min and the max of the column's stats have to
equal the partition value. Otherwise it throws a
PartitionValuesExtractorException that names the file, the range of the
column and the path value, and suggests partitioning by a column of whole
seconds or a coarser value. A file without stats for the column is kept,
since a Hudi table indexes only some columns in the metadata table, 32 by
default, and a table written with drop.partition.columns stores no footer
stats for the column.

The tests keep a file whose only value is the path value, for TIMESTAMP,
TIMESTAMP_NTZ, a null partition and a file without stats, and expect the
refusal for a single value with fractional seconds and for two values of
one second.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hudi source: DATE and TIMESTAMP partition values written as dates fail to parse

1 participant