Repository navigation
Description
Description
WindowBoundConverter.integralLiteralOfType (added in #1156) retypes an integral literal offset to match the ordering column's type, so that add(T, D) -> T stays defined for a RANGE frame. When it cannot do that it returns Optional.empty(), and the caller's .orElse(offset) keeps whatever type Calcite gave the literal — which is exactly the mismatch the method exists to prevent, now emitted silently.
When the fallback fires
Every guard in the method has a path to it:
- Out of range for a narrow ordering column.
ORDER BY smallint_col RANGE BETWEEN 100000 PRECEDING— Calcite accepts it, becauseSqlWindow.validateFrameBoundaryonly checks the bound's type family againstorderTypeFam.allowableDifferenceTypes()for RANGE, with no range check and no coercion to the ordering type. The i16 guard rejects 100000, so the offset stays an i32 literal and the plan carriesadd(i16, i32), which is not defined. - Decimal precision.
digitCount(value) + scale > precisionfalls through the same way. - FP round-trip. A value that does not survive
(long)(double) value(or the float equivalent) falls through. - Any ordering type the method does not enumerate — temporal columns, for instance.
ORDER BY timestamp_col RANGE BETWEEN 5 PRECEDINGkeeps an integral offset against a timestamp, where the spec wants interval_day.
All of these are degenerate frames in practice: a distance larger than the column's own domain, or a unit mismatch. That is why this is low severity rather than none — the plan is well-formed but not spec-conformant, and nothing says so.
What to decide
Throwing is the only thing that makes it visible, and UnsupportedOperationException is the established isthmus idiom for "this SQL has no faithful Substrait form". The counter-argument is that isthmus would then reject SQL that Calcite accepts and that it has converted since long before #1156, so a lenient-but-silent conversion may be the deliberate trade. Either way it is worth stating in the code rather than leaving as a fallthrough.
Test gap
The guards and the decimal/FP branches have no coverage. WindowBoundConverterTest (added in #1156) covers the happy paths — decimal keeps its fraction, ROWS widens to i64, RANGE takes the ordering type, zero becomes CurrentRow, a non-literal offset passes through — but the 47f52f9d commit that added the range checks and the decimal/FP branches added no tests, so every branch above is untested. Worth adding regardless of which way the question above goes, since the expected behaviour is observable either way.
Context
Surfaced reviewing #1156. Same shape as #1138 (spark: interval_year literal conversion silently wraps on Int overflow): a narrowing conversion that produces a plausible-looking value instead of failing. The related core-side gap — nothing validates offset/ordering type compatibility for a plan built directly or read from proto — is #1198.
🤖 Generated with AI
Activity
anasik commentedon Aug 31, 2026
@nielspardon taking this