Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.3 81f887584 -> ffc380aad
PHOENIX-4728 ARRAY_APPEND and ARRAY_REMOVE should work with null column value (Xavier Jodoin) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/ffc380aa Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ffc380aa Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ffc380aa Branch: refs/heads/4.x-HBase-1.3 Commit: ffc380aad453497020109b855b2668bb026fe5cf Parents: 81f8875 Author: James Taylor <jtay...@salesforce.com> Authored: Fri May 25 09:36:41 2018 -0700 Committer: James Taylor <jtay...@salesforce.com> Committed: Fri May 25 09:36:41 2018 -0700 ---------------------------------------------------------------------- .../phoenix/end2end/ArrayAppendFunctionIT.java | 38 ++++++++++++++++++++ .../apache/phoenix/compile/UpsertCompiler.java | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffc380aa/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java index caa17fe..7962a7a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java @@ -132,6 +132,24 @@ public class ArrayAppendFunctionIT extends ParallelStatsDisabledIT { } @Test + public void testUpsertEmptyArrayModification() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + String tableName = initTables(conn); + + ResultSet rs; + String[] strings = new String[]{"34567"}; + Array array = conn.createArrayOf("VARCHAR", strings); + + conn.createStatement().execute("UPSERT INTO " + tableName + " (region_name,nullVarChar) SELECT region_name,ARRAY_APPEND(nullVarChar,'34567') FROM " + tableName); + conn.commit(); + + rs = conn.createStatement().executeQuery("SELECT nullVarChar FROM " + tableName + " LIMIT 1"); + assertTrue(rs.next()); + assertEquals(array, rs.getArray(1)); + assertFalse(rs.next()); + } + + @Test public void testArrayAppendFunctionVarchar() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); String tableName = initTables(conn); @@ -147,6 +165,26 @@ public class ArrayAppendFunctionIT extends ParallelStatsDisabledIT { assertEquals(array, rs.getArray(1)); assertFalse(rs.next()); } + + @Test + public void testUpsertArrayAppendFunctionVarchar() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + String tableName = initTables(conn); + + conn.createStatement().execute("UPSERT INTO " + tableName + " (region_name,varchars) SELECT region_name,ARRAY_APPEND(varchars,'34567') as varchars FROM " + tableName+ " WHERE region_name = 'SF Bay Area'"); + conn.commit(); + + ResultSet rs; + rs = conn.createStatement().executeQuery("SELECT varchars FROM " + tableName + " WHERE region_name = 'SF Bay Area'"); + assertTrue(rs.next()); + + String[] strings = new String[]{"2345", "46345", "23234", "34567"}; + + Array array = conn.createArrayOf("VARCHAR", strings); + + assertEquals(array, rs.getArray(1)); + assertFalse(rs.next()); + } @Test public void testArrayAppendFunctionInteger() throws Exception { http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffc380aa/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java index 30f0c18..c3cfa10 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java @@ -549,7 +549,7 @@ public class UpsertCompiler { select = SelectStatement.create(select, hint); // Pass scan through if same table in upsert and select so that projection is computed correctly // Use optimizer to choose the best plan - QueryCompiler compiler = new QueryCompiler(statement, select, selectResolver, targetColumns, parallelIteratorFactoryToBe, new SequenceManager(statement), false, false, null); + QueryCompiler compiler = new QueryCompiler(statement, select, selectResolver, targetColumns, parallelIteratorFactoryToBe, new SequenceManager(statement), true, false, null); queryPlanToBe = compiler.compile(); // This is post-fix: if the tableRef is a projected table, this means there are post-processing // steps and parallelIteratorFactory did not take effect.