phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject phoenix git commit: PHOENIX-2141 ComparisonExpression should return Boolean null if either operand is null (bug fix)
Date Tue, 25 Aug 2015 13:18:33 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 530bf8279 -> 6a3e54856


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/6a3e5485
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6a3e5485
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6a3e5485

Branch: refs/heads/4.x-HBase-0.98
Commit: 6a3e548560c10b6999bd00bb216b5ff3e925190c
Parents: 530bf82
Author: maryannxue <wei.xue@intel.com>
Authored: Tue Aug 25 09:18:17 2015 -0400
Committer: maryannxue <wei.xue@intel.com>
Committed: Tue Aug 25 09:18:17 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/6a3e5485/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/6a3e5485/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/6a3e5485/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 431990e..e950d38 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/6a3e5485/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();
+        }       
+    }
 
 }


Mime
View raw message