yihua opened a new pull request, #20835:
URL: https://github.com/apache/hudi/pull/20835

   ### Describe the issue this Pull Request addresses
   
   closes #20817
   
   `SqlKeyGenerator` prints a TIMESTAMP partition value as `yyyy-MM-dd 
HH:mm:ss`, so values that differ only below the second share one partition 
path, and a reader that takes the partition value from the path (partition 
pruning, or extracting partition values from the path) sees the truncated value.
   
   Stacked on #20822: the first commit is that PR's fix, which the tables that 
keep truncating need. Please review the second commit; a rebase drops the first 
once #20822 merges.
   
   ### Summary and Changelog
   
   A new partitioned table records 
`hoodie.datasource.write.partitionpath.timestamp.fractional.seconds` (true at 
table version 10, false when created at an older version). With it, 
`SqlKeyGenerator` writes the value as Spark renders a timestamp cast to a 
string, e.g. `ts=2024-02-29 10%3A30%3A00.123456`, which is also the directory 
Spark itself writes. A whole-second value keeps its path, and a table without 
the property, which is every existing table, keeps truncating. The microseconds 
are read from the record, since the delegate key generator prints an 
InternalRow (or an Avro value with consistent logical timestamps) through a 
millisecond `Timestamp`.
   
   The layout is fixed per table: the Spark writer always hands the key 
generator the value the table records, a write that sets a different value is 
refused, and so is a CREATE TABLE over an existing table with a different 
value. The property is kept on downgrade, like the complex key generator 
encoding.
   
   Tests: new cases in `TestSqlKeyGenerator`, `TestHoodieTableConfig` and 
`TestHoodieWriterUtils`, and `TestTimestampPartitionFractionalSeconds`, which 
runs insert, upsert, bulk insert and update through Spark SQL on a new table 
(paths, pruning on the exact value, values extracted from the path) and on an 
existing table that must keep truncating, including under INSERT OVERWRITE. 
Four existing tests that assert the full `hoodie.properties` now expect the 
property.
   
   ### Impact
   
   New advanced table config, recorded at creation. New partitioned tables at 
table version 10 get sub-second partition paths for TIMESTAMP partition values 
written through Spark SQL; existing tables are unchanged. Limitations:
   - A version 10 table downgraded to 9 keeps the property, but a 1.1 or 1.2 
writer truncates, so it can write an update of a sub-second row under a 
different path (never supported: those writers predate the property).
   - Paths print in the JVM default time zone while Spark parses partition 
values in the session time zone, so pruning on the exact value relies on the 
two matching (never supported, unchanged here).
   
   ### Risk Level
   
   medium: it changes the partition path layout of new tables. The layout is 
pinned in the table config at creation, so existing tables keep their paths, 
and the SQL test covers both layouts end to end.
   
   ### Documentation Update
   
   The new config carries its documentation. No website change beyond the 
generated config reference.
   
   ### Contributor's checklist
   
   - [ ] Read through [contributor's 
guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [ ] Enough context is provided in the sections above
   - [ ] Adequate tests were added if applicable
   


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

Reply via email to