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

NullPointerException in CodeGenUtils.timePointToInternalCode() generated code

    XMLWordPrintableJSON

Details

    Description

      The code generated by CodeGenUtils.timePointToInternalCode() will cause a NullPointerException when SQL table field type is `TIMESTAMP` and the field value is `null`.

      Example for reproduce:

      object StreamSQLExample {
        def main(args: Array[String]): Unit = {
          val env = StreamExecutionEnvironment.getExecutionEnvironment
          val tEnv = TableEnvironment.getTableEnvironment(env)
      
          // null field value
          val orderA: DataStream[Order] = env.fromCollection(Seq(
            Order(null, "beer", 3)))
            
          tEnv.registerDataStream("OrderA", orderA, 'ts, 'product, 'amount)
          val result = tEnv.sql("SELECT * FROM OrderA")
          result.toAppendStream[Order].print()
          
          env.execute()
        }
      
        case class Order(ts: Timestamp, product: String, amount: Int)
      }
      

      In the above example, timePointToInternalCode() will generated some statements like this:

      ...
                long result$1 = org.apache.calcite.runtime.SqlFunctions.toLong((java.sql.Timestamp) in1.ts());
                boolean isNull$2 = (java.sql.Timestamp) in1.ts() == null;
      ...
      

      so, the NPE will happen when in1.ts() is null.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              llchen Liangliang Chen
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: