You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by pb...@apache.org on 2018/05/09 22:57:02 UTC
[11/13] 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/810ed4e3
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/810ed4e3
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/810ed4e3
Branch: refs/heads/4.x-cdh5.12
Commit: 810ed4e37a24cc281c46ece4ed958e45ab458ba2
Parents: f1230c0
Author: James Taylor <jt...@salesforce.com>
Authored: Wed May 9 13:12:26 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:40 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/810ed4e3/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/810ed4e3/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<String> {
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;
}