Jackie-Jiang commented on a change in pull request #7142: URL: https://github.com/apache/incubator-pinot/pull/7142#discussion_r667215753
########## File path: pinot-spi/src/main/java/org/apache/pinot/spi/config/table/TableStats.java ########## @@ -27,11 +27,20 @@ */ public class TableStats { public static final String CREATION_TIME_KEY = "creationTime"; + public static final String LAST_MODIFIED_TIME_KEY = "lastModifiedTime"; private String _creationTime; + private String _lastModifiedTime; + private String _tableName; - public TableStats(String creationTime) { + public TableStats(String creationTime, String lastModifiedTime, String tableName) { Review comment: Move `tableName` as the first parameter ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java ########## @@ -200,31 +202,69 @@ public String recommendConfig(String inputStr) { @Produces(MediaType.APPLICATION_JSON) @Path("/tables") @ApiOperation(value = "Lists all tables in cluster", notes = "Lists all tables in cluster") - public String listTableConfigs(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr) { + public String listTables(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr, + @ApiParam(value = "name|creationTime|lastModifiedTime") @QueryParam("sortType") @DefaultValue("name") String sortType, + @ApiParam(value = "true|false") @QueryParam("sortAsc") @DefaultValue("true") boolean sortAsc) { try { List<String> tableNames; TableType tableType = null; if (tableTypeStr != null) { tableType = TableType.valueOf(tableTypeStr.toUpperCase()); } + Boolean sortTypeValid = sortType.equalsIgnoreCase("name") || sortType.equalsIgnoreCase("creationTime") || sortType + .equalsIgnoreCase("lastModifiedTime"); + if (!sortTypeValid) { + throw new IllegalArgumentException( + "sortType expects={name|creationTime|lastModifiedTime} " + "got " + sortType); + } + if (tableType == null) { tableNames = _pinotHelixResourceManager.getAllRawTables(); + } else if (tableType == TableType.REALTIME) { + tableNames = _pinotHelixResourceManager.getAllRealtimeTables(); } else { - if (tableType == TableType.REALTIME) { - tableNames = _pinotHelixResourceManager.getAllRealtimeTables(); - } else { - tableNames = _pinotHelixResourceManager.getAllOfflineTables(); - } + tableNames = _pinotHelixResourceManager.getAllOfflineTables(); } - Collections.sort(tableNames); + HashMap<String, TableStats> MapStats = new HashMap<String, TableStats>(); Review comment: For `name` sort type, we don't need to read this list ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java ########## @@ -200,31 +202,69 @@ public String recommendConfig(String inputStr) { @Produces(MediaType.APPLICATION_JSON) @Path("/tables") @ApiOperation(value = "Lists all tables in cluster", notes = "Lists all tables in cluster") - public String listTableConfigs(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr) { + public String listTables(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr, + @ApiParam(value = "name|creationTime|lastModifiedTime") @QueryParam("sortType") @DefaultValue("name") String sortType, + @ApiParam(value = "true|false") @QueryParam("sortAsc") @DefaultValue("true") boolean sortAsc) { try { List<String> tableNames; TableType tableType = null; if (tableTypeStr != null) { tableType = TableType.valueOf(tableTypeStr.toUpperCase()); } + Boolean sortTypeValid = sortType.equalsIgnoreCase("name") || sortType.equalsIgnoreCase("creationTime") || sortType Review comment: This will cause NPE because sortType is optional ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java ########## @@ -200,31 +202,69 @@ public String recommendConfig(String inputStr) { @Produces(MediaType.APPLICATION_JSON) @Path("/tables") @ApiOperation(value = "Lists all tables in cluster", notes = "Lists all tables in cluster") - public String listTableConfigs(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr) { + public String listTables(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr, + @ApiParam(value = "name|creationTime|lastModifiedTime") @QueryParam("sortType") @DefaultValue("name") String sortType, + @ApiParam(value = "true|false") @QueryParam("sortAsc") @DefaultValue("true") boolean sortAsc) { try { List<String> tableNames; TableType tableType = null; if (tableTypeStr != null) { tableType = TableType.valueOf(tableTypeStr.toUpperCase()); } + Boolean sortTypeValid = sortType.equalsIgnoreCase("name") || sortType.equalsIgnoreCase("creationTime") || sortType + .equalsIgnoreCase("lastModifiedTime"); + if (!sortTypeValid) { + throw new IllegalArgumentException( + "sortType expects={name|creationTime|lastModifiedTime} " + "got " + sortType); + } + if (tableType == null) { tableNames = _pinotHelixResourceManager.getAllRawTables(); + } else if (tableType == TableType.REALTIME) { + tableNames = _pinotHelixResourceManager.getAllRealtimeTables(); } else { - if (tableType == TableType.REALTIME) { - tableNames = _pinotHelixResourceManager.getAllRealtimeTables(); - } else { - tableNames = _pinotHelixResourceManager.getAllOfflineTables(); - } + tableNames = _pinotHelixResourceManager.getAllOfflineTables(); } - Collections.sort(tableNames); + HashMap<String, TableStats> MapStats = new HashMap<String, TableStats>(); Review comment: A list here should be enough. We can directly sort on this list, and read the sorted table names from this list ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java ########## @@ -200,31 +202,69 @@ public String recommendConfig(String inputStr) { @Produces(MediaType.APPLICATION_JSON) @Path("/tables") @ApiOperation(value = "Lists all tables in cluster", notes = "Lists all tables in cluster") - public String listTableConfigs(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr) { + public String listTables(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr, + @ApiParam(value = "name|creationTime|lastModifiedTime") @QueryParam("sortType") @DefaultValue("name") String sortType, + @ApiParam(value = "true|false") @QueryParam("sortAsc") @DefaultValue("true") boolean sortAsc) { try { List<String> tableNames; TableType tableType = null; if (tableTypeStr != null) { tableType = TableType.valueOf(tableTypeStr.toUpperCase()); } + Boolean sortTypeValid = sortType.equalsIgnoreCase("name") || sortType.equalsIgnoreCase("creationTime") || sortType + .equalsIgnoreCase("lastModifiedTime"); + if (!sortTypeValid) { + throw new IllegalArgumentException( + "sortType expects={name|creationTime|lastModifiedTime} " + "got " + sortType); + } + if (tableType == null) { tableNames = _pinotHelixResourceManager.getAllRawTables(); + } else if (tableType == TableType.REALTIME) { + tableNames = _pinotHelixResourceManager.getAllRealtimeTables(); } else { - if (tableType == TableType.REALTIME) { - tableNames = _pinotHelixResourceManager.getAllRealtimeTables(); - } else { - tableNames = _pinotHelixResourceManager.getAllOfflineTables(); - } + tableNames = _pinotHelixResourceManager.getAllOfflineTables(); } - Collections.sort(tableNames); + HashMap<String, TableStats> MapStats = new HashMap<String, TableStats>(); + for (String tableName : tableNames) { + MapStats.put(tableName, _pinotHelixResourceManager.getTableStats(tableName)); + } + Review comment: Based on the sort type, sort accordingly: ```suggestion if (sortType == null || sortType.equalsIgnoreCase("name")) { tableNames.sort(sortAsc ? null : Comparator.reverseOrder()); } else { boolean sortByCreationTime = sortType.equalsIgnoreCase("creationTime"); Preconditions.checkState(sortByCreationTime || sortType.equalsIgnoreCase("lastModifiedTime"), ...); List<TableStats> tableStatsList = new ArrayList<>(tableNames.size()); for (String tableName : tableNames) { tableStatsList.add(_pinotHelixResourceManager.getTableStats(tableName)); } int sortFactor = sortAsc ? 1 : -1; if (sortByCreationTime) { Collections.sort(tableStatsList, (o1, o2) -> o1.getCreationTime().compareTo(o2.getCreationTime()) * sortFactor; } else { Collections.sort(tableStatsList, (o1, o2) -> o1.getModifiedTime().compareTo(o2.getModifiedTime()) * sortFactor; } // Create a new list from the sorted stats... } ``` -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org