phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject [31/52] [abbrv] phoenix git commit: PHOENIX-2402 NPE when using UPSERT SELECT with a char array (Julian Jaffe)
Date Fri, 11 Dec 2015 02:44:09 GMT
PHOENIX-2402 NPE when using UPSERT SELECT with a char array (Julian Jaffe)


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

Branch: refs/heads/calcite
Commit: 00ee9415a95668c34e95b43003354fc898f6b4ea
Parents: 49be33e
Author: James Taylor <jtaylor@salesforce.com>
Authored: Tue Dec 1 18:56:35 2015 -0800
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Tue Dec 1 18:56:35 2015 -0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/UpsertSelectIT.java  | 55 ++++++++++++++++++++
 .../phoenix/compile/ProjectionCompiler.java     |  4 +-
 .../phoenix/expression/CoerceExpression.java    |  8 ++-
 3 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/00ee9415/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
index aca1602..689562a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
@@ -1318,6 +1318,61 @@ public class UpsertSelectIT extends BaseClientManagedTimeIT {
         }
     }
     
+    @Test
+    public void testUpsertSelectWithFixedWidthNullByteSizeArray() throws Exception {
+        long ts = nextTimestamp();
+        Properties props = new Properties();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute(
+                "create table t1 (id bigint not null primary key, ca char(3)[])");
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute("upsert into t1 values (1, ARRAY['aaa', 'bbb'])");
+        conn.commit();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 15));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute(
+                "upsert into t1(id, ca) select id, ARRAY['ccc', 'ddd'] from t1 WHERE id =
1");
+        conn.commit();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
+        conn = DriverManager.getConnection(getUrl(), props);
+        ResultSet rs = conn.createStatement().executeQuery("select * from t1");
+
+        assertTrue(rs.next());
+        assertEquals(1, rs.getLong(1));
+        assertEquals("['ccc', 'ddd']", rs.getArray(2).toString());
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 25));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute(
+                "create table t2 (id bigint not null primary key, ba binary(4)[])");
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute("upsert into t2 values (2, ARRAY[1, 27])");
+        conn.commit();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 35));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute(
+                "upsert into t2(id, ba) select id, ARRAY[54, 1024] from t2 WHERE id = 2");
+        conn.commit();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        rs = conn.createStatement().executeQuery("select * from t2");
+
+        assertTrue(rs.next());
+        assertEquals(2, rs.getLong(1));
+        assertEquals("[[128,0,0,54], [128,0,4,0]]", rs.getArray(2).toString());
+    }
+
     private static Connection getConnection(long ts) throws SQLException {
         Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/00ee9415/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
index e477009..7cc2e66 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
@@ -78,12 +78,12 @@ import org.apache.phoenix.schema.PColumnFamily;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;
-import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.RowKeySchema;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.ValueBitSet;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -323,7 +323,7 @@ public class ProjectionCompiler {
                 if (expression.getDataType() != null && !expression.getDataType().isCastableTo(targetType))
{
                     throw new ArgumentTypeMismatchException(targetType, expression.getDataType(),
"column: " + targetColumn);
                 }
-                expression = CoerceExpression.create(expression, targetType);
+                expression = CoerceExpression.create(expression, targetType, targetColumn.getSortOrder(),
targetColumn.getMaxLength());
             }
         }
         return expression;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/00ee9415/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
index fb6a825..c31cb0a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
@@ -50,8 +50,14 @@ public class CoerceExpression extends BaseSingleExpression {
         return new CoerceExpression(expression, toType);
     }
     
+    public static Expression create(Expression expression, PDataType toType, SortOrder toSortOrder,
Integer maxLength) throws SQLException {
+        return create(expression, toType, toSortOrder, maxLength, true);
+    }
+    
     public static Expression create(Expression expression, PDataType toType, SortOrder toSortOrder,
Integer maxLength, boolean rowKeyOrderOptimizable) throws SQLException {
-        if (toType == expression.getDataType() && toSortOrder == expression.getSortOrder())
{
+        if (    toType == expression.getDataType() && 
+                toSortOrder == expression.getSortOrder() && 
+                (maxLength == null || maxLength.equals(expression.getMaxLength()))   ) {
             return expression;
         }
         return new CoerceExpression(expression, toType, toSortOrder, maxLength, rowKeyOrderOptimizable);


Mime
View raw message