From commits-return-21117-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Wed May 9 22:26:45 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 847D71807A1 for ; Wed, 9 May 2018 22:26:44 +0200 (CEST) Received: (qmail 3376 invoked by uid 500); 9 May 2018 20:26:43 -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 3289 invoked by uid 99); 9 May 2018 20:26:43 -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; Wed, 09 May 2018 20:26:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E41CFF6CA6; Wed, 9 May 2018 20:26:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamestaylor@apache.org To: commits@phoenix.apache.org Date: Wed, 09 May 2018 20:26:48 -0000 Message-Id: In-Reply-To: <33e907f0068445ad94aa31c6a2791e7b@git.apache.org> References: <33e907f0068445ad94aa31c6a2791e7b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [7/7] phoenix git commit: PHOENIX-4646 The data exceeds the max capacity for the data type error for valid scenarios (Sergey Soldatov) PHOENIX-4646 The data exceeds the max capacity for the data type error for valid scenarios (Sergey Soldatov) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/76635561 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/76635561 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/76635561 Branch: refs/heads/4.x-HBase-1.2 Commit: 766355614e31ba69f5ed2c58f071e40c314d7fa8 Parents: e1e61f5 Author: James Taylor Authored: Wed May 9 13:12:26 2018 -0700 Committer: James Taylor Committed: Wed May 9 13:25:30 2018 -0700 ---------------------------------------------------------------------- .../apache/phoenix/end2end/UpsertSelectIT.java | 19 +++++++++++++++++++ .../apache/phoenix/schema/types/PVarchar.java | 10 ++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/76635561/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java index 99cbe47..5db1fdd 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java @@ -1488,6 +1488,25 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT { } } + @Test // See https://issues.apache.org/jira/browse/PHOENIX-4646 + public void testLengthLimitedVarchar() throws Exception { + String tableName1 = generateUniqueName(); + String tableName2 = generateUniqueName(); + try (Connection conn = DriverManager.getConnection(getUrl())) { + conn.setAutoCommit(true); + conn.createStatement().execute("create table " + tableName1 + "(name varchar(160) primary key, id varchar(120), address varchar(160))"); + conn.createStatement().execute("create table " + tableName2 + "(name varchar(160) primary key, id varchar(10), address varchar(10))"); + conn.createStatement().execute("upsert into " + tableName1 + " values('test','test','test')"); + conn.createStatement().execute("upsert into " + tableName2 + " select * from " + tableName1); + ResultSet rs = conn.createStatement().executeQuery("select * from " + tableName2); + assertTrue(rs.next()); + assertEquals("test", rs.getString(1)); + assertEquals("test", rs.getString(2)); + assertEquals("test", rs.getString(2)); + assertFalse(rs.next()); + } + } + private static Connection getTenantConnection(String tenantId) throws Exception { Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); props.setProperty(TENANT_ID_ATTRIB, tenantId); http://git-wip-us.apache.org/repos/asf/phoenix/blob/76635561/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java index fb5a045..a99925c 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java @@ -102,15 +102,17 @@ public class PVarchar extends PDataType { SortOrder sortOrder, Integer maxLength, Integer scale, Integer desiredMaxLength, Integer desiredScale) { if (ptr.getLength() != 0 && desiredMaxLength != null) { - if (maxLength == null) { + if (maxLength == null || maxLength > desiredMaxLength) { if (value != null) { // Use value if provided maxLength = value.toString().length(); } else { - coerceBytes(ptr, value, srcType, maxLength, scale, sortOrder, desiredMaxLength, desiredScale, sortOrder, true); - maxLength = StringUtil.calculateUTF8Length(ptr.get(), ptr.getOffset(), ptr.getLength(), sortOrder); + coerceBytes(ptr, value, srcType, maxLength, scale, sortOrder, desiredMaxLength, + desiredScale, sortOrder, true); + maxLength = StringUtil + .calculateUTF8Length(ptr.get(), ptr.getOffset(), ptr.getLength(), sortOrder); } + return maxLength <= desiredMaxLength; } - return maxLength <= desiredMaxLength; } return true; }