Ruben Q L created CALCITE-7135:
----------------------------------

             Summary: SqlToRelConverter throws AssertionError on ARRAY subquery 
order by a field that is not present on the final projection
                 Key: CALCITE-7135
                 URL: https://issues.apache.org/jira/browse/CALCITE-7135
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.40.0
            Reporter: Ruben Q L


This query works fine in SqlToRelConverter:
{code:sql}
SELECT ARRAY(SELECT empno FROM emp)
{code}

This also works:
{code:sql}
SELECT ARRAY(SELECT empno FROM emp ORDER BY empno)
{code}

However this one:
{code:sql}
SELECT ARRAY(SELECT empno FROM emp ORDER BY ename)
{code}
fails with

{noformat}
java.lang.AssertionError: Conversion to relational algebra failed to preserve 
datatypes:
validated type:
RecordType(INTEGER NOT NULL ARRAY NOT NULL EXPR$0) NOT NULL
converted type:
RecordType(RecordType(INTEGER NOT NULL EMPNO, VARCHAR(20) NOT NULL ENAME) NOT 
NULL ARRAY NOT NULL EXPR$0) NOT NULL
...
at 
org.apache.calcite.sql2rel.SqlToRelConverter.checkConvertedType(SqlToRelConverter.java:524)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:643)
{noformat}

This problem seems to be that the subquery to construct the array is order by a 
field that is not part of its final projection; Calcite usually deals with this 
situation using a RelRoot "wrapper", but in this scenario we just have a simple 
RelNode.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to