[ 
https://issues.apache.org/jira/browse/PHOENIX-2301?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14989159#comment-14989159
 ] 

James Taylor commented on PHOENIX-2301:
---------------------------------------

Thanks, [~Dumindux]. So byteValue is null then? Also, what happens if one of 
the array element values is less than the max length, like this?
{code}
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts 
+ 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO TEST5 
VALUES (ARRAY['aa', 'bb', 'cc'])");
+        stmt.execute();
{code}
And also the reverse - if one of the array elements values is bigger than the 
max length? Do we get an exception?

These would be good to add tests for if we don't have them yet.

> NullPointerException when upserting into a char array column
> ------------------------------------------------------------
>
>                 Key: PHOENIX-2301
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2301
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.5.2
>            Reporter: Julian Jaffe
>            Assignee: Dumindu Buddhika
>         Attachments: PHOENIX-2301.patch
>
>
> Attempting to upsert into a char array causes an NPE. Minimum example:
> {code:sql}
> 0: jdbc:phoenix:xxxxxx> CREATE TABLE IF NOT EXISTS TEST("testIntArray" 
> INTEGER[], CONSTRAINT "test_pk" PRIMARY KEY("testIntArray")) 
> DEFAULT_COLUMN_FAMILY='T';
> No rows affected (1.28 seconds)
> 0: jdbc:phoenix:xxxxxx> UPSERT INTO TEST VALUES (ARRAY[1, 2, 3]);
> 1 row affected (0.184 seconds)
> 0: jdbc:phoenix:xxxxxx> SELECT * FROM TEST;
> +------------------------------------------+
> |               testIntArray               |
> +------------------------------------------+
> | [1, 2, 3]                                |
> +------------------------------------------+
> 1 row selected (0.308 seconds)
> 0: jdbc:phoenix:xxxxxx> DROP TABLE IF EXISTS TEST;
> No rows affected (3.348 seconds)
> 0: jdbc:phoenix:xxxxxx> CREATE TABLE IF NOT EXISTS TEST("testCharArray" 
> CHAR(3)[], CONSTRAINT "test_pk" PRIMARY KEY("testCharArray")) 
> DEFAULT_COLUMN_FAMILY='T';
> No rows affected (1.446 seconds)
> 0: jdbc:phoenix:xxxxxx> UPSERT INTO TEST VALUES (ARRAY['aaa', 'bbb', 'ccc']);
> java.lang.NullPointerException
>       at 
> org.apache.phoenix.schema.types.PArrayDataType.createPhoenixArray(PArrayDataType.java:1123)
>       at 
> org.apache.phoenix.schema.types.PArrayDataType.toObject(PArrayDataType.java:338)
>       at 
> org.apache.phoenix.schema.types.PCharArray.toObject(PCharArray.java:64)
>       at 
> org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:967)
>       at 
> org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:1008)
>       at 
> org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:1004)
>       at org.apache.phoenix.util.SchemaUtil.toString(SchemaUtil.java:381)
>       at org.apache.phoenix.schema.PTableImpl.newKey(PTableImpl.java:572)
>       at 
> org.apache.phoenix.compile.UpsertCompiler.setValues(UpsertCompiler.java:117)
>       at 
> org.apache.phoenix.compile.UpsertCompiler.access$400(UpsertCompiler.java:98)
>       at 
> org.apache.phoenix.compile.UpsertCompiler$3.execute(UpsertCompiler.java:821)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:319)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:311)
>       at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:309)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1432)
>       at sqlline.Commands.execute(Commands.java:822)
>       at sqlline.Commands.sql(Commands.java:732)
>       at sqlline.SqlLine.dispatch(SqlLine.java:808)
>       at sqlline.SqlLine.begin(SqlLine.java:681)
>       at sqlline.SqlLine.start(SqlLine.java:398)
>       at sqlline.SqlLine.main(SqlLine.java:292)
> 0: jdbc:phoenix:xxxxxx> SELECT * FROM TEST;
> +---------------+
> | testCharArray |
> +---------------+
> +---------------+
> No rows selected (0.169 seconds)
> 0: jdbc:phoenix:xxxxxx> SELECT "testCharArray" FROM TEST;
> +---------------+
> | testCharArray |
> +---------------+
> +---------------+
> No rows selected (0.182 seconds)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to