Alessandro Solimando created CALCITE-4354:
---------------------------------------------

             Summary: ITEM operator does not support synthetic struct type
                 Key: CALCITE-4354
                 URL: https://issues.apache.org/jira/browse/CALCITE-4354
             Project: Calcite
          Issue Type: Improvement
          Components: core
    Affects Versions: 1.27.0
            Reporter: Alessandro Solimando


The current implementation of the "ITEM" operator only supports struct/row type 
when this type if based on a class with named fields (that is, a non-synthetic 
type).  

For those non-synthetic struct types, the "ITEM" operator can be used to access 
named fields via a "string"-typed argument 
([SqlItemOperator#96|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java#L96]).

The type checker accepts to apply "ITEM" on "ANY" type 
([SqlItemOperator#49|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java#L49]),
 and the operand checker only accepts "string"-based values 
([SqlItemOperator.java#105|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java#L105]).

[SqlValidatorTest.java#L11933|https://github.com/apache/calcite/blob/master/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java#L11933]
 is an example of application of the "ITEM" operator over a struct with named 
fields. 

However, the “getAllowedSignatures” method 
([SqlItemOperator.java#116|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java#L116])
 does not reflect this, and asserts a signature as follows: 
"<ARRAY>[<INTEGER>]" or "<MAP>[<VALUE>]".

"ITEM" operator could be enriched with the support of synthetic struct/row 
type, with a positional access to the fields with a signature 
"<ROW>[<INTEGER>]".



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to