[ 
https://issues.apache.org/jira/browse/CALCITE-5127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17531619#comment-17531619
 ] 

Dmitry Sysolyatin edited comment on CALCITE-5127 at 5/4/22 9:22 AM:
--------------------------------------------------------------------

[~libenchao] Thanks for doing this task. There are more failing queries. But I 
am not sure that the reason is the same. It is more looks like that correlate 
variable $cor0 has an incorrect type
{code:java}
!use bookstore
SELECT array(SELECT lau."books")
FROM "bookstore"."authors" au
LEFT JOIN "bookstore"."authors" lau ON (lau."name" = au."name");
{code}
It does not take into account that `lau` records can be null because of LEFT 
JOIN as a result it fails:
{code:java}
> RecordType(RecordType(RecordType(JavaType(class java.lang.String) title, 
> JavaType(int) NOT NULL publishYear, RecordType(JavaType(int) NOT NULL pageNo, 
> JavaType(class java.lang.String) contentType) NOT NULL ARRAY NOT NULL pages) 
> NOT NULL ARRAY books) NOT NULL ARRAY NOT NULL EXPR$0) NOT NULL
> converted type:
> RecordType(RecordType(RecordType(JavaType(class java.lang.String) title, 
> JavaType(int) NOT NULL publishYear, RecordType(JavaType(int) NOT NULL pageNo, 
> JavaType(class java.lang.String) contentType) NOT NULL ARRAY NOT NULL pages) 
> NOT NULL ARRAY NOT NULL books) NOT NULL ARRAY NOT NULL EXPR$0) NOT NULL
> rel:
> LogicalProject(EXPR$0=[ARRAY({
> LogicalProject(books=[$cor0.books0])
>   LogicalValues(tuples=[[{ 0 }]])
> })])
>   LogicalJoin(condition=[=($9, $4)], joinType=[left])
>     LogicalProject(aid=[$0], name=[$1], birthPlace=[$2], books=[$3], 
> name0=[CAST($1):VARCHAR])
>       LogicalTableScan(table=[[bookstore, authors]])
>     LogicalProject(aid=[$0], name=[$1], birthPlace=[$2], books=[$3], 
> name0=[CAST($1):VARCHAR])
>       LogicalTableScan(table=[[bookstore, authors]])
> 
{code}


was (Author: dmsysolyatin):
[~libenchao] Thanks for doing this task. There are more failing queries. But I 
am not sure that the reason is the same. It is more looks like that correlate 
variable $cor0 has an incorrect type
{code:java}
!use bookstore
SELECT array(SELECT lau."books")
FROM "bookstore"."authors" au
LEFT JOIN "bookstore"."authors" lau ON (lau."name" = au."name");
{code}
It does not take into account that `lau` records can be null because of JOIN as 
a result it fails:
{code:java}
> RecordType(RecordType(RecordType(JavaType(class java.lang.String) title, 
> JavaType(int) NOT NULL publishYear, RecordType(JavaType(int) NOT NULL pageNo, 
> JavaType(class java.lang.String) contentType) NOT NULL ARRAY NOT NULL pages) 
> NOT NULL ARRAY books) NOT NULL ARRAY NOT NULL EXPR$0) NOT NULL
> converted type:
> RecordType(RecordType(RecordType(JavaType(class java.lang.String) title, 
> JavaType(int) NOT NULL publishYear, RecordType(JavaType(int) NOT NULL pageNo, 
> JavaType(class java.lang.String) contentType) NOT NULL ARRAY NOT NULL pages) 
> NOT NULL ARRAY NOT NULL books) NOT NULL ARRAY NOT NULL EXPR$0) NOT NULL
> rel:
> LogicalProject(EXPR$0=[ARRAY({
> LogicalProject(books=[$cor0.books0])
>   LogicalValues(tuples=[[{ 0 }]])
> })])
>   LogicalJoin(condition=[=($9, $4)], joinType=[left])
>     LogicalProject(aid=[$0], name=[$1], birthPlace=[$2], books=[$3], 
> name0=[CAST($1):VARCHAR])
>       LogicalTableScan(table=[[bookstore, authors]])
>     LogicalProject(aid=[$0], name=[$1], birthPlace=[$2], books=[$3], 
> name0=[CAST($1):VARCHAR])
>       LogicalTableScan(table=[[bookstore, authors]])
> 
{code}

> 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)

Reply via email to