[
https://issues.apache.org/jira/browse/CALCITE-5127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17531602#comment-17531602
]
Benchao Li commented on CALCITE-5127:
-------------------------------------
[~dmsysolyatin] Thanks for reporting this, and the test cases.
I looked into the problem for a while, currently the ostensible reason is the
"projection merge"/"projection elimination".
For the first test case:
{code:sql}
SELECT ARRAY(SELECT s.x) FROM (SELECT ARRAY[1,2,3] as x) s;
{code}
the plan (if not merge the projection) should be:
{code:java}
LogicalProject(EXPR$0=[ARRAY({
LogicalProject(X=[$cor0.X])
LogicalValues(tuples=[[{ 0 }]])
})])
LogicalProject(X=[ARRAY(1, 2, 3)])
LogicalValues(tuples=[[{ 0 }]])
{code}
As you can see, "LogicalProject(X=[ARRAY(1, 2, 3)])"'s fields is not used by
the top project, that's why it is eliminated by {{RelBuilder}},
{{ProjectMergeRule}}, {{SqlToRelConverter::trimUnusedFields}}. (After I
disabled these codes, the test case passed.)
I'll dig deeper into the problem and propose a solution later.
> Error when executing query with subquery in select list that uses outer
> column of array type
> --------------------------------------------------------------------------------------------
>
> Key: CALCITE-5127
> URL: https://issues.apache.org/jira/browse/CALCITE-5127
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Dmitry Sysolyatin
> Priority: Major
>
> The following queries fail:
> {code}
> SELECT ARRAY(SELECT s.x) FROM (SELECT ARRAY[1,2,3] as x) s;
> SELECT ARRAY(SELECT * FROM UNNEST(s.x) y) FROM (SELECT ARRAY[1,2,3] as x) s;
> SELECT (SELECT CARDINALITY(s.x) LIMIT 1) FROM (SELECT ARRAY[1,2,3] as x) s;
>
> {code}
> With exception:
> {code}
> Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to
> java.util.List
> {code}
> You can find test cases for this task in
> https://github.com/apache/calcite/commit/27e68ded2c3bea7d7af73dd1dc156e46fb3591a8
--
This message was sent by Atlassian Jira
(v8.20.7#820007)