You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2015/12/09 05:15:22 UTC

phoenix git commit: PHOENIX-1949 NPE while inserting NULL in a VARCHAR array using UPSERT stmt (Ram)

Repository: phoenix
Updated Branches:
  refs/heads/master bf0661775 -> c2a1f7445


PHOENIX-1949 NPE while inserting NULL in a VARCHAR array using UPSERT stmt
(Ram)


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

Branch: refs/heads/master
Commit: c2a1f7445f3882464a58d07cb9fd15a914e13d36
Parents: bf06617
Author: ramkrishna <ra...@gmail.com>
Authored: Wed Dec 9 09:43:01 2015 +0530
Committer: ramkrishna <ra...@gmail.com>
Committed: Wed Dec 9 09:45:01 2015 +0530

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/ArrayIT.java     | 27 ++++++++++++++++++++
 .../org/apache/phoenix/schema/types/PChar.java  |  6 ++---
 .../apache/phoenix/schema/types/PVarchar.java   |  6 ++---
 3 files changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2a1f744/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 7400127..846507b 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
@@ -870,6 +870,33 @@ public class ArrayIT extends BaseClientManagedTimeIT {
     }
 
     @Test
+    public void testArrayWithVarCharArray() throws Exception {
+        Connection conn;
+        PreparedStatement stmt;
+        ResultSet rs;
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute("CREATE TABLE t ( k VARCHAR PRIMARY KEY, a VARCHAR ARRAY[])");
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        stmt = conn.prepareStatement("UPSERT INTO t VALUES('a',ARRAY['a',null])");
+        int res = stmt.executeUpdate();
+        assertEquals(1, res);
+        conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        rs = conn.createStatement().executeQuery("SELECT ARRAY_ELEM(a,2) FROM t");
+        assertTrue(rs.next());
+        assertEquals(null, rs.getString(1));
+        conn.close();
+    }
+
+    @Test
     public void testArraySelectSingleArrayElemWithCast() throws Exception {
         Connection conn;
         PreparedStatement stmt;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2a1f744/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
----------------------------------------------------------------------
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 6b26197..4170253 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
@@ -104,12 +104,12 @@ public class PChar extends PDataType<String> {
 
     @Override
     public Object toObject(byte[] bytes, int offset, int length, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-      if (!actualType.isCoercibleTo(this)) { // TODO: have isCoercibleTo that takes bytes, offset?
-        throwConstraintViolationException(actualType,this);
-      }
       if (length == 0) {
         return null;
       }
+      if (!actualType.isCoercibleTo(this)) {
+        throwConstraintViolationException(actualType, this);
+      }
       length = StringUtil.getUnpaddedCharLength(bytes, offset, length, sortOrder);
       if (sortOrder == SortOrder.DESC) {
         bytes = SortOrder.invert(bytes, offset, length);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2a1f744/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 fa3dbad..2575115 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
@@ -59,12 +59,12 @@ public class PVarchar extends PDataType<String> {
   @Override
   public Object toObject(byte[] bytes, int offset, int length, PDataType actualType,
       SortOrder sortOrder, Integer maxLength, Integer scale) {
-    if (!actualType.isCoercibleTo(this)) {
-      throwConstraintViolationException(actualType, this);
-    }
     if (length == 0) {
       return null;
     }
+    if (!actualType.isCoercibleTo(this)) {
+      throwConstraintViolationException(actualType, this);
+    }
     if (sortOrder == SortOrder.DESC) {
       bytes = SortOrder.invert(bytes, offset, length);
       offset = 0;