Repository: phoenix
Updated Branches:
  refs/heads/master d2575288d -> 1666e932d


PHOENIX-3832 Local Index - Empty resultset for multi-tenant tables


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

Branch: refs/heads/master
Commit: 1666e932d157be732946e02b474b6c342199bc0f
Parents: d257528
Author: James Taylor <jamestay...@apache.org>
Authored: Tue May 16 17:53:25 2017 -0700
Committer: James Taylor <jamestay...@apache.org>
Committed: Tue May 16 17:53:25 2017 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/index/LocalIndexIT.java     | 30 ++++++++++++++++++++
 .../apache/phoenix/index/IndexMaintainer.java   |  3 ++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1666e932/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index ea4780b..32254b0 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -682,4 +682,34 @@ public class LocalIndexIT extends BaseLocalIndexIT {
     }
 
 
+    @Test
+    public void testLocalIndexForMultiTenantTable() throws Exception {
+        String tableName = schemaName + "." + generateUniqueName();
+        String indexName = "IDX_" + generateUniqueName();
+
+        Connection conn1 = getConnection();
+        try{
+            if (isNamespaceMapped) {
+                conn1.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " 
+ schemaName);
+            }
+            String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT 
NULL,\n" +
+                    "k1 INTEGER NOT NULL,\n" +
+                    "v1 VARCHAR,\n" +
+                    "v2 VARCHAR,\n" +
+                    "CONSTRAINT pk PRIMARY KEY (t_id, k1)) MULTI_TENANT=true";
+            conn1.createStatement().execute(ddl);
+            conn1.createStatement().execute("UPSERT INTO " + tableName + " 
values('b',1,'x','y')");
+            conn1.commit();
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName 
+ " ON " + tableName + "(v1)");
+            
+            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM 
" + tableName + " WHERE v1 = 'x'");
+            assertTrue(rs.next());
+            assertEquals("b", rs.getString("T_ID"));
+            assertEquals("y", rs.getString("V2"));
+            assertFalse(rs.next());
+       } finally {
+            conn1.close();
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1666e932/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index 26c2421..dd46345 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -692,6 +692,9 @@ public class IndexMaintainer implements Writable, 
Iterable<ColumnReference> {
                 dataPosOffset++;
                 output.write(0); // will be set at end to salt byte
             }
+            if (viewIndexId != null) {
+                indexRowKeySchema.next(ptr, indexPosOffset++, maxRowKeyOffset);
+            }
             if (isMultiTenant) {
                 indexRowKeySchema.next(ptr, indexPosOffset, maxRowKeyOffset);
                 output.write(ptr.get(), ptr.getOffset(), ptr.getLength());

Reply via email to