priyankporwal commented on a change in pull request #546: PHOENIX-5395:
IndexUpgradeTool passes data table instead of view for …
URL: https://github.com/apache/phoenix/pull/546#discussion_r305087725
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
##########
@@ -554,4 +551,99 @@ private boolean extractTablesAndIndexes(PhoenixConnection
conn) {
return false;
}
}
+
+ private void prepareToRebuildIndexes(Connection conn) {
+ try {
+ HashMap<String, IndexInfo> rebuildIndexes = new HashMap<>();
+
+ for (Map.Entry<String, HashSet<String>> entry :
tablesAndIndexes.entrySet()) {
+ String physicalTableName = entry.getKey();
+ HashSet<String> physicalIndexes = entry.getValue();
+
+ String viewIndexPhysicalName = MetaDataUtil
+ .getViewIndexPhysicalName(physicalTableName);
+ boolean hasViewIndex =
physicalIndexes.contains(viewIndexPhysicalName);
+
+ String schemaName =
SchemaUtil.getSchemaNameFromFullName(physicalTableName);
+ String tableName =
SchemaUtil.getTableNameFromFullName(physicalTableName);
+
+ for (String physicalIndexName : physicalIndexes) {
+ if (physicalIndexName.equals(viewIndexPhysicalName)) {
+ continue;
+ }
+
+ String indexTableName =
SchemaUtil.getTableNameFromFullName(physicalIndexName);
+ String pIndexName = SchemaUtil.getTableName(schemaName,
indexTableName);
+ IndexInfo indexInfo = new IndexInfo(schemaName, tableName,
+ GLOBAL_INDEX_ID, pIndexName);
+
+ rebuildIndexes.put(physicalIndexName, indexInfo);
+ }
+ if (hasViewIndex) {
+ ResultSet
+ rs =
+ conn.createStatement().executeQuery(
+ "SELECT DISTINCT TABLE_NAME, TENANT_ID
FROM "
+ + "SYSTEM.CATALOG WHERE
COLUMN_FAMILY = \'"
+ + viewIndexPhysicalName
+ + "\' AND TABLE_TYPE = \'i\' AND "
+ "LINK_TYPE = "
+ +
PTable.LinkType.PHYSICAL_TABLE.getSerializedValue());
+ while (rs.next()) {
+ String viewIndexName = rs.getString(1);
+ String tenantId = rs.getString(2);
+ ResultSet
+ innerRS =
+ conn.createStatement().executeQuery(
+ "SELECT DISTINCT TABLE_NAME FROM "
+ + "SYSTEM.CATALOG WHERE
COLUMN_FAMILY = \'"
+ + viewIndexName
+ + "\' AND TABLE_TYPE = \'i\'
AND " + "LINK_TYPE = "
+ +
PTable.LinkType.INDEX_TABLE.getSerializedValue());
+ innerRS.next();
+ String viewName = innerRS.getString(1);
+ IndexInfo
+ indexInfo =
+ new IndexInfo(schemaName, viewName, tenantId,
viewIndexName);
+ rebuildIndexes.put(viewIndexName, indexInfo);
+ }
+ }
+ //for rebuilding indexes in case of upgrade.
+ rebuildMap.put(physicalTableName, rebuildIndexes);
+ }
+ } catch (SQLException e) {
+ LOGGER.severe("Failed to prepare the map for index rebuilds "+e);
+ throw new RuntimeException("Failed to prepare the map for index
rebuilds");
+ }
+ }
+
+ private class IndexInfo {
+
Review comment:
Nit: remove blank line
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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