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

Benchao Li commented on FLINK-34656:
------------------------------------

[~nilerzhou] Thank you for the test case, it helps a lot, we indeed should fix 
it. The problem seems related to the type of 
{{ARRAY(BIGINT.notNull()).nullable()}}, although the inner type is {{NOT 
NULL}}, the outer type is {{NULLABLE}}, there is a similar discussion in 
FLINK-31830 (and a corresponding discussion thread : 
https://lists.apache.org/thread/fzrfc9c3rtgw761ofdydl0q96km558q7).

Since this is a codegen issue which does not affect the user interface, we can 
solve this directly.

> Generated code for `ITEM` operator should return null when getting element of 
> a null map/array/row
> --------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-34656
>                 URL: https://issues.apache.org/jira/browse/FLINK-34656
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>    Affects Versions: 1.20.0
>            Reporter: yisha zhou
>            Priority: Major
>
> In FieldAccessFromTableITCase we can find that the expected result of f0[1] 
> is null when f0 is a null array. 
> However, behavior in generated code for ITEM is not consistent with case 
> above. The main code is:
>  
> {code:java}
> val arrayAccessCode =
>   s"""
>      |${array.code}
>      |${index.code}
>      |boolean $nullTerm = ${array.nullTerm} || ${index.nullTerm} ||
>      |   $idxStr < 0 || $idxStr >= ${array.resultTerm}.size() || $arrayIsNull;
>      |$resultTypeTerm $resultTerm = $nullTerm ? $defaultTerm : $arrayGet;
>      |""".stripMargin {code}
> If `array.nullTerm` is true, a default value of element type will be 
> returned, for example -1 for null bigint array.
> The reason why FieldAccessFromTableITCase can get expected result is that the 
> ReduceExpressionsRule generated an expression code for that case like:
> {code:java}
> boolean isNull$0 = true || false ||
>    ((int) 1) - 1 < 0 || ((int) 1) - 1 >= 
> ((org.apache.flink.table.data.ArrayData) null).size() || 
> ((org.apache.flink.table.data.ArrayData) null).isNullAt(((int) 1) - 1);
> long result$0 = isNull$0 ? -1L : ((org.apache.flink.table.data.ArrayData) 
> null).getLong(((int) 1) - 1);
> if (isNull$0) {
>   out.setField(0, null);
> } else {
>   out.setField(0, result$0);
> } {code}
> The reduced expr will be a null literal.
>  
> I think the behaviors for getting element of a null value should be unified.



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

Reply via email to