[ 
https://issues.apache.org/jira/browse/CALCITE-7135?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ruben Q L reopened CALCITE-7135:
--------------------------------

I'm reopening this ticket because I just realized that the proposed fix only 
withs if SqlToRelConverter uses withExpand=true, but still fails with the 
(default) withExpand=false.
I'll create a follow-up PR right away to complete the patch.

> 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
>            Assignee: Ruben Q L
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.41.0
>
>
> 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