This is an automated email from the ASF dual-hosted git repository. pboado pushed a commit to branch 5.x-cdh6 in repository https://gitbox.apache.org/repos/asf/phoenix.git
commit cbca95d870abe1e831f343263bcf750be330198f Author: s.kadam <s.ka...@salesforce.com> AuthorDate: Fri Apr 19 23:53:54 2019 +0100 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 3b0f6d7..807c2e2 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 @@ -507,9 +507,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 cc6f55a..f2d5cfe 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 @@ -921,14 +921,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