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 2014/05/26 07:46:23 UTC

git commit: Phoenix-989-problem setting column type of Array to null (ram)

Repository: incubator-phoenix
Updated Branches:
  refs/heads/4.0 614a693d9 -> d1970d71d


Phoenix-989-problem setting column type of Array to null (ram)


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

Branch: refs/heads/4.0
Commit: d1970d71d94da31c3afa2a21d006f07623e8e854
Parents: 614a693
Author: Ramkrishna <ra...@intel.com>
Authored: Mon May 26 11:15:39 2014 +0530
Committer: Ramkrishna <ra...@intel.com>
Committed: Mon May 26 11:15:39 2014 +0530

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/ArrayIT.java     | 78 ++++++++++++++++++++
 .../apache/phoenix/schema/PArrayDataType.java   |  1 +
 .../org/apache/phoenix/schema/PDataType.java    | 25 ++++++-
 3 files changed, 103 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d1970d71/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 7b13447..bf4be73 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
@@ -34,6 +34,7 @@ import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Types;
 import java.util.Properties;
 
 import org.apache.phoenix.query.BaseTest;
@@ -1209,6 +1210,83 @@ public class ArrayIT extends BaseClientManagedTimeIT {
     }
 
     @Test
+    public void testUpsertValuesWithNull() throws Exception {
+        long ts = nextTimestamp();
+        String tenantId = getOrganizationId();
+        createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+        String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID,a_double_array) values('" + tenantId
+                + "','00A123122312312',null)";
+        Properties props = new Properties(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts)); // Execute
+                                                                                 // at
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            PreparedStatement statement = conn.prepareStatement(query);
+            int executeUpdate = statement.executeUpdate();
+            assertEquals(1, executeUpdate);
+            conn.commit();
+            statement.close();
+            conn.close();
+            // create another connection
+            props = new Properties(TEST_PROPERTIES);
+            props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
+            conn = DriverManager.getConnection(getUrl(), props);
+            query = "SELECT ARRAY_ELEM(a_double_array,2) FROM table_with_array";
+            statement = conn.prepareStatement(query);
+            ResultSet rs = statement.executeQuery();
+            assertTrue(rs.next());
+            // Need to support primitive
+            Double[] doubleArr = new Double[1];
+            doubleArr[0] = 0.0d;
+            conn.createArrayOf("DOUBLE", doubleArr);
+            Double result = rs.getDouble(1);
+            assertEquals(doubleArr[0], result);
+            assertFalse(rs.next());
+        } finally {
+            conn.close();
+        }
+    }
+    
+    @Test
+    public void testUpsertValuesWithNullUsingPreparedStmt() throws Exception {
+        long ts = nextTimestamp();
+        String tenantId = getOrganizationId();
+        createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+        String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID,a_string_array) values(?, ?, ?)";
+        Properties props = new Properties(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts)); // Execute
+                                                                                 // at
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            PreparedStatement statement = conn.prepareStatement(query);
+            statement.setString(1, tenantId);
+            statement.setString(2, "00A123122312312");
+            statement.setNull(3, Types.ARRAY);
+            int executeUpdate = statement.executeUpdate();
+            assertEquals(1, executeUpdate);
+            conn.commit();
+            statement.close();
+            conn.close();
+            // create another connection
+            props = new Properties(TEST_PROPERTIES);
+            props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
+            conn = DriverManager.getConnection(getUrl(), props);
+            query = "SELECT ARRAY_ELEM(a_string_array,1) FROM table_with_array";
+            statement = conn.prepareStatement(query);
+            ResultSet rs = statement.executeQuery();
+            assertTrue(rs.next());
+            String[] strArr = new String[1];
+            strArr[0] = null;
+            conn.createArrayOf("VARCHAR", strArr);
+            String result = rs.getString(1);
+            assertEquals(strArr[0], result);
+            assertFalse(rs.next());
+        } finally {
+            conn.close();
+        }
+    }
+
+    @Test
     public void testPKWithArray() throws Exception {
         Connection conn;
         PreparedStatement stmt;

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d1970d71/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
index 3d1fce8..01b28da 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
@@ -197,6 +197,7 @@ public class PArrayDataType {
 	public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value,
 			PDataType srcType, Integer maxLength, Integer scale,
 			Integer desiredMaxLength, Integer desiredScale) {
+        if (value == null) return true;
 		PhoenixArray pArr = (PhoenixArray) value;
 		Object[] arr = (Object[]) pArr.array;
 		PDataType baseType = PDataType.fromTypeId(srcType.getSqlType()

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d1970d71/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
index ee1e288..d886c39 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
@@ -3293,6 +3293,7 @@ public enum PDataType {
 		
 		@Override
 		public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
 		   PhoenixArray pArr = (PhoenixArray)value;
 		   int[] intArr = (int[])pArr.array;
            for (int i : intArr) {
@@ -3368,7 +3369,7 @@ public enum PDataType {
 		
 		@Override
 		public boolean isCoercibleTo(PDataType targetType, Object value) {
-		   
+           if (value == null) { return true; }
 		   PhoenixArray pArr = (PhoenixArray)value;
 		   boolean[] booleanArr = (boolean[])pArr.array;
            for (boolean i : booleanArr) {
@@ -3451,6 +3452,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] charArr = (Object[])pArr.array;
            for (Object i : charArr) {
@@ -3540,6 +3542,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] charArr = (Object[])pArr.array;
            for (Object i : charArr) {
@@ -3629,6 +3632,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] charArr = (Object[])pArr.array;
            for (Object i : charArr) {
@@ -3719,6 +3723,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] charArr = (Object[])pArr.array;
            for (Object i : charArr) {
@@ -3808,6 +3813,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            long[] longArr = (long[])pArr.array;
            for (long i : longArr) {
@@ -3890,6 +3896,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            short[] shortArr = (short[])pArr.array;
            for (short i : shortArr) {
@@ -3980,6 +3987,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            byte[] byteArr = (byte[])pArr.array;
            for (byte i : byteArr) {
@@ -4055,6 +4063,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            float[] floatArr = (float[])pArr.array;
            for (float i : floatArr) {
@@ -4138,6 +4147,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            double[] doubleArr = (double[])pArr.array;
            for (double i : doubleArr) {
@@ -4229,6 +4239,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] decimalArr = (Object[])pArr.array;
            for (Object i : decimalArr) {
@@ -4312,6 +4323,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] timeStampArr = (Object[])pArr.array;
            for (Object i : timeStampArr) {
@@ -4395,6 +4407,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] timeStampArr = (Object[])pArr.array;
            for (Object i : timeStampArr) {
@@ -4477,6 +4490,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] timeArr = (Object[])pArr.array;
            for (Object i : timeArr) {
@@ -4559,6 +4573,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] timeArr = (Object[])pArr.array;
            for (Object i : timeArr) {
@@ -4641,6 +4656,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; }
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] dateArr = (Object[])pArr.array;
            for (Object i : dateArr) {
@@ -4723,6 +4739,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; } 
            PhoenixArray pArr = (PhoenixArray)value;
            Object[] dateArr = (Object[])pArr.array;
            for (Object i : dateArr) {
@@ -4805,6 +4822,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; } 
            PhoenixArray pArr = (PhoenixArray)value;
            long[] longArr = (long[])pArr.array;
            for (long i : longArr) {
@@ -4887,6 +4905,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; } 
            PhoenixArray pArr = (PhoenixArray)value;
            int[] intArr = (int[])pArr.array;
            for (int i : intArr) {
@@ -4970,6 +4989,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; } 
            PhoenixArray pArr = (PhoenixArray)value;
            short[] shortArr = (short[])pArr.array;
            for (short i : shortArr) {
@@ -5053,6 +5073,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; } 
            PhoenixArray pArr = (PhoenixArray)value;
            byte[] byteArr = (byte[])pArr.array;
            for (byte i : byteArr) {
@@ -5134,6 +5155,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; } 
            PhoenixArray pArr = (PhoenixArray)value;
            float[] floatArr = (float[])pArr.array;
            for (float i : floatArr) {
@@ -5225,6 +5247,7 @@ public enum PDataType {
 		
 		@Override
         public boolean isCoercibleTo(PDataType targetType, Object value) {
+           if (value == null) { return true; } 
            PhoenixArray pArr = (PhoenixArray)value;
            double[] doubleArr = (double[])pArr.array;
            for (double i : doubleArr) {