Oops, I misspoke. Calcite hasn’t used the array-to-Values transformation here. 
I’m not sure where the ARRAY literal has gone. Possibly it’s still present, 
just not being printed in the plan. 

Julian

> On May 2, 2022, at 8:41 AM, Julian Hyde <jhyde.apa...@gmail.com> wrote:
> 
> The plan isn’t “completely wrong”. Calcite intentionally converts UNNEST of 
> a constant ARRAY into Values because the latter is a primitive relational 
> expression.
> 
> As for the casts, maybe some confusion about scalar types versus record types 
> with a single field. Can you please log a jira case. 
> 
> Julian
> 
>> On May 2, 2022, at 8:09 AM, Dmitry Sysolyatin <dm.sysolya...@gmail.com> 
>> wrote:
>> 
>> Hi!
>> I am working on https://issues.apache.org/jira/browse/CALCITE-5126. When I
>> was writing tests for this task I faced with issue that reproducible in
>> main branch as well.
>> 
>> I tried to execute the following query using unnest.iq file
>> 
>> SELECT ARRAY(SELECT * FROM UNNEST(s.x) y)
>> FROM (SELECT ARRAY[1,2,3] as x) s;
>> 
>> Calcite generated the following plan:
>> 
>> EnumerableProject(EXPR$0=[$1]): rowcount = 1.0, cumulative cost = {14.0
>> rows, 12.0 cpu, 0.0 io}, id = 98
>> 
>> EnumerableCorrelate(correlation=[$cor0], joinType=[inner],
>> requiredColumns=[{0}]): rowcount = 1.0, cumulative cost = {13.0 rows, 11.0
>> cpu, 0.0 io}, id = 97
>> 
>>   EnumerableValues(tuples=[[{ 0 }]]): rowcount = 1.0, cumulative cost =
>> {1.0 rows, 1.0 cpu, 0.0 io}, id = 79
>> 
>>   EnumerableCollect(field=[x]): rowcount = 1.0, cumulative cost = {5.0
>> rows, 5.0 cpu, 0.0 io}, id = 96
>> 
>>     EnumerableProject(EXPR$0=[+($0, 1)]): rowcount = 1.0, cumulative cost
>> = {4.0 rows, 4.0 cpu, 0.0 io}, id = 95
>> 
>>       EnumerableUncollect: rowcount = 1.0, cumulative cost = {3.0 rows,
>> 3.0 cpu, 0.0 io}, id = 94
>> 
>>         EnumerableProject(X=[$cor0.X]): rowcount = 1.0, cumulative cost =
>> {2.0 rows, 2.0 cpu, 0.0 io}, id = 93
>> 
>>           EnumerableValues(tuples=[[{ 0 }]]): rowcount = 1.0, cumulative
>> cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 79
>> 
>> It is a completely wrong plan. It does not use ARRAY[1,2,3] at all and code
>> fails with error:
>> Caused by: java.lang.ClassCastException: class java.lang.Integer cannot be
>> cast to class java.util.List (java.lang.Integer and java.util.List are in
>> module java.base of loader 'bootstrap')
>> 
>> 
>> Maybe someone knows how to fastly fix this?

Reply via email to