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

jackylau commented on FLINK-31908:
----------------------------------

why i found this is here i supports the flink builtin functions like 
array_union [https://github.com/apache/flink/pull/22483/files]

for example in it
f0 is [1, 2, null] and type is INTEGER ARRAY
array_union(f0, [1.0E0, NULL, 4.0E0]) => it should return [1.0, 2.0, NULL, 4.0] 
but not.

the reasion is following  
{code:java}
[1, 2, null] => INTEGER ARRAY
[1.0E0, NULL, 4.0E0] => DOUBLE NOT NULL ARRAY NOT NULL

so the array_union function type is the common of the both DOUBLE ARRAY.
so the flink will insert implicit cast for f0, 
the cast should like cast(f0 as DOUBLE ARRAY), but it return cast(f0 as DOUBLE 
NOT NULL ARRAY),

this will cast [1, 2, null] -> [1.0, 2.0. 0.0] in the runtime eval method, make 
the result not correct. {code}
why it return cast(f0 as DOUBLE NOT NULL ARRAY)?
the root cause is calcite not transitive the nullable for array element

> cast expr to type with not null  should not change nullable of expr
> -------------------------------------------------------------------
>
>                 Key: FLINK-31908
>                 URL: https://issues.apache.org/jira/browse/FLINK-31908
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table SQL / API
>    Affects Versions: 1.18.0
>            Reporter: jackylau
>            Priority: Major
>
> {code:java}
> Stream<TestSetSpec> getTestSetSpecs() {
>     return Stream.of(
>             TestSetSpec.forFunction(BuiltInFunctionDefinitions.CAST)
>                     .onFieldsWithData(new Integer[]{1, 2}, 3)
>                     .andDataTypes(DataTypes.ARRAY(INT()), INT())
>                     .testSqlResult(
>                             "CAST(f0 AS ARRAY<DOUBLE NOT NULL>)",
>                             new Double[]{1.0d, 2.0d},
>                             DataTypes.ARRAY(DOUBLE().notNull())));
> } {code}
> but the result type should DataTypes.ARRAY(DOUBLE())), the root cause is 
> calcite bug



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to