Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-34656

Generated code for `ITEM` operator should return null when getting element of a null map/array/row

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.20.0
    • None
    • Table SQL / Planner
    • None

    Description

      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:

       

      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 

      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:

      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);
      } 

      The reduced expr will be a null literal.
       

      I think the behaviors for getting element of a null value should be unified.

      Attachments

        Activity

          People

            Unassigned Unassigned
            nilerzhou yisha zhou
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: