phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [06/22] phoenix git commit: PHOENIX-4646 The data exceeds the max capacity for the data type error for valid scenarios (Sergey Soldatov)
Date Tue, 22 May 2018 20:39:49 GMT
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/cc0de5d2
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cc0de5d2
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cc0de5d2

Branch: refs/heads/omid2
Commit: cc0de5d274e56205051dc5968281f5152e035ab2
Parents: 7c20fda
Author: James Taylor <jtaylor@salesforce.com>
Authored: Wed May 9 13:12:26 2018 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Wed May 9 13:37:10 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/cc0de5d2/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 275d72d..e6feea6 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
@@ -1486,6 +1486,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/cc0de5d2/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;
     }


Mime
View raw message