PHOENIX-3800 NPE when doing UPSERT SELECT into salted tables

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

Branch: refs/heads/omid
Commit: f51c0db9f2d2ee261e602a114d47dd63353bbba8
Parents: 5b09901
Author: Ankit Singhal <[email protected]>
Authored: Fri May 5 11:38:44 2017 +0530
Committer: Ankit Singhal <[email protected]>
Committed: Fri May 5 11:38:44 2017 +0530

----------------------------------------------------------------------
 .../apache/phoenix/end2end/UpsertSelectIT.java  | 21 +++++++++++++++-----
 .../apache/phoenix/compile/UpsertCompiler.java  |  2 +-
 2 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f51c0db9/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 0a20d47..1c04acb 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
@@ -78,20 +78,31 @@ public class UpsertSelectIT extends BaseClientManagedTimeIT 
{
     
     @Test
     public void testUpsertSelectWithNoIndex() throws Exception {
-        testUpsertSelect(false);
+        testUpsertSelect(false, false);
     }
     
     @Test
     public void testUpsertSelecWithIndex() throws Exception {
-        testUpsertSelect(true);
+        testUpsertSelect(true, false);
     }
     
-    private void testUpsertSelect(boolean createIndex) throws Exception {
+    @Test
+    public void testUpsertSelecWithIndexWithSalt() throws Exception {
+        testUpsertSelect(true, true);
+    }
+
+    @Test
+    public void testUpsertSelecWithNoIndexWithSalt() throws Exception {
+        testUpsertSelect(false, true);
+    }
+
+    private void testUpsertSelect(boolean createIndex, boolean saltTable) 
throws Exception {
         long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), 
null, ts-1, getUrl(), null);
+        byte[][] splits = getDefaultSplits(tenantId);
+        initATableValues(ATABLE_NAME, tenantId, saltTable ? null : splits, 
null, ts-1, getUrl(), saltTable ? "salt_buckets = 2" : null);
 
-        ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, 
CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
+        ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, 
CUSTOM_ENTITY_DATA_FULL_NAME, null, ts-1, saltTable ? "salt_buckets = 2" : 
null);
         String indexName = "IDX1";
         if (createIndex) {
             Properties props = new Properties();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f51c0db9/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 2304d83..5559ad7 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
@@ -677,7 +677,7 @@ public class UpsertCompiler {
                     for (int i = 0 ; i < projectedExpressions.size(); i++) {
                         // Must make new column if position has changed
                         PColumn column = allColumns.get(allColumnsIndexes[i]);
-                        projectedColumns.add(column.getPosition() == i + 
posOff ? column : new PColumnImpl(column, i));
+                        projectedColumns.add(column.getPosition() == i + 
posOff ? column : new PColumnImpl(column, i + posOff));
                     }
                     // Build table from projectedColumns
                     // Hack to add default column family to be used on server 
in case no value column is projected.

Reply via email to