yisha zhou created FLINK-34656: ---------------------------------- Summary: 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
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)