This is an automated email from the ASF dual-hosted git repository. jackie pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push: new 94009d548e Add segmentNames as an optional parameter in the get IS and EV APIs for a table (#15332) 94009d548e is described below commit 94009d548e511c5a37022bf5d4c9765f0ffd86cf Author: Chaitanya Deepthi <45308220+deepthi...@users.noreply.github.com> AuthorDate: Thu Mar 20 17:25:34 2025 -0400 Add segmentNames as an optional parameter in the get IS and EV APIs for a table (#15332) --- .../pinot/controller/api/resources/TableViews.java | 48 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java index c4ade0c947..41bda73670 100644 --- a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java +++ b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java @@ -28,9 +28,11 @@ import io.swagger.annotations.Authorization; import io.swagger.annotations.SecurityDefinition; import io.swagger.annotations.SwaggerDefinition; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; @@ -43,6 +45,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.apache.commons.lang3.StringUtils; import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; import org.apache.pinot.common.utils.DatabaseUtils; @@ -96,10 +99,17 @@ public class TableViews { public TableView getIdealState( @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "realtime|offline", required = false) @QueryParam("tableType") String tableTypeStr, - @Context HttpHeaders headers) { + @ApiParam(value = "Comma separated segment names", required = false) @QueryParam("segmentNames") + String segmentNames, @Context HttpHeaders headers) { tableName = DatabaseUtils.translateTableName(tableName, headers); TableType tableType = validateTableType(tableTypeStr); - return getTableState(tableName, IDEALSTATE, tableType); + TableViews.TableView tableIdealStateView = getTableState(tableName, IDEALSTATE, tableType); + if (StringUtils.isNotEmpty(segmentNames)) { + List<String> segmentNamesList = + Arrays.stream(segmentNames.split(",")).map(String::trim).collect(Collectors.toList()); + return getSegmentsView(tableIdealStateView, segmentNamesList); + } + return tableIdealStateView; } @GET @@ -110,10 +120,17 @@ public class TableViews { public TableView getExternalView( @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "realtime|offline", required = false) @QueryParam("tableType") String tableTypeStr, - @Context HttpHeaders headers) { + @ApiParam(value = "Comma separated segment names", required = false) @QueryParam("segmentNames") + String segmentNames, @Context HttpHeaders headers) { tableName = DatabaseUtils.translateTableName(tableName, headers); TableType tableType = validateTableType(tableTypeStr); - return getTableState(tableName, EXTERNALVIEW, tableType); + TableViews.TableView tableExternalView = getTableState(tableName, EXTERNALVIEW, tableType); + if (StringUtils.isNotEmpty(segmentNames)) { + List<String> segmentNamesList = + Arrays.stream(segmentNames.split(",")).map(String::trim).collect(Collectors.toList()); + return getSegmentsView(tableExternalView, segmentNamesList); + } + return tableExternalView; } @GET @@ -170,6 +187,29 @@ public class TableViews { return segmentStatusInfoList; } + public TableView getSegmentsView(TableViews.TableView tableView, List<String> segmentNames) { + TableView tableViewResult = new TableView(); + if (tableView._offline != null) { + tableViewResult._offline = getTableTypeSegmentsView(tableView._offline, segmentNames); + } + if (tableView._realtime != null) { + tableViewResult._realtime = getTableTypeSegmentsView(tableView._realtime, segmentNames); + } + return tableViewResult; + } + + private Map<String, Map<String, String>> getTableTypeSegmentsView(Map<String, Map<String, String>> tableTypeView, + List<String> segmentNames) { + Map<String, Map<String, String>> tableTypeViewResult = new HashMap<>(); + for (String segmentName : segmentNames) { + Map<String, String> segmentView = tableTypeView.get(segmentName); + if (segmentView != null) { + tableTypeViewResult.put(segmentName, segmentView); + } + } + return tableTypeViewResult; + } + private Map<String, Map<String, String>> getStateMap(TableViews.TableView view) { if (view != null && view._offline != null && !view._offline.isEmpty()) { return view._offline; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org