Skip to content

[CALCITE-7627] Enumerable DML should reject assignments that may lose data - #5211

Open
zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix_CALCITE-7627_store_assignment
Open

[CALCITE-7627] Enumerable DML should reject assignments that may lose data#5211
zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix_CALCITE-7627_store_assignment

Conversation

@zzwqqq

@zzwqqq zzwqqq commented Aug 23, 2026

Copy link
Copy Markdown
Member

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.

@zzwqqq

zzwqqq commented Aug 23, 2026

Copy link
Copy Markdown
Member Author

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!

@zzwqqq zzwqqq self-assigned this Aug 23, 2026
@sonarqubecloud

Copy link
Copy Markdown

* EnumerableCalc(
* condition=[
* AND(
* $THROW_UNLESS(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had no idea that this expression exists

if (targetType.getPrecision() < 0) {
continue;
}
// Check character and binary lengths because their casts may truncate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

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.

2 participants