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

Using`if` statement for a string subtype of the row type may meet npe in code generated by codegen

    XMLWordPrintableJSON

Details

    Description

      When I use the `if` statement for the string subtype of the row type, the code generated by `IfCallGen` may meet npe. The case is:

      -- if the value of 'nested' colmun is row(null, 10), the job will meet npe
      CREATE TABLE NestedTable (
        nested row<name string, `value` int>
      ) WITH (
        ...
      );
      
      select
          if (nested.name is null, 'JKL', nested.name) AS nestedName
      from NestedTable 

      Three conditions are required to reproduce the bug:

      1、use `if` statement

      2、string subtype of row type

      3、the value of string subtype element is null

       

      After excluding the effect of java code spilitter, the picture shows the original code generated by codegen(you can find the complete code generated by codegen in attached file: StreamExecCalc$17),the assignment logic for `isNull$7` is between the line 140 and the line 152, so the value of `isNull$7` in line 94 is always false(the default value), and the line 96 will meet npe when `result$7` is null.

      To fix this issue, we can change the location of the logic to generate casted codes in `IfCallGen`, like this:

      Attachments

        1. image-2023-03-29-16-06-19-351.png
          338 kB
          Yuan Kui
        2. StreamExecCalc$17
          7 kB
          Yuan Kui
        3. image-2023-03-29-15-33-37-983.png
          405 kB
          Yuan Kui

        Issue Links

          Activity

            People

              catyee Yuan Kui
              catyee Yuan Kui
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: