Ramin Gharib created FLINK-41243:
------------------------------------

             Summary: VARIANT field access with a non-literal key fails in code 
generation
                 Key: FLINK-41243
                 URL: https://issues.apache.org/jira/browse/FLINK-41243
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner
    Affects Versions: 2.3.0
            Reporter: Ramin Gharib
             Fix For: 2.5.0


VARIANT field access accepts any character string key, but the code generation 
only handles a literal key. A column or any other expression as the key fails 
while the planner generates code:

{code:sql}
-- v VARIANT, k STRING
SELECT v[k] FROM t;
SELECT v[LOWER(k)] FROM t;
{code}

{noformat}
java.util.NoSuchElementException: None.get
        at 
org.apache.flink.table.planner.codegen.calls.ScalarOperatorGens$.generateVariantGet(ScalarOperatorGens.scala:1750)
        at 
org.apache.flink.table.planner.codegen.ExprCodeGenerator.generateCallExpression(ExprCodeGenerator.scala:865)
{noformat}

The Table API fails the same way for $("v").at($("k")). A NULL literal key 
fails with a NullPointerException at the same place:

{code:sql}
SELECT v[CAST(NULL AS STRING)] FROM t;
{code}

Validation accepts these keys in SqlItemOperator and 
ItemAtIndexArgumentTypeStrategy. The code generation reads the key's literal 
value without checking that it is a literal, since FLINK-37924. A key that is 
not a literal should read the field per row.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to