You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by gj...@apache.org on 2019/04/26 22:14:11 UTC

[phoenix] branch master updated: PHOENIX-5168 IndexScrutinyTool to output to Table when that option is given

This is an automated email from the ASF dual-hosted git repository.

gjacoby pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new ff51c27  PHOENIX-5168 IndexScrutinyTool to output to Table when that option is given
ff51c27 is described below

commit ff51c2766a25f676ef22df3bfdf668f76b5f2d54
Author: Gokcen Iskender <gi...@salesforce.com>
AuthorDate: Wed Apr 24 13:16:34 2019 -0700

    PHOENIX-5168 IndexScrutinyTool to output to Table when that option is given
---
 .../phoenix/end2end/IndexScrutinyToolIT.java       | 38 ++++++++++++++--------
 .../phoenix/mapreduce/index/IndexScrutinyTool.java |  4 ++-
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java
index 046c3f0..72857e7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java
@@ -10,6 +10,7 @@
  */
 package org.apache.phoenix.end2end;
 
+import static org.apache.phoenix.mapreduce.index.IndexScrutinyTableOutput.OUTPUT_TABLE_NAME;
 import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.BAD_COVERED_COL_VAL_COUNT;
 import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.BATCHES_PROCESSED_COUNT;
 import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.INVALID_ROW_COUNT;
@@ -172,6 +173,14 @@ public class IndexScrutinyToolIT {
         protected long getCounterValue(Counters counters, Enum<PhoenixScrutinyJobCounters> counter) {
             return counters.findCounter(counter).getValue();
         }
+
+        protected int countRows(Connection conn, String tableFullName) throws SQLException {
+            ResultSet count = conn.createStatement().executeQuery("select count(*) from " + tableFullName);
+            count.next();
+            int numRows = count.getInt(1);
+            return numRows;
+        }
+
     }
 
     @RunWith(Parameterized.class) public static class IndexScrutinyToolNonTenantIT extends SharedIndexToolIT {
@@ -247,8 +256,8 @@ public class IndexScrutinyToolIT {
             upsertRow(dataTableUpsertStmt, 2, "name-2", 95123);
             conn.commit();
 
-            int numDataRows = countRows(dataTableFullName);
-            int numIndexRows = countRows(indexTableFullName);
+            int numDataRows = countRows(conn, dataTableFullName);
+            int numIndexRows = countRows(conn, indexTableFullName);
 
             // scrutiny should report everything as ok
             List<Job> completedJobs = runScrutiny(schemaName, dataTableName, indexTableName);
@@ -259,8 +268,8 @@ public class IndexScrutinyToolIT {
             assertEquals(0, getCounterValue(counters, INVALID_ROW_COUNT));
 
             // make sure row counts weren't modified by scrutiny
-            assertEquals(numDataRows, countRows(dataTableFullName));
-            assertEquals(numIndexRows, countRows(indexTableFullName));
+            assertEquals(numDataRows, countRows(conn, dataTableFullName));
+            assertEquals(numIndexRows, countRows(conn, indexTableFullName));
         }
 
         /**
@@ -405,7 +414,7 @@ public class IndexScrutinyToolIT {
                 deleteRow(indexTableFullName, "WHERE \":ID\"=" + idToDelete);
             }
             conn.commit();
-            int numRows = countRows(indexTableFullName);
+            int numRows = countRows(conn, indexTableFullName);
             int numDeleted = numTestRows - numRows;
 
             // run scrutiny with batch size of 10
@@ -683,13 +692,6 @@ public class IndexScrutinyToolIT {
             indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
         }
 
-        private int countRows(String tableFullName) throws SQLException {
-            ResultSet count = conn.createStatement().executeQuery("select count(*) from " + tableFullName);
-            count.next();
-            int numRows = count.getInt(1);
-            return numRows;
-        }
-
         private void upsertIndexRow(String name, int id, int zip) throws SQLException {
             indexTableUpsertStmt.setString(1, name);
             indexTableUpsertStmt.setInt(2, id); // id
@@ -898,9 +900,17 @@ public class IndexScrutinyToolIT {
         * Add 3 rows to Tenant view.
         * Empty index table and observe they are not equal.
         * Use data table as source and output to file.
-        * Output to table doesn't work for tenantid connection because it can't create the scrutiny table as tenant.
         **/
         @Test public void testWithEmptyIndexTableOutputToFile() throws Exception{
+            testWithOutput(OutputFormat.FILE);
+        }
+
+        @Test public void testWithEmptyIndexTableOutputToTable() throws Exception{
+            testWithOutput(OutputFormat.TABLE);
+            assertEquals(3, countRows(connGlobal, OUTPUT_TABLE_NAME));
+        }
+
+        private void testWithOutput(OutputFormat outputFormat) throws Exception {
             connTenant.createStatement()
                     .execute(String.format(upsertQueryStr, tenantViewName, tenantId, 1, "x"));
             connTenant.createStatement()
@@ -919,7 +929,7 @@ public class IndexScrutinyToolIT {
 
             String[]
                     argValues =
-                    getArgValues("", tenantViewName, indexNameTenant, 10L, SourceTable.DATA_TABLE_SOURCE, true, OutputFormat.FILE, null,
+                    getArgValues("", tenantViewName, indexNameTenant, 10L, SourceTable.DATA_TABLE_SOURCE, true, outputFormat, null,
                             tenantId, EnvironmentEdgeManager.currentTimeMillis());
             List<Job> completedJobs = runScrutiny(argValues);
 
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java
index 26d7336..39df6ac 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java
@@ -428,7 +428,9 @@ public class IndexScrutinyTool extends Configured implements Tool {
 
             if (outputInvalidRows && OutputFormat.TABLE.equals(outputFormat)) {
                 // create the output table if it doesn't exist
-                try (Connection outputConn = ConnectionUtil.getOutputConnection(configuration)) {
+                Configuration outputConfiguration = HBaseConfiguration.create(configuration);
+                outputConfiguration.unset(PhoenixRuntime.TENANT_ID_ATTRIB);
+                try (Connection outputConn = ConnectionUtil.getOutputConnection(outputConfiguration)) {
                     outputConn.createStatement().execute(IndexScrutinyTableOutput.OUTPUT_TABLE_DDL);
                     outputConn.createStatement()
                             .execute(IndexScrutinyTableOutput.OUTPUT_METADATA_DDL);