phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dumin...@apache.org
Subject phoenix git commit: PHOENIX-2301 NullPointerException when upserting into a char array column
Date Sun, 15 Nov 2015 14:18:33 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 fa17fc42f -> b5940dbf2


PHOENIX-2301 NullPointerException when upserting into a char array column


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b5940dbf
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b5940dbf
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b5940dbf

Branch: refs/heads/4.x-HBase-1.0
Commit: b5940dbf2d0fc7072065901fb17c46139f2cd11d
Parents: fa17fc4
Author: Dumindu Buddhika <duminduk@apache.org>
Authored: Sun Nov 15 19:43:59 2015 +0530
Committer: Dumindu Buddhika <duminduk@apache.org>
Committed: Sun Nov 15 19:43:59 2015 +0530

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/ArrayIT.java     | 26 ++++++++++++++++++++
 .../org/apache/phoenix/schema/PTableImpl.java   |  2 +-
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b5940dbf/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
index b7a2ad2..7400127 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
@@ -2679,4 +2679,30 @@ public class ArrayIT extends BaseClientManagedTimeIT {
         assertEquals(conn.createArrayOf("INTEGER", new Integer[]{5, 6}), rs.getArray(4));
         assertEquals(3, rs.getInt(5));
     }
+
+    @Test
+    public void testCharPrimaryKey() throws SQLException{
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        String ddl = "CREATE TABLE TEST5(testCharArray CHAR(3)[], CONSTRAINT test_pk PRIMARY
KEY(testCharArray)) DEFAULT_COLUMN_FAMILY='T'";
+        conn.createStatement().execute(ddl);
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO TEST5 VALUES (ARRAY['aaa',
'bbb', 'ccc'])");
+        stmt.execute();
+        conn.commit();
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        ResultSet rs;
+        stmt = conn.prepareStatement("SELECT testCharArray from TEST5");
+        rs = stmt.executeQuery();
+        assertTrue(rs.next());
+        assertEquals(conn.createArrayOf("CHAR", new String[]{"aaa", "bbb", "ccc"}), rs.getArray(1));
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b5940dbf/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
index b591281..ff4b512 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
@@ -579,7 +579,7 @@ public class PTableImpl implements PTable {
                         // once we require tables to have been upgraded
                         byteValue = StringUtil.padChar(byteValue, maxLength);
                     }
-                } else if (maxLength != null && byteValue.length > maxLength)
{
+                } else if (maxLength != null && !type.isArrayType() && byteValue.length
> maxLength) {
                     throw new DataExceedsCapacityException(name.getString() + "." + column.getName().getString()
+ " may not exceed " + maxLength + " bytes (" + SchemaUtil.toString(type, byteValue) + ")");
                 }
                 os.write(byteValue, 0, byteValue.length);


Mime
View raw message