swaroopak commented on a change in pull request #551: PHOENIX-5415: NPE in 
getting conf from addHbaseResources in IndexUpgr…
URL: https://github.com/apache/phoenix/pull/551#discussion_r307883918
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
 ##########
 @@ -572,40 +577,55 @@ private void prepareToRebuildIndexes(Connection conn, 
String dataTableFullName)
             }
 
             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());
+                String viewSql = "SELECT DISTINCT TABLE_NAME, TENANT_ID FROM "
+                        + "SYSTEM.CATALOG "
+                        + "WHERE COLUMN_FAMILY = \'" + dataTableFullName + "\' 
"
+                        + "AND LINK_TYPE = "
+                        + PTable.LinkType.PHYSICAL_TABLE.getSerializedValue();
+
+                ResultSet rs =
+                        conn.createStatement().executeQuery(viewSql);
+
                 while (rs.next()) {
-                    String viewIndexName = rs.getString(1);
+                    String viewName = 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 == null ? GLOBAL_INDEX_ID: tenantId,
-                            viewIndexName);
-                    rebuildIndexes.put(viewIndexName, indexInfo);
+
+                    findViewIndexes(conn, schemaName, viewName, tenantId, 
rebuildIndexes);
                 }
             }
             //for rebuilding indexes in case of upgrade.
             rebuildMap.put(dataTableFullName, rebuildIndexes);
+
+            String json = gson.toJson(rebuildMap);
+            LOGGER.info("Index rebuild map " + json);
         } catch (SQLException e) {
-            LOGGER.severe("Failed to prepare the map for index rebuilds "+e);
+            LOGGER.severe("Failed to prepare the map for index rebuilds " + e);
             throw new RuntimeException("Failed to prepare the map for index 
rebuilds");
         }
     }
 
+    private void findViewIndexes(Connection conn, String schemaName, String 
viewName,
+            String tenantId, HashMap<String, IndexInfo> rebuildIndexes) throws 
SQLException {
 
 Review comment:
   I see what you mean, thanks! :D 

----------------------------------------------------------------
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

Reply via email to