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

Sergey Nuyanzin commented on FLINK-40182:
-----------------------------------------

Merged as 
[baab138d7784d44d2a49ec83b861c444b3705587|https://github.com/apache/flink/commit/baab138d7784d44d2a49ec83b861c444b3705587]

> ArrayToArray and MapToMap cast rules generate code which might fail with NPE
> ----------------------------------------------------------------------------
>
>                 Key: FLINK-40182
>                 URL: https://issues.apache.org/jira/browse/FLINK-40182
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>            Reporter: Sergey Nuyanzin
>            Assignee: Sergey Nuyanzin
>            Priority: Major
>              Labels: pull-request-available
>
> {{ArrayToArrayCastRule}}, {{MapToMapAndMultisetToMultisetCastRule}} generate 
> code that trusted the target type's declared NOT NULL nullability instead of 
> checking the actual runtime value. When the source array/map element was 
> actually null (a cast doesn't enforce constraints, so a NOT NULL target type 
> is not a runtime guarantee).
> Better to throw TableRuntimeException with a better message.
> repro
> {code:sql}
> SELECT CAST(
>     ARRAY_SLICE(
>       test_array,
>       1,
>       LEAST( CARDINALITY(JSON_QUERY(b, 'lax $[*]' RETURNING ARRAY<STRING>)), 
> 10 )
>     )
>   as ARRAY<ROW<`id` STRING NOT NULL> NOT NULL>)
> FROM (
>   SELECT
>     *,
>     ARRAY[
>       ROW(JSON_VALUE(a.b, '$[0].id' RETURNING VARCHAR ERROR ON EMPTY)),
>       CASE WHEN JSON_EXISTS(a.b, '$[1]') THEN
>         ROW(JSON_VALUE(a.b, '$[1].id' RETURNING VARCHAR ERROR ON EMPTY))
>       END,
>       ROW(JSON_VALUE(a.b, '$[2].id' RETURNING VARCHAR ERROR ON EMPTY)),
>       CASE WHEN JSON_EXISTS(a.b, '$[3]') THEN
>         ROW(JSON_VALUE(a.b, '$[3].id' RETURNING VARCHAR ERROR ON EMPTY))
>       END
>     ] as test_array
>   FROM (VALUES (
>     '[{"id":"S1"},null,{"id":"S3"}]'
>   )) AS a(b)
> ) AS test_array;{code}



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

Reply via email to