PHOENIX-2073 Two bytes character in LIKE expression is not allowed (Yuhao Bi)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c40d64b3 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c40d64b3 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c40d64b3 Branch: refs/heads/4.x-HBase-1.1 Commit: c40d64b3bbc793ec920a8a8032c7a93bd015380a Parents: 980d29c Author: Yuhao Bi <byh0...@gmail.com> Authored: Thu Jun 25 15:41:06 2015 +0800 Committer: Thomas D'Silva <tdsi...@salesforce.com> Committed: Fri Jun 26 11:04:34 2015 -0700 ---------------------------------------------------------------------- .../apache/phoenix/compile/WhereOptimizer.java | 3 ++- .../phoenix/compile/WhereOptimizerTest.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/c40d64b3/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java index a5aef02..32de712 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java @@ -65,6 +65,7 @@ import org.apache.phoenix.schema.tuple.Tuple; import org.apache.phoenix.schema.types.PChar; import org.apache.phoenix.schema.types.PDataType; import org.apache.phoenix.schema.types.PVarbinary; +import org.apache.phoenix.schema.types.PVarchar; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.MetaDataUtil; import org.apache.phoenix.util.ScanUtil; @@ -945,7 +946,7 @@ public class WhereOptimizer { KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.iterator().next(); final String startsWith = node.getLiteralPrefix(); - byte[] key = PChar.INSTANCE.toBytes(startsWith, node.getChildren().get(0).getSortOrder()); + byte[] key = PVarchar.INSTANCE.toBytes(startsWith, node.getChildren().get(0).getSortOrder()); // If the expression is an equality expression against a fixed length column // and the key length doesn't match the column length, the expression can // never be true. http://git-wip-us.apache.org/repos/asf/phoenix/blob/c40d64b3/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java ---------------------------------------------------------------------- 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 f40afc3..2d4763f 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 @@ -688,6 +688,24 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest { } @Test + public void testLikeExtractAllKeyExpression2() throws SQLException { + String tenantId = "000000000000001"; + String keyPrefix = "ä¸æ"; + String query = "select * from atable where organization_id = ? and entity_id LIKE '" + keyPrefix + "%'"; + List<Object> binds = Arrays.<Object>asList(tenantId); + StatementContext context = compileStatement(query, binds); + Scan scan = context.getScan(); + + assertNull(scan.getFilter()); + byte[] startRow = ByteUtil.concat( + PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15)); + assertArrayEquals(startRow, scan.getStartRow()); + byte[] stopRow = ByteUtil.concat( + PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15)); + assertArrayEquals(stopRow, scan.getStopRow()); + } + + @Test public void testLikeExtractAllAsEqKeyExpression() throws SQLException { String tenantId = "000000000000001"; String keyPrefix = "002";