phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject phoenix git commit: PHOENIX-2314 Cannot prepare parameterized statement with a 'like' predicate
Date Mon, 04 Sep 2017 22:03:37 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master f03c43bdd -> 0a3ef6c1b


PHOENIX-2314 Cannot prepare parameterized statement with a 'like' predicate


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

Branch: refs/heads/master
Commit: 0a3ef6c1b5f2013ce6b3e5158e0417294ab7d92b
Parents: f03c43b
Author: kliewkliew <kliew@apache.org>
Authored: Fri Sep 1 14:28:44 2017 -0700
Committer: kliewkliew <kliewkliew@users.noreply.github.com>
Committed: Sun Sep 3 14:19:12 2017 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/LikeExpressionIT.java       | 16 +++++++++++
 .../phoenix/compile/ExpressionCompiler.java     |  2 +-
 .../phoenix/end2end/QueryServerBasicsIT.java    | 28 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0a3ef6c1/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
index c2198cc..0b061d5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
@@ -414,4 +414,20 @@ public class LikeExpressionIT extends ParallelStatsDisabledIT {
             assertEquals(expectedCount, i);
         }
     }
+
+    @Test
+    public void testParameterizedLikeExpression() throws Exception {
+        final Connection conn = DriverManager.getConnection(getUrl());
+        final PreparedStatement select = conn.prepareStatement(
+                "select k from " + tableName + " where k like ?");
+        select.setString(1, "12%");
+        ResultSet rs = select.executeQuery();
+        assertTrue(rs.next());
+        assertEquals("123n7-app-2-", rs.getString(1));
+        assertFalse(rs.next());
+
+        select.setString(1, null);
+        rs = select.executeQuery();
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0a3ef6c1/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 fb4c542..9daa744 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
@@ -498,7 +498,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
         if (rhs instanceof LiteralExpression) {
             String pattern = (String)((LiteralExpression)rhs).getValue();
             if (pattern == null || pattern.length() == 0) {
-                return LiteralExpression.newConstant(null, rhs.getDeterminism());
+                return LiteralExpression.newConstant(null, PBoolean.INSTANCE, rhs.getDeterminism());
             }
             // TODO: for pattern of '%' optimize to strlength(lhs) > 0
             // We can't use lhs IS NOT NULL b/c if lhs is NULL we need

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0a3ef6c1/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
b/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
index ca4cf0b..ceb0a78 100644
--- a/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
+++ b/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
@@ -315,4 +315,32 @@ public class QueryServerBasicsIT extends BaseHBaseManagedTimeIT {
   private int getArrayValueForOffset(int arrayOffset) {
       return arrayOffset * 2 + 1;
   }
+
+  @Test
+  public void testParameterizedLikeExpression() throws Exception {
+    final Connection conn = DriverManager.getConnection(CONN_STRING);
+    final String tableName = generateUniqueName();
+    conn.createStatement().execute(
+            "CREATE TABLE " + tableName + " (k VARCHAR NOT NULL PRIMARY KEY, i INTEGER)");
+    conn.commit();
+
+    final PreparedStatement upsert = conn.prepareStatement(
+            "UPSERT INTO " + tableName + " VALUES (?, ?)");
+    upsert.setString(1, "123n7-app-2-");
+    upsert.setInt(2, 1);
+    upsert.executeUpdate();
+    conn.commit();
+
+    final PreparedStatement select = conn.prepareStatement(
+            "select k from " + tableName + " where k like ?");
+    select.setString(1, "12%");
+    ResultSet rs = select.executeQuery();
+    assertTrue(rs.next());
+    assertEquals("123n7-app-2-", rs.getString(1));
+    assertFalse(rs.next());
+
+    select.setString(1, null);
+    rs = select.executeQuery();
+    assertFalse(rs.next());
+  }
 }


Mime
View raw message