Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 a0999539d -> 656ce76aa


PHOENIX-1876 Check for null function arguments before evaluating when constant


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 5479ab6e62572efa1d0e2fc4373837bbd219f80d
Parents: a099953
Author: James Taylor <jtay...@salesforce.com>
Authored: Thu Apr 16 10:01:25 2015 -0700
Committer: James Taylor <jtay...@salesforce.com>
Committed: Thu Apr 16 12:08:18 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/phoenix/end2end/DecodeFunctionIT.java   | 9 +++------
 .../java/org/apache/phoenix/end2end/EncodeFunctionIT.java   | 8 ++------
 .../java/org/apache/phoenix/compile/ExpressionCompiler.java | 6 +++---
 3 files changed, 8 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5479ab6e/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
index 68e0add..93205a7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
@@ -18,6 +18,7 @@
 package org.apache.phoenix.end2end;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -111,12 +112,8 @@ public class DecodeFunctionIT extends 
BaseHBaseManagedTimeIT {
 
                conn.createStatement().execute(ddl);
 
-               try {
-                       conn.createStatement().executeQuery("SELECT * FROM 
test_table WHERE some_column = DECODE('8', NULL)");
-            fail();
-        } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.ILLEGAL_DATA.getErrorCode(), 
e.getErrorCode());
-        }
+               ResultSet rs = conn.createStatement().executeQuery("SELECT * 
FROM test_table WHERE some_column = DECODE('8', NULL)");
+               assertFalse(rs.next());
        }
 
        @Test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5479ab6e/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
index 489ebfd..ceafc5b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
@@ -116,12 +116,8 @@ public class EncodeFunctionIT extends 
BaseHBaseManagedTimeIT {
         String ddl = "CREATE TABLE TEST_TABLE ( pk VARCHAR(10) NOT NULL 
CONSTRAINT PK PRIMARY KEY (pk))";
         conn.createStatement().execute(ddl);
 
-        try {
-            conn.createStatement().executeQuery("SELECT * FROM TEST_TABLE 
WHERE pk = ENCODE(1, NULL)");
-            fail();
-        } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.ILLEGAL_DATA.getErrorCode(), 
e.getErrorCode());
-        }
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM 
TEST_TABLE WHERE pk = ENCODE(1, NULL)");
+        assertFalse(rs.next());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5479ab6e/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 ce95850..ab6b851 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
@@ -316,9 +316,6 @@ public class ExpressionCompiler extends 
UnsupportedAllParseNodeVisitor<Expressio
         children = node.validate(children, context);
         Expression expression = node.create(children, context);
         ImmutableBytesWritable ptr = context.getTempPtr();
-        if (ExpressionUtil.isConstant(expression)) {
-            return ExpressionUtil.getConstantExpression(expression, ptr);
-        }
         BuiltInFunctionInfo info = node.getInfo();
         for (int i = 0; i < info.getRequiredArgCount(); i++) { 
             // Optimization to catch cases where a required argument is null 
resulting in the function
@@ -331,6 +328,9 @@ public class ExpressionCompiler extends 
UnsupportedAllParseNodeVisitor<Expressio
                 }
             }
         }
+        if (ExpressionUtil.isConstant(expression)) {
+            return ExpressionUtil.getConstantExpression(expression, ptr);
+        }
         expression = addExpression(expression);
         expression = wrapGroupByExpression(expression);
         if (aggregateFunction == node) {

Reply via email to