[CALCITE-7627] Enumerable DML should reject assignments that may lose data - #5211
[CALCITE-7627] Enumerable DML should reject assignments that may lose data#5211zzwqqq wants to merge 1 commit into
Conversation
|
Hi @mihaibudiu @xuzifu666, this is a follow-up to #5041, which you both reviewed. Could you take a look at this PR as well? Thanks! |
|
| * EnumerableCalc( | ||
| * condition=[ | ||
| * AND( | ||
| * $THROW_UNLESS( |
There was a problem hiding this comment.
Had no idea that this expression exists
| if (targetType.getPrecision() < 0) { | ||
| continue; | ||
| } | ||
| // Check character and binary lengths because their casts may truncate. |
There was a problem hiding this comment.
I think that a nicer solution would be to have a way for users to plug-in a function to convert each value.
For example, you may reject dates BC, or you may round timestamps that have higher precision.
The plug-in should be per type: for each input column type, there's a custom function to accept the value (perhaps converting it), or throw if the value is out of range.
I don't really know how you can do this cleanly - this code generator is not parameterized.
There was a problem hiding this comment.
Thanks for reviewing. Just to make sure I understand: are you suggesting a hook for each target type that can validate or convert a value before it is assigned to the target column? Would you expect the generated code for EnumerableTableModify to call this hook at execution time, or would the hook build a Rex expression in the input plan?



Jira Link
CALCITE-7627
Changes Proposed
This is a follow-up to #5041.
Add an EnumerableCalc below EnumerableTableModify for INSERT and UPDATE. The Calc checks bounded character and binary values with CHAR_LENGTH or OCTET_LENGTH, and uses target casts for exact numeric conversion and bounded DECIMAL checks. Overlength values and numeric overflow fail at runtime; NULL values pass. Unbounded character and binary types and approximate numeric types are unchanged.
This implementation uses the conversion rule to reuse the existing Rex implementations for length checks and casts. A code-generator implementation is also possible, but it would need equivalent Java-level handling and the same semantics as Rex.
Tests cover character and binary lengths, trailing spaces, numeric conversion and overflow, DECIMAL precision and scale, NULL values, and UPDATE assignments.