phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject phoenix git commit: PHOENIX-2641 Implicit wildcard in LIKE predicate search pattern
Date Tue, 06 Sep 2016 18:25:16 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.8-HBase-1.2 dad0aafe7 -> 966fa83f5


PHOENIX-2641 Implicit wildcard in LIKE predicate search pattern

This closes #200


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

Branch: refs/heads/4.8-HBase-1.2
Commit: 966fa83f5db3ce1de68d3819a7c33f4d20b0c22f
Parents: dad0aaf
Author: kliewkliew <kliewkliew@users.noreply.github.com>
Authored: Wed Aug 24 06:40:35 2016 -0700
Committer: Thomas D'Silva <tdsilva@salesforce.com>
Committed: Tue Sep 6 11:23:48 2016 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/LikeExpressionIT.java       | 23 ++++++++++++++++++++
 .../phoenix/compile/ExpressionCompiler.java     | 10 +++++++--
 .../phoenix/expression/LikeExpressionTest.java  |  6 +++++
 3 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/966fa83f/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 6bfa358..f97e1d7 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
@@ -182,4 +182,27 @@ public class LikeExpressionIT extends BaseHBaseManagedTimeTableReuseIT
{
                 "SELECT * FROM " + t + " WHERE k like 'AA_'");
         assertFalse(rs.next());
     }
+
+    @Test
+    public void testOneChar() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String t = generateRandomString();
+        String ddl = "CREATE TABLE " + t + " (k VARCHAR NOT NULL PRIMARY KEY)";
+        conn.createStatement().execute(ddl);
+        conn.createStatement().execute("UPSERT INTO " + t + " VALUES('A')");
+        conn.createStatement().execute("UPSERT INTO " + t + " VALUES('AA')");
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT * FROM " + t + " WHERE k like '_'");
+        assertTrue(rs.next());
+        assertEquals("A", rs.getString(1));
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery(
+                "SELECT * FROM " + t + " WHERE k like '_A'");
+        assertTrue(rs.next());
+        assertEquals("AA", rs.getString(1));
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/966fa83f/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 0fd1876..aaab763 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
@@ -136,6 +136,7 @@ import org.apache.phoenix.schema.types.PhoenixArray;
 import org.apache.phoenix.util.ExpressionUtil;
 import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.StringUtil;
 
 
 public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expression>
{
@@ -517,8 +518,13 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                       return new ComparisonExpression(Arrays.asList(lhs,rhs), op);
                   }
                 }
-            } else if (index == 0 && pattern.length() == 1) {
-                return IsNullExpression.create(lhs, true, context.getTempPtr());
+            } else {
+                byte[] nullExpressionString = new byte[pattern.length()];
+                byte[] wildcard = {StringUtil.MULTI_CHAR_LIKE};
+                StringUtil.fill(nullExpressionString, 0, pattern.length(), wildcard, 0, 1,
false);
+                if (pattern.equals(new String (nullExpressionString))) {
+                    return IsNullExpression.create(lhs, true, context.getTempPtr());
+                }
             }
         }
         QueryServices services = context.getConnection().getQueryServices();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/966fa83f/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
index 580ac8e..2e33e7b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
@@ -77,6 +77,12 @@ public class LikeExpressionTest {
     }
 
     @Test
+    public void testOneChar() throws Exception {
+        assertEquals(Boolean.TRUE, testExpression ("A", "_"));
+        assertEquals(Boolean.FALSE, testExpression ("AA", "_"));
+    }
+
+    @Test
     public void testEmptySourceStr() throws Exception {
         assertEquals(Boolean.TRUE, testExpression ("", "%"));
         assertEquals(Boolean.FALSE, testExpression ("", "_"));


Mime
View raw message