You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2015/04/16 21:33:53 UTC

[2/2] phoenix git commit: PHOENIX-1876 Check for null function arguments before evaluating when constant

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

Branch: refs/heads/4.3
Commit: 06e0d6102e369b682a2de453762e4b9997f72885
Parents: 759b82b
Author: James Taylor <jt...@salesforce.com>
Authored: Thu Apr 16 10:01:25 2015 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Thu Apr 16 12:32:25 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/06e0d610/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/06e0d610/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/06e0d610/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 81e4059..f474772 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
@@ -312,9 +312,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
@@ -327,6 +324,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) {