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

   ### Describe the issue this Pull Request addresses
   
   closes #20898
   
   UPDATE and MERGE INTO on a Hudi table ignore 
`spark.sql.storeAssignmentPolicy`: Spark casts each assigned value to the 
column type before Hudi's alignment sees it, so unsafe casts slip through and 
struct values are matched by position.
   
   ### Summary and Changelog
   
   Stacked on #20843, review that first: this builds on its 
`resolveRowLevelAssignments` alignment through Spark's `AssignmentUtils`. For a 
table of a non-native table format (`hoodie.table.format` other than `native`), 
on Spark 3.5 and 4, the alignment now runs on every assignment and takes each 
value as written, dropping the cast and null check Spark added, so Spark checks 
it against the store assignment policy as it does for a table with row-level 
operations; a value Spark could not cast by position (a struct with its fields 
in another order) is deferred so the statement resolves and the alignment 
matches it by name. The LEGACY policy is refused there, as Spark refuses it for 
row-level commands, since its cast would wrap an overflowing value or turn a 
malformed one into NULL. Native tables keep the current behaviour exactly. The 
unresolved-column error of a MERGE INTO assignment now quotes the name as Spark 
does (`` `t`.`invalid_col` ``). New tests in `TestMergeIntoTable2` and `Te
 stUpdateTable` cover ANSI, STRICT and LEGACY on a non-native table and check 
that a native table still casts and still fails on an overflowing value.
   
   ### Impact
   
   Behaviour change for tables of a non-native table format on Spark 3.5 and 4 
only; native tables are unchanged. There is no Hudi option to turn it off. 
Statements that now fail at analysis there but pass on Spark 3.3/3.4 (and on 
native tables):
   - under ANSI (default), a value that cannot be cast safely, for example a 
STRING assigned to an INT, DOUBLE, DATE or TIMESTAMP column, or a numeric value 
assigned to a TIMESTAMP column 
(`INCOMPATIBLE_DATA_FOR_TABLE.CANNOT_SAFELY_CAST`);
   - a MERGE INTO `UPDATE SET *` or `INSERT *` from a source whose STRING id 
feeds an INT record key;
   - a struct value without the column's field names (`CANNOT_FIND_DATA`);
   - under STRICT, any non-up-cast, including `SET c = NULL` on a column;
   - any UPDATE or MERGE INTO under the LEGACY policy.
   A struct with its fields in another order now works.
   
   ### Risk Level
   
   medium. Only non-native tables change, but statements that relied on 
implicit casts there now fail at analysis time; covered by the new tests and 
the existing MERGE INTO, UPDATE and partial update suites.
   
   ### Documentation Update
   
   The Spark SQL DML page should say that on a table of a non-native table 
format, UPDATE and MERGE INTO assignments follow 
`spark.sql.storeAssignmentPolicy` (ANSI by default; LEGACY is refused) like 
Spark's row-level tables, so an unsafe cast in an assignment must be written 
explicitly.
   
   ### 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