From issues-return-4371-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Fri Feb 1 18:00:29 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id DE8B8180627 for ; Fri, 1 Feb 2019 19:00:28 +0100 (CET) Received: (qmail 97887 invoked by uid 500); 1 Feb 2019 18:00:28 -0000 Mailing-List: contact issues-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list issues@phoenix.apache.org Received: (qmail 97878 invoked by uid 99); 1 Feb 2019 18:00:28 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Feb 2019 18:00:28 +0000 From: GitBox To: issues@phoenix.apache.org Subject: [GitHub] gjacoby126 commented on a change in pull request #435: PHOENIX-4940 Add tenantId parameter to index tool Message-ID: <154904402749.26163.1817092559211990390.gitbox@gitbox.apache.org> Date: Fri, 01 Feb 2019 18:00:27 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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: users@infra.apache.org With regards, Apache Git Services