gjacoby126 commented on a change in pull request #435: PHOENIX-4940 Add 
tenantId parameter to index tool
URL: https://github.com/apache/phoenix/pull/435#discussion_r253138277
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -228,6 +229,89 @@ public void testSecondaryIndex() throws Exception {
         }
     }
 
+    @Test
+    public void testIndexToolWithTenantId() throws Exception {
+        if (!useTenantId) { return;}
+        String tenantId = "TENANT1";
+        String schemaName = "SCHEMA1";
+        String dataTableName = "DTABLE1";
+        String viewTenantName = "VIEWTENANT1";
+        String indexNameGlobal = "INDEX1";
+        String indexNameTenant = "INDEXTENANT1";
+        String viewIndexTableName = "_IDX_DTABLE1";
+
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection connGlobal = DriverManager.getConnection(getUrl(), props);
+        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        Connection connTenant = DriverManager.getConnection(getUrl(), props);
+        String createTableStr = "CREATE TABLE %s (TENANT_ID VARCHAR(15) NOT 
NULL, ID INTEGER NOT NULL, NAME VARCHAR, "
+                + "CONSTRAINT PK_1 PRIMARY KEY (TENANT_ID, ID)) 
MULTI_TENANT=true";
+        String createViewStr = "CREATE VIEW %s AS SELECT * FROM %s";
+
+        String upsertQueryStr = "UPSERT INTO %s (TENANT_ID, ID, NAME) 
VALUES('%s' , %d, '%s')";
+        String createIndexStr = "CREATE INDEX %s ON %s (NAME) ";
+
+        try {
+            String tableStmtGlobal = String.format(createTableStr, 
dataTableName);
+            connGlobal.createStatement().execute(tableStmtGlobal);
+
+            String viewStmtTenant = String.format(createViewStr, 
viewTenantName, dataTableName);
+            connTenant.createStatement().execute(viewStmtTenant);
+
+            String idxStmtTenant = String.format(createIndexStr, 
indexNameTenant, viewTenantName);
+            connTenant.createStatement().execute(idxStmtTenant);
+
+            connTenant.createStatement()
+                    .execute(String.format(upsertQueryStr, viewTenantName, 
tenantId, 1, "x"));
+            connTenant.commit();
+
+            runIndexTool(true, false, "", viewTenantName, indexNameTenant, 
tenantId, 0,
+                    new String[0]);
+
+            String selectSql = String.format("SELECT ID FROM %s WHERE 
NAME='x'", viewTenantName);
+            ResultSet rs = connTenant.createStatement().executeQuery("EXPLAIN 
" + selectSql);
+            String actualExplainPlan = QueryUtil.getExplainPlan(rs);
+            assertExplainPlan(false, actualExplainPlan, "", 
viewIndexTableName);
+            rs = connTenant.createStatement().executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals(1, rs.getInt(1));
+            assertFalse(rs.next());
+
+            // Remove from tenant view index and build.
+            ConnectionQueryServices queryServices = 
connGlobal.unwrap(PhoenixConnection.class).getQueryServices();
+            Admin admin = queryServices.getAdmin();
+            TableName tableName = TableName.valueOf(viewIndexTableName);
+            admin.disableTable(tableName);
+            admin.truncateTable(tableName, false);
+
+            runIndexTool(true, false, "", viewTenantName, indexNameTenant, 
tenantId, 0,
+                    new String[0]);
+            Table htable= 
queryServices.getTable(Bytes.toBytes(viewIndexTableName));
+            ResultScanner scanner = htable.getScanner(new Scan());
 
 Review comment:
   Can compress this down to a call to getUtility().countRows(Table) if you 
still want the HBase level check

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to