You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ya...@apache.org on 2021/02/23 01:03:01 UTC

[phoenix] branch 4.x updated: PHOENIX-6396 PChar illegal data exception should not contain value

This is an automated email from the ASF dual-hosted git repository.

yanxinyi pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x by this push:
     new 14ce2ae  PHOENIX-6396 PChar illegal data exception should not contain value
14ce2ae is described below

commit 14ce2aeae1801d78758e5f47d6ffa962904bf907
Author: Xinyi Yan <ya...@apache.org>
AuthorDate: Mon Feb 22 17:02:53 2021 -0800

    PHOENIX-6396 PChar illegal data exception should not contain value
---
 .../src/main/java/org/apache/phoenix/schema/types/PChar.java   | 10 +++++-----
 .../java/org/apache/phoenix/compile/QueryCompilerTest.java     |  4 +++-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
index 017e813..f6d9a10 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
@@ -85,7 +85,7 @@ public class PChar extends PDataType<String> {
       }
       byte[] b = PVarchar.INSTANCE.toBytes(object);
       if (b.length != ((String) object).length()) {
-        throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
+        throw newIllegalDataException("CHAR types may only contain single byte characters.");
       }
       return b;
     }
@@ -97,7 +97,7 @@ public class PChar extends PDataType<String> {
       }
       int len = PVarchar.INSTANCE.toBytes(object, bytes, offset);
       if (len != ((String) object).length()) {
-        throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
+        throw newIllegalDataException("CHAR types may only contain single byte characters.");
       }
       return len;
     }
@@ -118,7 +118,7 @@ public class PChar extends PDataType<String> {
       // TODO: UTF-8 decoder that will invert as it decodes
       String s = Bytes.toString(bytes, offset, length);
       if (length != s.length()) {
-        throw newIllegalDataException("CHAR types may only contain single byte characters (" + s + ")");
+        throw newIllegalDataException("CHAR types may only contain single byte characters.");
       }
       return s;
     }
@@ -142,7 +142,7 @@ public class PChar extends PDataType<String> {
         Integer actualMaxLength, Integer actualScale, SortOrder actualModifier,
         Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
       if (o != null && actualType.equals(PVarchar.INSTANCE) && ((String)o).length() != ptr.getLength()) {
-        throw newIllegalDataException("CHAR types may only contain single byte characters (" + o + ")");
+        throw newIllegalDataException("CHAR types may only contain single byte characters.");
       }
       super.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
       if (ptr.getLength() > 0 && desiredMaxLength != null &&
@@ -201,7 +201,7 @@ public class PChar extends PDataType<String> {
     @Override
     public Object toObject(String value) {
       if (StringUtil.hasMultiByteChars(value)) {
-        throw newIllegalDataException("CHAR types may only contain single byte characters (" + value + ")");
+        throw newIllegalDataException("CHAR types may only contain single byte characters.");
       }
       return value;
     }
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index ac32956..7a450a8 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -631,6 +631,7 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest {
 
     @Test
     public void testUpsertMultiByteIntoChar() throws Exception {
+        String value = "繰り返し曜日マスク";
         try {
             // Select non agg column in aggregate query
             String query = "upsert into ATABLE VALUES (?, ?, ?)";
@@ -639,7 +640,7 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest {
             try {
                 PreparedStatement statement = conn.prepareStatement(query);
                 statement.setString(1, "00D300000000XHP");
-                statement.setString(2, "繰り返し曜日マスク");
+                statement.setString(2, value);
                 statement.setInt(3, 1);
                 statement.executeUpdate();
                 fail();
@@ -649,6 +650,7 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest {
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 201 (22000): Illegal data."));
             assertTrue(e.getMessage().contains("CHAR types may only contain single byte characters"));
+            assertFalse(e.getMessage().contains(value));
         }
     }