yihua opened a new pull request, #20855: URL: https://github.com/apache/hudi/pull/20855
### Describe the issue this Pull Request addresses Closes #20841. Spark SQL UPDATE, DELETE and MERGE INTO on a Hudi table accept conditions Spark rejects for other tables. A non-deterministic condition (`rand()` in a WHERE, ON or WHEN clause) is applied by the write as a filter or inside `ExpressionPayload`, where it can be evaluated more than once per record. A subquery in a MERGE INTO WHEN condition fails inside the write with an internal error, and an aggregate there is evaluated per record. ### Summary and Changelog `ResolveImplementations` converted these statements into Hudi commands before Spark's analysis check could see them. It now leaves a statement with a non-deterministic condition unconverted, so Spark fails it with `INVALID_NON_DETERMINISTIC_EXPRESSIONS` as it does for other tables, and it refuses a subquery or aggregate in a WHEN condition at analysis with a message naming the clause (`MERGE operation contains unsupported UPDATE condition. Subqueries are not allowed: ...`). Tests: a new UPDATE/DELETE case in `TestUpdateTable` (COW and MOR) and a MERGE INTO case in `TestMergeIntoTable2` (keyed and keyless) assert each statement fails and the table is unchanged, and that a non-deterministic assignment value in an UPDATE, which is not a condition, still works. Without the fix the non-deterministic statements run and the subquery case fails inside the write. ### Impact Behavior change: statements with a non-deterministic condition now fail at analysis. In particular `DELETE FROM t WHERE rand() < 0.1`, which used to delete a random sample, no longer works on Hudi tables, matching Spark's behavior for other tables. A condition whose subquery reads a non-deterministic plan (for example a view with a `uuid()` column) is refused too, as Spark does. MERGE INTO with a subquery or aggregate in a WHEN condition fails with a clear analysis error instead of failing or misbehaving in the write. Subqueries and aggregates in MERGE INTO assignment values are not covered here and still fail in the write, as does a non-deterministic MERGE INTO assignment value (a separate, existing failure in `ExpressionPayload`). ### Risk Level low Only statements with non-deterministic conditions, or WHEN conditions with subqueries or aggregates, are affected. It conflicts textually with #20843 in `HoodieAnalysis`, `TestMergeIntoTable2` and `TestUpdateTable` (both touch the same `ResolveImplementations` cases and append tests); the changes are independent, so whichever merges second needs a rebase. ### Documentation Update none ### Contributor's checklist - [x] Read through [contributor's guide](https://hudi.apache.org/contribute/how-to-contribute) - [x] Enough context is provided in the sections above - [x] 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]
