Skip to content

isthmus: a window offset that cannot be retyped to the ordering column falls back to a type-mismatched offset #1199

Closed

Description

@nielspardon

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, because SqlWindow.validateFrameBoundary only checks the bound's type family against orderTypeFam.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 carries add(i16, i32), which is not defined.
  • Decimal precision. digitCount(value) + scale > precision falls 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 PRECEDING keeps 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

  1. anasik commented on Aug 31, 2026

    @anasik
    Contributor

    @nielspardon taking this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingisthmus

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions