You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2015/08/25 14:58:18 UTC

phoenix git commit: PHOENIX-2141 ComparisonExpression should return Boolean null if either operand is null (bug fix)

Repository: phoenix
Updated Branches:
  refs/heads/master db137dcae -> 8a983243f


PHOENIX-2141 ComparisonExpression should return Boolean null if either operand is null (bug fix)


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

Branch: refs/heads/master
Commit: 8a983243f55bf36236bbcac018e01dff4cb14e8a
Parents: db137dc
Author: maryannxue <we...@intel.com>
Authored: Tue Aug 25 08:57:53 2015 -0400
Committer: maryannxue <we...@intel.com>
Committed: Tue Aug 25 08:57:53 2015 -0400

----------------------------------------------------------------------
 .../phoenix/compile/ExpressionCompiler.java     |  3 --
 .../phoenix/expression/AndExpression.java       |  3 --
 .../phoenix/compile/WhereCompilerTest.java      |  3 +-
 .../phoenix/expression/NullValueTest.java       | 45 +++++++++++++++++---
 4 files changed, 41 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a983243/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
index 1523dce..1278494 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
@@ -251,9 +251,6 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
             if (child.getDataType() != PBoolean.INSTANCE) {
                 throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), child.toString());
             }
-            if (LiteralExpression.isBooleanNull(child)) {
-                return child;
-            }
             if (LiteralExpression.isFalse(child)) {
                 iterator.remove();
             }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a983243/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
index 29b024d..70e94ca 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
@@ -44,9 +44,6 @@ public class AndExpression extends AndOrExpression {
             if (child.getDataType() != PBoolean.INSTANCE) {
                 throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), child.toString());
             }
-            if (LiteralExpression.isBooleanNull(child)) {
-                return child;
-            }
             if (LiteralExpression.isFalse(child)) {
                 return child;
             }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a983243/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
index 6c040d2..a1d1440 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
@@ -218,8 +218,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
 
     @Test
     public void testCollapseFunctionToNull() throws SQLException {
-        String tenantId = "000000000000001";
-        String query = "select * from atable where organization_id='" + tenantId + "' and substr(entity_id,null) = 'foo'";
+        String query = "select * from atable where substr(entity_id,null) = 'foo'";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
         PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a983243/phoenix-core/src/test/java/org/apache/phoenix/expression/NullValueTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/NullValueTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/NullValueTest.java
index d5addf0..e46c80c 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/NullValueTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/NullValueTest.java
@@ -38,16 +38,24 @@ public class NullValueTest extends BaseConnectionlessQueryTest {
     }
     
     @Test
-    public void testAndOrExpressionWithNullOperands() throws Exception {
-        String[] query = {"SELECT 'a' >= '' or '' < 'a'", 
+    public void testAndExpressionWithNullOperands() throws Exception {
+        String[] query = {"SELECT 'b' >= 'a' and '' < 'b'", 
+                          "SELECT 'b' >= '' and 'a' < 'b'",
+                          "SELECT 'a' >= 'b' and 'a' < ''",
+                          "SELECT '' >= 'a' and 'b' < 'a'",
                           "SELECT 'a' >= '' and '' < 'a'"};
+        Boolean[] result = {null,
+                            null,
+                            Boolean.FALSE,
+                            Boolean.FALSE,
+                            null};
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
-            for (String q : query) {
-                ResultSet rs = conn.createStatement().executeQuery(q);
+            for (int i = 0; i < query.length; i++) {
+                ResultSet rs = conn.createStatement().executeQuery(query[i]);
                 assertTrue(rs.next());
-                assertNull(rs.getObject(1));
+                assertEquals(result[i], rs.getObject(1));
                 assertEquals(false, rs.getBoolean(1));
                 assertFalse(rs.next());
             }
@@ -55,5 +63,32 @@ public class NullValueTest extends BaseConnectionlessQueryTest {
             conn.close();
         }       
     }
+    
+    @Test
+    public void testOrExpressionWithNullOperands() throws Exception {
+        String[] query = {"SELECT 'b' >= 'a' or '' < 'b'", 
+                          "SELECT 'b' >= '' or 'a' < 'b'",
+                          "SELECT 'a' >= 'b' or 'a' < ''",
+                          "SELECT '' >= 'a' or 'b' < 'a'",
+                          "SELECT 'a' >= '' or '' < 'a'"};
+        Boolean[] result = {Boolean.TRUE,
+                            Boolean.TRUE,
+                            null,
+                            null,
+                            null};
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            for (int i = 0; i < query.length; i++) {
+                ResultSet rs = conn.createStatement().executeQuery(query[i]);
+                assertTrue(rs.next());
+                assertEquals(result[i], rs.getObject(1));
+                assertEquals(Boolean.TRUE.equals(result[i]) ? true : false, rs.getBoolean(1));
+                assertFalse(rs.next());
+            }
+        } finally {
+            conn.close();
+        }       
+    }
 
 }