Skip to content

fix(isthmus)!: preserve UPDATE predicates - #1259

Draft
bvolpato wants to merge 2 commits into
substrait-io:mainfrom
bvolpato:bvolpato/fix-update-predicate
Draft

fix(isthmus)!: preserve UPDATE predicates#1259
bvolpato wants to merge 2 commits into
substrait-io:mainfrom
bvolpato:bvolpato/fix-update-predicate

Conversation

@bvolpato

@bvolpato bvolpato commented Sep 3, 2026

Copy link
Copy Markdown
Member

Calcite represents a normal SQL UPDATE as a projection over the WHERE filter. Checking only the immediate input therefore replaces the predicate with TRUE. For example:

CREATE TABLE src1 (intcol INT, charcol VARCHAR(10));
UPDATE src1 SET intcol = 10 WHERE 1 = 0;

The converted update currently targets every row. Walk the projection/filter chain, express both predicates and assignments in target-table coordinates, and retain every selection condition. This also handles predicates above projections and assignments containing projected references inside larger expressions.

Downsides

Flattening cannot preserve every Calcite input pipeline in Substrait's zero-input UpdateRel. Conversion rejects unsupported row-selection operators, window or nondeterministic projections, multiple filters with nondeterministic predicates, and removed correlation binding points instead of emitting a different update. Independent subqueries remain supported when their evaluation can be preserved, and the determinism check includes expressions inside subqueries. A single filter condition keeps its original expression so repeated volatile calls are not deduplicated.

BREAKING CHANGE: UPDATE conversion now throws UnsupportedOperationException for input pipelines it cannot preserve. Callers must handle the unsupported conversion instead of relying on the previous output, which could discard selection conditions, retain unresolved outer references, or change how often nondeterministic expressions run.

Resolve predicates and assignments through projection/filter inputs back to
columns of the target table. Reject input pipelines that cannot be preserved
by a zero-input UpdateRel.

BREAKING CHANGE: UPDATE conversion rejects unsupported row-selection
operators, window projections, and removed correlation binding points
instead of emitting an update with different selection semantics.
Inlining a projected nondeterministic value can evaluate it more than once, and composing multiple filters can deduplicate repeated volatile predicates. Reject those input shapes when their evaluation boundaries cannot be represented by UpdateRel.

Inspect nested subquery plans and their aggregate and window operators for nondeterminism. Convert a single filter condition directly so repeated volatile calls inside it remain distinct. Cover projected RAND values, multiple RAND filters, and single-filter conversion with a custom function mapper.
@bvolpato
bvolpato force-pushed the bvolpato/fix-update-predicate branch from c9b3d1c to 43057b4 Compare September 4, 2026 16:15
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.

1 participant