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/07 18:35:41 UTC
[phoenix] branch 4.15-HBase-1.3 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.15-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.15-HBase-1.3 by this push:
new 496ec30 PHOENIX-5650: IndexUpgradeTool does not rebuild view indexes
496ec30 is described below
commit 496ec30021382583c52aaefa08e66acb702a51c6
Author: s.kadam <s....@apache.org>
AuthorDate: Mon Jan 6 15:38:35 2020 -0800
PHOENIX-5650: IndexUpgradeTool does not rebuild view indexes
---
.../end2end/ParameterizedIndexUpgradeToolIT.java | 35 +++++++++++++++++-
.../phoenix/mapreduce/index/IndexUpgradeTool.java | 41 ++++++++++++++--------
2 files changed, 60 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 5a2cef9..a529f33 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
@@ -52,9 +52,12 @@ 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;
@@ -86,6 +89,8 @@ 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 +173,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
@@ -346,6 +351,34 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest {
}
}
+ @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 ef8c492..0a1f276 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
@@ -648,17 +648,12 @@ 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,
tenantId);
@@ -673,16 +668,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.CHILD_LINK "
+ + "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 = conn.createStatement().executeQuery(viewIndexesSql);
while (rs.next()) {
@@ -692,6 +692,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;