fix(isthmus)!: translate array indexes correctly - #1261
Draft
bvolpato wants to merge 2 commits into
Draft
Conversation
Normalize safe array indexes by their operator base. Preserve null and out-of-range low indexes without introducing negative list offsets, and check wide indexes before narrowing. BREAKING CHANGE: Unsafe array operators and unrepresentable offsets now reach unsupported-function handling instead of changing semantics.
Folding an invalid or null index to NULL can remove a throwing cast or another computed array operand. Restrict this fold to literals and references into an existing record; reject other operands when their evaluation cannot be preserved. Cover throwing casts, nested array selections, computed operands, and safe literal and column references for ITEM, SAFE_OFFSET, and SAFE_ORDINAL.
bvolpato
force-pushed
the
bvolpato/fix-array-item-index
branch
from
September 4, 2026 16:21
8659726 to
125c546
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calcite's safe array operators have a zero- or one-based index, while Substrait list references use zero-based offsets and interpret negative offsets from the end. Copying the literal index changes the selected value: for a = [10, 20, 30], a[1] becomes the second element and a[-1] becomes the last instead of null.
Normalize the index using the operator's declared base. Null and below-base indexes produce typed null when the array operand can safely be omitted, and wide integer indexes are checked before narrowing to the protobuf offset. The resulting offsets follow spec v0.102.0.
Downsides
Substrait list references cannot preserve the throwing behavior of unsafe OFFSET/ORDINAL operators, or represent offsets outside the signed 32-bit range. These conversions now fall through to unsupported-function handling. Computed array operands are also rejected for null or below-base indexes when folding them to null would discard evaluation, including errors from casts.
BREAKING CHANGE: Unsafe array access operators, unrepresentable indexes, and null or below-base accesses whose array operand cannot safely be omitted now fail conversion. Callers must handle the unsupported conversion when the operator or operand evaluation cannot be preserved.