This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.14-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.14-HBase-1.3 by this push:
     new d165069  PHOENIX-5173: LIKE and ILIKE statements return empty result 
list for search without wildcard
d165069 is described below

commit d165069d510e46a2850b6a80b03a47da25c23c77
Author: s.kadam <s.ka...@salesforce.com>
AuthorDate: Fri Apr 19 15:53:54 2019 -0700

    PHOENIX-5173: LIKE and ILIKE statements return empty result list for search 
without wildcard
---
 .../apache/phoenix/end2end/LikeExpressionIT.java   | 24 ++++++++++++++++++++++
 .../apache/phoenix/compile/ExpressionCompiler.java |  3 ---
 .../apache/phoenix/compile/WhereOptimizerTest.java |  8 ++++++--
 3 files changed, 30 insertions(+), 5 deletions(-)

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 0b061d5..65d55cc 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
@@ -430,4 +430,28 @@ public class LikeExpressionIT extends 
ParallelStatsDisabledIT {
         rs = select.executeQuery();
         assertFalse(rs.next());
     }
+    //associated to PHOENIX-5173 jira
+    @Test
+    public void testLikeExpressionWithoutWildcards() throws Exception {
+        String table = generateUniqueName();
+        final String createTable = "CREATE TABLE "
+                + table + " (ID BIGINT NOT NULL PRIMARY KEY, USER_NAME 
VARCHAR(255))";
+        final String upsertTable = "UPSERT INTO " + table + " VALUES(1, 'Some 
Name')";
+        String likeSelect = "SELECT * FROM " + table + " WHERE USER_NAME LIKE 
'Some Name'";
+        String iLikeSelect = "SELECT * FROM " + table + " WHERE USER_NAME 
ILIKE 'soMe nAme'";
+
+        try(Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            conn.createStatement().execute(createTable);
+            conn.createStatement().executeUpdate(upsertTable);
+            try(ResultSet rs = 
conn.createStatement().executeQuery(likeSelect)) {
+                assertTrue(rs.next());
+                assertFalse(rs.next());
+            }
+            try(ResultSet rs = 
conn.createStatement().executeQuery(iLikeSelect)) {
+                assertTrue(rs.next());
+                assertFalse(rs.next());
+            }
+        }
+    }
 }
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 9daa744..692eec5 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
@@ -511,9 +511,6 @@ public class ExpressionCompiler extends 
UnsupportedAllParseNodeVisitor<Expressio
             }
             if (index == -1) {
                 String rhsLiteral = LikeExpression.unescapeLike(pattern);
-                if (lhsMaxLength != null && lhsMaxLength != 
rhsLiteral.length()) {
-                    return LiteralExpression.newConstant(false, 
rhs.getDeterminism());
-                }
                 if (node.getLikeType() == LikeType.CASE_SENSITIVE) {
                   CompareOp op = node.isNegate() ? CompareOp.NOT_EQUAL : 
CompareOp.EQUAL;
                   if (pattern.equals(rhsLiteral)) {
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
index e5555d6..56d9933 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
@@ -909,14 +909,18 @@ public class WhereOptimizerTest extends 
BaseConnectionlessQueryTest {
     }
 
     @Test
-    public void testDegenerateLikeNoWildcard() throws SQLException {
+    public void testLikeNoWildcardExpression() throws SQLException {
         String tenantId = "000000000000001";
         String keyPrefix = "002";
         String query = "select * from atable where organization_id LIKE ? and 
entity_id  LIKE '" + keyPrefix + "'";
         List<Object> binds = Arrays.<Object>asList(tenantId);
         StatementContext context = compileStatement(query, binds);
         Scan scan = context.getScan();
-        assertDegenerate(scan);
+        byte[] startRow = ByteUtil.concat(
+                
PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
+        assertArrayEquals(startRow, scan.getStartRow());
+        byte[] stopRow = ByteUtil.nextKey(startRow);
+        assertArrayEquals(stopRow, scan.getStopRow());
     }
 
     @Test

Reply via email to