flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhue...@apache.org
Subject [2/2] flink git commit: [FLINK-7309] [table] Fix NullPointerException when selecting null fields.
Date Tue, 29 Aug 2017 20:12:28 GMT
[FLINK-7309] [table] Fix NullPointerException when selecting null fields.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/eec261e9
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/eec261e9
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/eec261e9

Branch: refs/heads/release-1.3
Commit: eec261e9287b7272f21106df931686a9b4ca828a
Parents: 3167f72
Author: Yestin <873915231@qq.com>
Authored: Fri Aug 4 17:21:03 2017 +0800
Committer: Fabian Hueske <fhueske@apache.org>
Committed: Tue Aug 29 17:34:46 2017 +0200

----------------------------------------------------------------------
 .../flink/table/codegen/CodeGenerator.scala     | 14 +++++---
 .../table/expressions/TemporalTypesTest.scala   | 34 ++++++++++++++++++--
 2 files changed, 41 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/eec261e9/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/CodeGenerator.scala
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/CodeGenerator.scala
b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/CodeGenerator.scala
index f31b20c..c168d13 100644
--- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/CodeGenerator.scala
+++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/CodeGenerator.scala
@@ -1784,21 +1784,27 @@ class CodeGenerator(
     }
 
     val wrappedCode = if (nullCheck && !isReference(fieldType)) {
+      // assumes that fieldType is a boxed primitive.
       s"""
-        |$tmpTypeTerm $tmpTerm = $unboxedFieldCode;
-        |boolean $nullTerm = $tmpTerm == null;
+        |boolean $nullTerm = $fieldTerm == null;
         |$resultTypeTerm $resultTerm;
         |if ($nullTerm) {
         |  $resultTerm = $defaultValue;
         |}
         |else {
-        |  $resultTerm = $tmpTerm;
+        |  $resultTerm = $fieldTerm;
         |}
         |""".stripMargin
     } else if (nullCheck) {
       s"""
-        |$resultTypeTerm $resultTerm = $unboxedFieldCode;
         |boolean $nullTerm = $fieldTerm == null;
+        |$resultTypeTerm $resultTerm;
+        |if ($nullTerm) {
+        |  $resultTerm = $defaultValue;
+        |}
+        |else {
+        |  $resultTerm = $unboxedFieldCode;
+        |}
         |""".stripMargin
     } else {
       s"""

http://git-wip-us.apache.org/repos/asf/flink/blob/eec261e9/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/TemporalTypesTest.scala
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/TemporalTypesTest.scala
b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/TemporalTypesTest.scala
index 4f47fd5..e4bab24 100644
--- a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/TemporalTypesTest.scala
+++ b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/TemporalTypesTest.scala
@@ -538,10 +538,31 @@ class TemporalTypesTest extends ExpressionTestBase {
       "1990-09-12 10:20:45.123")
   }
 
+  @Test
+  def testSelectNullValues(): Unit ={
+    testAllApis(
+      'f11,
+      "f11",
+      "f11",
+      "null"
+    )
+    testAllApis(
+      'f12,
+      "f12",
+      "f12",
+      "null"
+    )
+    testAllApis(
+      'f13,
+      "f13",
+      "f13",
+      "null"
+    )
+  }
   // ----------------------------------------------------------------------------------------------
 
-  def testData = {
-    val testData = new Row(11)
+  def testData: Row = {
+    val testData = new Row(14)
     testData.setField(0, Date.valueOf("1990-10-14"))
     testData.setField(1, Time.valueOf("10:20:45"))
     testData.setField(2, Timestamp.valueOf("1990-10-14 10:20:45.123"))
@@ -553,6 +574,10 @@ class TemporalTypesTest extends ExpressionTestBase {
     testData.setField(8, 1467012213000L)
     testData.setField(9, 24)
     testData.setField(10, 12000L)
+    // null selection test.
+    testData.setField(11, null)
+    testData.setField(12, null)
+    testData.setField(13, null)
     testData
   }
 
@@ -568,6 +593,9 @@ class TemporalTypesTest extends ExpressionTestBase {
       Types.INT,
       Types.LONG,
       Types.INTERVAL_MONTHS,
-      Types.INTERVAL_MILLIS).asInstanceOf[TypeInformation[Any]]
+      Types.INTERVAL_MILLIS,
+      Types.SQL_DATE,
+      Types.SQL_TIME,
+      Types.SQL_TIMESTAMP).asInstanceOf[TypeInformation[Any]]
   }
 }


Mime
View raw message