phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject phoenix git commit: PHOENIX-1949 NPE while inserting NULL in a VARCHAR array using UPSERT stmt (Ram)
Date Wed, 09 Dec 2015 04:22:51 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.6-HBase-1.1 e3f920096 -> 10411c43e


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/10411c43
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/10411c43
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/10411c43

Branch: refs/heads/4.6-HBase-1.1
Commit: 10411c43e3d41241273359c26f9747bc1de45f35
Parents: e3f9200
Author: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Authored: Wed Dec 9 09:43:01 2015 +0530
Committer: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Committed: Wed Dec 9 09:52:27 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/10411c43/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..80396a6 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/10411c43/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/10411c43/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;


Mime
View raw message