amogh-jahagirdar commented on code in PR #11143: URL: https://github.com/apache/iceberg/pull/11143#discussion_r1765239647
########## core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java: ########## @@ -124,20 +133,19 @@ public static ListNamespacesResponse listNamespaces( SupportsNamespaces catalog, Namespace parent, String pageToken, String pageSize) { List<Namespace> results; List<Namespace> subResults; + String nextToken = null; if (parent.isEmpty()) { results = catalog.listNamespaces(); } else { results = catalog.listNamespaces(parent); } - int start = INTIAL_PAGE_TOKEN.equals(pageToken) ? 0 : Integer.parseInt(pageToken); - int end = start + Integer.parseInt(pageSize); - subResults = results.subList(start, end); - String nextToken = String.valueOf(end); + int pageStart = INITIAL_PAGE_TOKEN.equals(pageToken) ? 0 : Integer.parseInt(pageToken); + subResults = paginate(results, pageStart, Integer.parseInt(pageSize)); - if (end >= results.size()) { - nextToken = null; + if (pageStart + subResults.size() < results.size()) { + nextToken = String.valueOf(pageStart + subResults.size()); } Review Comment: Is it possible to put all this in a generic method `private static <T> String nextToken(List<T> results, String pageToken, String pageSize)` that way we don't have to duplicate and can more easily reuse it for other cases in the future? -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org