ankitsultana commented on a change in pull request #8188:
URL: https://github.com/apache/pinot/pull/8188#discussion_r809525327



##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableInstances.java
##########
@@ -116,16 +121,42 @@ public String getTableInstances(
   }
 
   @GET
-  @Path("/tables/{tableNameWithType}/livebrokers")
+  @Path("/tables/{tableName}/livebrokers")
   @Produces(MediaType.APPLICATION_JSON)
   @ApiOperation(value = "List the brokers serving a table", notes = "List live 
brokers of the given table based on EV")
   @ApiResponses(value = {
       @ApiResponse(code = 200, message = "Success"),
       @ApiResponse(code = 404, message = "Table not found"),
       @ApiResponse(code = 500, message = "Internal server error")})
   public List<String> getLiveBrokersForTable(
-      @ApiParam(value = "Table name with type", required = true)
-      @PathParam("tableNameWithType") String tableNameWithType) {
-    return 
_pinotHelixResourceManager.getLiveBrokersForTable(tableNameWithType);
+      @ApiParam(value = "Table name (with or without type)", required = true)
+      @PathParam("tableName") String tableName) {
+    if (TableNameBuilder.getTableTypeFromTableName(tableName) != null) {
+      return _pinotHelixResourceManager.getLiveBrokersForTable(tableName);
+    }
+    // If table doesn't have table-type suffix, then we return the intersection
+    // of brokers for both realtime and offline table-types.
+    boolean hasOfflineTable = 
_pinotHelixResourceManager.hasOfflineTable(tableName);
+    boolean hasRealtimeTable = 
_pinotHelixResourceManager.hasRealtimeTable(tableName);
+    if (hasOfflineTable && hasRealtimeTable) {
+      Set<String> offlineBrokers = new 
HashSet<>(_pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.OFFLINE.tableNameWithType(tableName)));
+      return _pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.REALTIME.tableNameWithType(tableName))
+              .stream()
+              .filter(offlineBrokers::contains)
+              .collect(Collectors.toList());
+    } else if (hasOfflineTable) {
+      return _pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.OFFLINE.tableNameWithType(tableName));
+    } else if (hasRealtimeTable) {
+      return _pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.REALTIME.tableNameWithType(tableName));
+    }
+    return new ArrayList<>();
+  }
+
+  public void setPinotHelixResourceManager(PinotHelixResourceManager 
pinotHelixResourceManager) {
+      _pinotHelixResourceManager = pinotHelixResourceManager;

Review comment:
       Ah good catch.. didn't know about this. Fixed




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to