Repository navigation
[FLINK-41370][table] Reject a literal index below 1 in SQL VARIANT array access - #29806
Merged
Merged
Conversation
raminqaf
force-pushed
the
FLINK-41370
branch
5 times, most recently
from
November 9, 2026 08:27
88632e5 to
04960d1
Compare
twalthr
approved these changes
Nov 9, 2026
…ray access SQL `v[0]` and `v[-1]` on an array VARIANT returned NULL for every row, while the same literal fails during planning for a plain ARRAY and for `VARIANT.at(INT)` in the Table API. The index is 1-based, so such a literal can never address an element. The ARRAY literal-index check now also runs for a VARIANT index of any integer type. A computed index below 1 still returns NULL. Generated-by: Claude Code 2.1.319 (Claude Opus 5.5)
Merged
1 task done
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.
What is the purpose of the change
SQL array access on a VARIANT returned NULL for a literal index below 1. The same literal already fails during planning for a plain ARRAY, and for
VARIANT.at(INT)in the Table API. With a VARIANT columnvholding[1, "hello", 3.14]:v[0]NULLArray element access needs an index starting at 1 but was 0.v[-1]NULLArray element access needs an index starting at 1 but was -1.v[-4294967295]NULLArray element access needs an index starting at 1 but was -4294967295.$("v").at(0L)in Table APINULLArray element access needs an index starting at 1 but was 0.v[i]withi = 0NULLNULLThe index is 1-based, so such a literal can never address an element. A computed index below 1 still returns NULL, as it does for ARRAY. A computed BIGINT index outside the INT range also still returns NULL, as FLINK-41330 made it. DuckDB and Trino, the other engines with a 1-based VARIANT index, also reject index 0. The Table API check already rejected an INT literal in
at(). A TINYINT, SMALLINT or BIGINT literal now fails too.An expression with such a literal returned NULL for every row and now fails during planning. This includes a literal in a branch that never runs, such as
CASE WHEN i > 0 THEN v[i] ELSE v[0] END, as it does for ARRAY. The check runs during code generation, soCOMPILE PLANstill succeeds andEXECUTE PLANfails, again as for ARRAY. No released version holds such a plan, because Flink 2.3.0 can't round-trip a compiled plan with a VARIANT expression through JSON (Unsupported RelDataType: VARIANT).I plan to backport this to release-2.4 so it ships with 2.4.0, the first release that can restore a compiled plan with
v[i].Brief change log
ScalarOperatorGens.generateVariantGetruns the ARRAY literal-index check. The check moves into a shared helper and matches a literal of any integer type, since a VARIANT index can be TINYINT to BIGINT. ARRAY still only reaches it with INT, becauserequireIntegerruns first.variant '[' INT ']'entry insql_functions.ymlsays that a literal index below 1 fails during planning.Verifying this change
This change added tests and can be verified as follows:
VARIANT_ARRAY_ERROR_ACCESSinVariantSemanticTest. Without the fix they fail withExpecting code to raise a throwable.v[-4294967295]is a BIGINT literal, so it pins that the check accepts any integer literal and compares it as along. Narrowed toint, the literal would be 1 and pass.VARIANT_ARRAY_ACCESS_WITH_NON_LITERAL_INDEXcovers a computed index of 0, which still returns NULL.ArrayTypeTest#testArrayIndexStaticCheckForSqlstill pins the ARRAY message.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code 2.1.319 (Claude Opus 5.5)