flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhue...@apache.org
Subject [12/12] flink git commit: [FLINK-3759] [table] Throw exception if NULL literal is encountered in non-null mode.
Date Fri, 15 Apr 2016 17:39:57 GMT
[FLINK-3759] [table] Throw exception if NULL literal is encountered in non-null mode.

This closes #1892


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

Branch: refs/heads/master
Commit: 722155a1fb95ddb45b6ee4c6cc6d0438cdbafac6
Parents: 1acd844
Author: twalthr <twalthr@apache.org>
Authored: Fri Apr 15 11:05:36 2016 +0200
Committer: Fabian Hueske <fhueske@apache.org>
Committed: Fri Apr 15 19:38:15 2016 +0200

----------------------------------------------------------------------
 .../flink/api/table/codegen/CodeGenerator.scala | 11 +++----
 .../api/java/table/test/ExpressionsITCase.java  | 24 +++++++++------
 .../api/scala/sql/test/ExpressionsITCase.scala  | 32 ++++++++++++--------
 .../scala/table/test/ExpressionsITCase.scala    | 22 ++++++++++----
 4 files changed, 55 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/722155a1/flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/CodeGenerator.scala
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/CodeGenerator.scala
b/flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/CodeGenerator.scala
index c336c82..7b3b02a 100644
--- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/CodeGenerator.scala
+++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/CodeGenerator.scala
@@ -907,18 +907,15 @@ class CodeGenerator(
     val resultTypeTerm = primitiveTypeTermForTypeInfo(resultType)
     val defaultValue = primitiveDefaultValue(resultType)
 
-    val wrappedCode = if (nullCheck) {
-      s"""
+    if (nullCheck) {
+      val wrappedCode = s"""
         |$resultTypeTerm $resultTerm = $defaultValue;
         |boolean $nullTerm = true;
         |""".stripMargin
+      GeneratedExpression(resultTerm, nullTerm, wrappedCode, resultType)
     } else {
-      s"""
-        |$resultTypeTerm $resultTerm = $defaultValue;
-        |""".stripMargin
+      throw new CodeGenException("Null literals are not allowed if nullCheck is disabled.")
     }
-
-    GeneratedExpression(resultTerm, nullTerm, wrappedCode, resultType)
   }
 
   // ----------------------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/flink/blob/722155a1/flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/ExpressionsITCase.java
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/ExpressionsITCase.java
b/flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/ExpressionsITCase.java
index 7980fe3..879c74f 100644
--- a/flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/ExpressionsITCase.java
+++ b/flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/ExpressionsITCase.java
@@ -27,7 +27,9 @@ import org.apache.flink.api.java.operators.DataSource;
 import org.apache.flink.api.java.tuple.Tuple2;
 import org.apache.flink.api.java.tuple.Tuple3;
 import org.apache.flink.api.table.TableEnvironment;
+import org.apache.flink.api.table.codegen.CodeGenException;
 import org.apache.flink.api.table.test.utils.TableProgramsTestBase;
+import static org.junit.Assert.fail;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -104,7 +106,7 @@ public class ExpressionsITCase extends TableProgramsTestBase {
 	@Test
 	public void testNullLiteral() throws Exception {
 		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
-		TableEnvironment tableEnv = getJavaTableEnvironment();
+		BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
 
 		DataSource<Tuple2<Integer, Integer>> input =
 				env.fromElements(new Tuple2<>(1, 0));
@@ -114,16 +116,20 @@ public class ExpressionsITCase extends TableProgramsTestBase {
 
 		Table result = table.select("a, b, Null(INT), Null(STRING) === ''");
 
-		DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
-		List<Row> results = ds.collect();
-		String expected;
-		if (getConfig().getNullCheck()) {
-			expected = "1,0,null,null";
+		try {
+			DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
+			if (!config().getNullCheck()) {
+				fail("Exception expected if null check is disabled.");
+			}
+			List<Row> results = ds.collect();
+			String expected = "1,0,null,null";
+			compareResultAsText(results, expected);
 		}
-		else {
-			expected = "1,0,-1,true";
+		catch (CodeGenException e) {
+			if (config().getNullCheck()) {
+				throw e;
+			}
 		}
-		compareResultAsText(results, expected);
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/flink/blob/722155a1/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/sql/test/ExpressionsITCase.scala
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/sql/test/ExpressionsITCase.scala
b/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/sql/test/ExpressionsITCase.scala
index 1d72c5d..fb69d08 100644
--- a/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/sql/test/ExpressionsITCase.scala
+++ b/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/sql/test/ExpressionsITCase.scala
@@ -19,13 +19,14 @@
 package org.apache.flink.api.scala.sql.test
 
 import org.apache.flink.api.scala.{ExecutionEnvironment, _}
+import org.apache.flink.api.table.{TableEnvironment, Row}
 import org.apache.flink.api.scala.table._
-import org.apache.flink.api.table.Row
-import org.apache.flink.api.table.plan.TranslationContext
+import org.apache.flink.api.table.codegen.CodeGenException
 import org.apache.flink.api.table.test.utils.TableProgramsTestBase
 import org.apache.flink.api.table.test.utils.TableProgramsTestBase.TableConfigMode
 import org.apache.flink.test.util.MultipleProgramsTestBase.TestExecutionMode
 import org.apache.flink.test.util.TestBaseUtils
+import org.junit.Assert._
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.junit.runners.Parameterized
@@ -42,23 +43,30 @@ class ExpressionsITCase(
   def testNullLiteral(): Unit = {
 
     val env = ExecutionEnvironment.getExecutionEnvironment
-    val tEnv = getScalaTableEnvironment
-    TranslationContext.reset()
+    val tEnv = TableEnvironment.getTableEnvironment(env, config)
 
     val sqlQuery = "SELECT a, b, CAST(NULL AS INT), CAST(NULL AS VARCHAR) = '' FROM MyTable"
 
-    val ds = env.fromElements((1, 0))
-    tEnv.registerDataSet("MyTable", ds, 'a, 'b)
+    val t = env.fromElements((1, 0))
+    tEnv.registerDataSet("MyTable", t, 'a, 'b)
 
     val result = tEnv.sql(sqlQuery)
 
-    val expected = if (getConfig.getNullCheck) {
-      "1,0,null,null"
-    } else {
-      "1,0,-1,true"
+    try {
+      val ds = result.toDataSet[Row]
+      if (!config.getNullCheck) {
+        fail("Exception expected if null check is disabled.")
+      }
+      val results = ds.collect()
+      val expected = "1,0,null,null"
+      TestBaseUtils.compareResultAsText(results.asJava, expected)
+    }
+    catch {
+      case e: CodeGenException =>
+        if (config.getNullCheck) {
+          throw e
+        }
     }
-    val results = result.toDataSet[Row](getConfig).collect()
-    TestBaseUtils.compareResultAsText(results.asJava, expected)
   }
 
 }

http://git-wip-us.apache.org/repos/asf/flink/blob/722155a1/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/table/test/ExpressionsITCase.scala
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/table/test/ExpressionsITCase.scala
b/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/table/test/ExpressionsITCase.scala
index 9e908dc..0e07eaa 100644
--- a/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/table/test/ExpressionsITCase.scala
+++ b/flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/table/test/ExpressionsITCase.scala
@@ -23,6 +23,7 @@ import java.util.Date
 import org.apache.flink.api.common.typeinfo.BasicTypeInfo
 import org.apache.flink.api.scala._
 import org.apache.flink.api.scala.table._
+import org.apache.flink.api.table.codegen.CodeGenException
 import org.apache.flink.api.table.expressions.Null
 import org.apache.flink.api.table.{TableEnvironment, Row}
 import org.apache.flink.api.table.expressions.Literal
@@ -30,6 +31,7 @@ import org.apache.flink.api.table.test.utils.TableProgramsTestBase
 import org.apache.flink.api.table.test.utils.TableProgramsTestBase.TableConfigMode
 import org.apache.flink.test.util.MultipleProgramsTestBase.TestExecutionMode
 import org.apache.flink.test.util.TestBaseUtils
+import org.junit.Assert._
 import org.junit._
 import org.junit.runner.RunWith
 import org.junit.runners.Parameterized
@@ -110,13 +112,21 @@ class ExpressionsITCase(
         Null(BasicTypeInfo.INT_TYPE_INFO),
         Null(BasicTypeInfo.STRING_TYPE_INFO) === "")
 
-    val expected = if (config.getNullCheck) {
-      "1,0,null,null"
-    } else {
-      "1,0,-1,true"
+    try {
+      val ds = t.toDataSet[Row]
+      if (!config.getNullCheck) {
+        fail("Exception expected if null check is disabled.")
+      }
+      val results = ds.collect()
+      val expected = "1,0,null,null"
+      TestBaseUtils.compareResultAsText(results.asJava, expected)
+    }
+    catch {
+      case e: CodeGenException =>
+        if (config.getNullCheck) {
+          throw e
+        }
     }
-    val results = t.toDataSet[Row].collect()
-    TestBaseUtils.compareResultAsText(results.asJava, expected)
   }
 
   // Date literals not yet supported


Mime
View raw message