carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipes...@apache.org
Subject [07/42] carbondata git commit: updated null check for right expression in not in expression
Date Thu, 15 Jun 2017 11:50:12 GMT
updated null check for right expression in not in expression


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

Branch: refs/heads/branch-1.1
Commit: 93f7f96674ce25bf83b13bb7947178ce52115420
Parents: fd50ad2
Author: kunal642 <kunal.kapoor@knoldus.in>
Authored: Thu May 18 13:48:34 2017 +0530
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Thu Jun 15 12:44:54 2017 +0530

----------------------------------------------------------------------
 .../expression/conditional/NotInExpression.java | 22 ++++++++++----------
 .../ExpressionWithNullTestCase.scala            |  2 ++
 2 files changed, 13 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/93f7f966/core/src/main/java/org/apache/carbondata/core/scan/expression/conditional/NotInExpression.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/core/scan/expression/conditional/NotInExpression.java
b/core/src/main/java/org/apache/carbondata/core/scan/expression/conditional/NotInExpression.java
index 2552f96..67e3a50 100644
--- a/core/src/main/java/org/apache/carbondata/core/scan/expression/conditional/NotInExpression.java
+++ b/core/src/main/java/org/apache/carbondata/core/scan/expression/conditional/NotInExpression.java
@@ -42,6 +42,17 @@ public class NotInExpression extends BinaryConditionalExpression {
     if (setOfExprResult == null) {
       ExpressionResult val = null;
       ExpressionResult rightRsult = right.evaluate(value);
+      // Both left and right result need to be checked for null because NotInExpression is
basically
+      // an And Operation on the list of predicates that are provided.
+      // Example: x in (1,2,null) would be converted to x=1 AND x=2 AND x=null.
+      // If any of the predicates is null then the result is unknown for all the predicates
thus
+      // we will return false for each of them.
+      for (ExpressionResult expressionResult: rightRsult.getList()) {
+        if (expressionResult.isNull() || leftRsult.isNull()) {
+          leftRsult.set(DataType.BOOLEAN, false);
+          return leftRsult;
+        }
+      }
       setOfExprResult = new HashSet<ExpressionResult>(10);
       for (ExpressionResult exprResVal : rightRsult.getList()) {
         if (exprResVal.getDataType().getPrecedenceOrder() < leftRsult.getDataType()
@@ -80,17 +91,6 @@ public class NotInExpression extends BinaryConditionalExpression {
         setOfExprResult.add(val);
       }
     }
-    // Both left and right results need to be checked for null because NotInExpression is
basically
-    // an And Operation on the list of predicates that are provided.
-    // Example: x in (1,2,null) would be converted to x=1 AND x=2 AND x=null.
-    // If any of the predicates is null then the result is unknown for all the predicates
thus
-    // we will return false for each of them.
-    for (ExpressionResult expressionResult: setOfExprResult) {
-      if (expressionResult.isNull() || leftRsult.isNull()) {
-        leftRsult.set(DataType.BOOLEAN, false);
-        return leftRsult;
-      }
-    }
     leftRsult.set(DataType.BOOLEAN, !setOfExprResult.contains(leftRsult));
     return leftRsult;
   }

http://git-wip-us.apache.org/repos/asf/carbondata/blob/93f7f966/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/ExpressionWithNullTestCase.scala
----------------------------------------------------------------------
diff --git a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/ExpressionWithNullTestCase.scala
b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/ExpressionWithNullTestCase.scala
index a421c7e..cbc2750 100644
--- a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/ExpressionWithNullTestCase.scala
+++ b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/ExpressionWithNullTestCase.scala
@@ -38,6 +38,7 @@ class ExpressionWithNullTestCase extends QueryTest with BeforeAndAfterAll
{
   }
 
   test("test to check in expression with null values") {
+    checkAnswer(sql("select * from expression_test where id in (1,2,'', NULL, ' ')"), sql("select
* from expression_test_hive where id in (1,2,' ', NULL, ' ')"))
     checkAnswer(sql("select * from expression_test where id in (1,2,'')"), sql("select *
from expression_test_hive where id in (1,2,'')"))
     checkAnswer(sql("select * from expression_test where id in ('')"), sql("select * from
expression_test_hive where id in ('')"))
     checkAnswer(sql("select * from expression_test where number in (null)"), sql("select
* from expression_test_hive where number in (null)"))
@@ -54,6 +55,7 @@ class ExpressionWithNullTestCase extends QueryTest with BeforeAndAfterAll
{
   }
 
   test("test to check not in expression with null values") {
+    checkAnswer(sql("select * from expression_test where id not in (1,2,'', NULL, ' ')"),
sql("select * from expression_test_hive where id not in (1,2,' ', NULL, ' ')"))
     checkAnswer(sql("select * from expression_test where id not in (1,2,'')"), sql("select
* from expression_test_hive where id not in (1,2,'')"))
     checkAnswer(sql("select * from expression_test where id not in ('')"), sql("select *
from expression_test_hive where id not in ('')"))
     checkAnswer(sql("select * from expression_test where number not in (null)"), sql("select
* from expression_test_hive where number not in (null)"))


Mime
View raw message