[
https://issues.apache.org/jira/browse/CALCITE-7135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18016801#comment-18016801
]
Ruben Q L commented on CALCITE-7135:
------------------------------------
[~krooswu] thanks for taking this; I'm not sure if you've started to work on
it, but I looked a bit into the issue and I just found a simple fix (1 line of
code); so if you don't mind, I'm going to assign the ticket to myself and file
a PR with my fix proposal.
> 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: krooswu
> Priority: Major
>
> 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)