Return-Path: X-Original-To: apmail-phoenix-commits-archive@minotaur.apache.org Delivered-To: apmail-phoenix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 99EF11871B for ; Fri, 26 Jun 2015 18:04:03 +0000 (UTC) Received: (qmail 34680 invoked by uid 500); 26 Jun 2015 18:04:03 -0000 Delivered-To: apmail-phoenix-commits-archive@phoenix.apache.org Received: (qmail 34640 invoked by uid 500); 26 Jun 2015 18:04:03 -0000 Mailing-List: contact commits-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list commits@phoenix.apache.org Received: (qmail 34631 invoked by uid 99); 26 Jun 2015 18:04:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jun 2015 18:04:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 49DC4DFF6B; Fri, 26 Jun 2015 18:04:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: tdsilva@apache.org To: commits@phoenix.apache.org Message-Id: <311d363b4bb741f58b69794f7321a2fa@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: phoenix git commit: PHOENIX-2073 Two bytes character in LIKE expression is not allowed (Yuhao Bi) Date: Fri, 26 Jun 2015 18:04:03 +0000 (UTC) Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.0 a60436521 -> 99cc28808 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/99cc2880 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/99cc2880 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/99cc2880 Branch: refs/heads/4.x-HBase-1.0 Commit: 99cc288082b1299f9cc3b4af67b3295281ea8d06 Parents: a604365 Author: Yuhao Bi Authored: Thu Jun 25 15:41:06 2015 +0800 Committer: Thomas D'Silva Committed: Fri Jun 26 11:03:42 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/99cc2880/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 b7f04e0..0cbef11 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; @@ -952,7 +953,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/99cc2880/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 adbd9a2..c1787ca 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 binds = Arrays.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";