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

Josh Mahonin commented on PHOENIX-2210:
---------------------------------------

I literally ran into the same thing this morning. I chalked it up to me using 
unsupported syntax, though it would be nice to get an error instead of a NPE. 

Does it work if you change your upsert select query to the following (note the 
'FROM T'):

{code}
UPSERT INTO T (PK1, PK2, KV1) SELECT PK1, PK2, (KV1 + 100) FROM T WHERE PK1 = 
'PK10' AND PK2 = 'PK20'
{code}



> UPSERT SELECT on the same table fails with NPE
> ----------------------------------------------
>
>                 Key: PHOENIX-2210
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2210
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Samarth Jain
>
> {code}
> @Test
>     public void testUpsertSelectSameRow() throws Exception {
>         try (Connection conn = DriverManager.getConnection(getUrl())) {
>             conn.createStatement().execute("CREATE TABLE T (PK1 VARCHAR NOT 
> NULL, PK2 VARCHAR NOT NULL, KV1 INTEGER CONSTRAINT PK PRIMARY KEY (PK1, 
> PK2))");
>             conn.createStatement().executeUpdate("UPSERT INTO T VALUES 
> ('PK10', 'PK20', 10)");
>             conn.createStatement().executeUpdate("UPSERT INTO T VALUES 
> ('PK11', 'PK21', 20)");
>             conn.createStatement().executeUpdate("UPSERT INTO T VALUES 
> ('PK12', 'PK22', 30)");
>             conn.commit();
>             conn.createStatement().executeUpdate("UPSERT INTO T (PK1, PK2, 
> KV1) SELECT PK1, PK2, (KV1 + 100) WHERE PK1 = 'PK10' AND PK2 = 'PK20' ");
>             conn.commit();
>             ResultSet rs = conn.createStatement().executeQuery("SELECT KV1 
> FROM T WHERE WHERE PK1 = 'PK10' AND PK2 = 'PK20'");
>             assertTrue(rs.next());
>             assertEquals(110, rs.getInt(1));
>         }
>     }
> {code}
> {code}
> Exception:
> java.lang.NullPointerException
>       at org.apache.phoenix.schema.TableRef.equals(TableRef.java:115)
>       at 
> org.apache.phoenix.compile.UpsertCompiler.compile(UpsertCompiler.java:392)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.compilePlan(PhoenixStatement.java:550)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.compilePlan(PhoenixStatement.java:1)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$3.call(PhoenixStatement.java:318)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$3.call(PhoenixStatement.java:1)
>       at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:310)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.executeUpdate(PhoenixStatement.java:1421)
> {code}



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

Reply via email to