[
https://issues.apache.org/jira/browse/CALCITE-5127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17608166#comment-17608166
]
Stamatis Zampetakis commented on CALCITE-5127:
----------------------------------------------
The new tests added for {{RelFieldTrimmer}} in
https://github.com/apache/calcite/pull/2911, made me realize that the changes
there significantly reduces the capacity of field trimmer to work when there
are sub-queries. Normally, we can trim project fields even when it has
sub-queries but we cannot safely trim its inputs cause there may be problems
when we have correlation variables.
I also realized that the trimmer already contains
[code|https://github.com/apache/calcite/blob/f8dd80fcd2d4d92767936fe7b3dae349f2f0ec40/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java#L212]
to handle the case that some relational expression may reference fields
through correlation variables.
The latter means that if {{Project}} was returning the variables that are set,
the field trimmer would work without problems. It appears that my previous
comment where I stated that nobody uses {{Project#getVariablesSet}} was wrong.
I am really sorry to change my mind again but in the end the
https://github.com/apache/calcite/pull/2813 seems a better solution for the
problems we discovered now and for the long term.
[~libenchao] Let's reopen PR#2813 address the last few minor comments that
remain and merge that one if you agree.
> Error when executing query with correlated sub-query in SELECT clause
> ---------------------------------------------------------------------
>
> Key: CALCITE-5127
> URL: https://issues.apache.org/jira/browse/CALCITE-5127
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Dmitry Sysolyatin
> Assignee: Benchao Li
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.33.0
>
> Time Spent: 2h 40m
> Remaining Estimate: 0h
>
> 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.10#820010)