You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sk...@apache.org on 2020/01/08 18:35:07 UTC

[phoenix] branch 4.14-HBase-1.4 updated: PHOENIX-5650: IndexUpgradeTool does not rebuild view indexes

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

skadam pushed a commit to branch 4.14-HBase-1.4
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.14-HBase-1.4 by this push:
     new a0894e1  PHOENIX-5650: IndexUpgradeTool does not rebuild view indexes
a0894e1 is described below

commit a0894e18f1bcb259879b3e076733454b8a1c9a03
Author: s.kadam <s....@apache.org>
AuthorDate: Tue Jan 7 09:48:15 2020 -0800

    PHOENIX-5650: IndexUpgradeTool does not rebuild view indexes
---
 .../end2end/ParameterizedIndexUpgradeToolIT.java   | 38 +++++++++++++++++++-
 .../phoenix/mapreduce/index/IndexUpgradeTool.java  | 41 ++++++++++++++--------
 2 files changed, 63 insertions(+), 16 deletions(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java
index 652ca55..18f0894 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java
@@ -32,6 +32,7 @@ import org.apache.phoenix.mapreduce.index.IndexUpgradeTool;
 import org.apache.phoenix.query.BaseTest;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
@@ -52,13 +53,17 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.UUID;
 
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LINK_TYPE;
 import static org.apache.phoenix.mapreduce.index.IndexUpgradeTool.ROLLBACK_OP;
 import static org.apache.phoenix.mapreduce.index.IndexUpgradeTool.UPGRADE_OP;
 import static org.apache.phoenix.query.QueryServices.DROP_METADATA_ATTRIB;
@@ -86,6 +91,9 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest {
     private static Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1),
             clientProps = Maps.newHashMapWithExpectedSize(1);
 
+    public static final String
+            VERIFY_COUNT_ASSERT_MESSAGE = "view-index count in system table doesn't match";
+    
     private final boolean mutable;
     private final boolean upgrade;
     private final boolean isNamespaceEnabled;
@@ -168,7 +176,7 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest {
         conn.createStatement().execute(createTblStr);
         conn.createStatement().execute("CREATE TABLE TRANSACTIONAL_TABLE(id bigint NOT NULL "
                         + "PRIMARY KEY, a.name varchar, sal bigint, address varchar) "
-                + " TRANSACTIONAL=true "//", TRANSACTION_PROVIDER='TEPHRA' "
+                + " TRANSACTIONAL=true "
                 + ((tableDDLOptions.trim().length() > 0) ? "," : "") + tableDDLOptions);
 
         //views
@@ -350,6 +358,34 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest {
         validate(true);
     }
 
+    @Test
+    public void verifyViewAndViewIndexes() throws SQLException {
+        String tableName = "MOCK1";
+        String schemaName = "TEST";
+        String viewQuery = iut.getViewSql(tableName, schemaName);
+        ResultSet rs = conn.createStatement().executeQuery(viewQuery);
+        int countViews = 0;
+        List<String> views = new ArrayList<>();
+        List<Integer> indexCount = new ArrayList<>();
+        while (rs.next()) {
+            views.add(rs.getString(1));
+            countViews++;
+        }
+        Assert.assertEquals("view count in system table doesn't match", 2, countViews);
+        for (int i=0; i < views.size(); i++) {
+            String viewName = SchemaUtil.getTableNameFromFullName(views.get(i));
+            String viewIndexQuery = iut.getViewIndexesSql(viewName, schemaName, null);
+            rs = conn.createStatement().executeQuery(viewIndexQuery);
+            int indexes = 0;
+            while (rs.next()) {
+                indexes++;
+            }
+            indexCount.add(indexes);
+        }
+        Assert.assertEquals(VERIFY_COUNT_ASSERT_MESSAGE, 1, (int) indexCount.get(0));
+        Assert.assertEquals(VERIFY_COUNT_ASSERT_MESSAGE, 2, (int) indexCount.get(1));
+    }
+
     @After
     public void cleanup() throws IOException, SQLException {
         //TEST.MOCK1,TEST1.MOCK2,TEST.MOCK3
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
index f5e39f4..b258674 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
@@ -650,18 +650,13 @@ public class IndexUpgradeTool extends Configured implements Tool {
 
         if (hasViewIndex) {
 
-            String viewSql = "SELECT DISTINCT TABLE_NAME, TENANT_ID FROM "
-                    + "SYSTEM.CATALOG "
-                    + "WHERE COLUMN_FAMILY = \'" + dataTableFullName + "\' "
-                    + (!StringUtil.EMPTY_STRING.equals(schemaName) ? "AND TABLE_SCHEM = \'"
-                    + schemaName + "\' " : "")
-                    + "AND LINK_TYPE = "
-                    + PTable.LinkType.PHYSICAL_TABLE.getSerializedValue();
+            String viewSql = getViewSql(tableName, schemaName);
 
             ResultSet rs = conn.createStatement().executeQuery(viewSql);
 
             while (rs.next()) {
-                String viewName = rs.getString(1);
+                String viewFullName = rs.getString(1);
+                String viewName = SchemaUtil.getTableNameFromFullName(viewFullName);
                 String tenantId = rs.getString(2);
 
                 ArrayList<String> viewIndexes = findViewIndexes(conn, schemaName, viewName,
@@ -676,16 +671,21 @@ public class IndexUpgradeTool extends Configured implements Tool {
         return indexInfos;
     }
 
+    @VisibleForTesting
+    public String getViewSql(String tableName, String schemaName) {
+       return "SELECT DISTINCT COLUMN_FAMILY, TENANT_ID FROM "
+                + "SYSTEM.CATALOG "
+                + "WHERE TABLE_NAME = \'" + tableName + "\'"
+                + (!Strings.isNullOrEmpty(schemaName) ? " AND TABLE_SCHEM = \'"
+                + schemaName + "\'" : "")
+                + " AND LINK_TYPE = "
+                + PTable.LinkType.CHILD_TABLE.getSerializedValue();
+    }
+
     private ArrayList<String> findViewIndexes(Connection conn, String schemaName, String viewName,
             String tenantId) throws SQLException {
 
-        String viewIndexesSql = "SELECT DISTINCT COLUMN_FAMILY FROM "
-                + "SYSTEM.CATALOG "
-                + "WHERE TABLE_NAME = \'" + viewName + "\'"
-                + (!StringUtil.EMPTY_STRING.equals(schemaName) ? "AND TABLE_SCHEM = \'"
-                + schemaName + "\' " : "")
-                + "AND LINK_TYPE = " + PTable.LinkType.INDEX_TABLE.getSerializedValue()
-                + (tenantId != null ? " AND TENANT_ID = \'" + tenantId + "\'" : "");
+        String viewIndexesSql = getViewIndexesSql(viewName, schemaName, tenantId);
         ArrayList<String> viewIndexes = new ArrayList<>();
         ResultSet
                 rs =
@@ -697,6 +697,17 @@ public class IndexUpgradeTool extends Configured implements Tool {
         return viewIndexes;
     }
 
+    @VisibleForTesting
+    public String getViewIndexesSql(String viewName, String schemaName, String tenantId) {
+        return "SELECT DISTINCT COLUMN_FAMILY FROM "
+                + "SYSTEM.CATALOG "
+                + "WHERE TABLE_NAME = \'" + viewName + "\'"
+                + (!Strings.isNullOrEmpty(schemaName) ? " AND TABLE_SCHEM = \'"
+                + schemaName + "\'" : "")
+                + " AND LINK_TYPE = " + PTable.LinkType.INDEX_TABLE.getSerializedValue()
+                + (tenantId != null ? " AND TENANT_ID = \'" + tenantId + "\'" : "");
+    }
+
     private class IndexInfo {
         final private String schemaName;
         final private String baseTable;