deniskuzZ commented on code in PR #6750:
URL: https://github.com/apache/hive/pull/6750#discussion_r4097566751


##########
standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogAdapter.java:
##########
@@ -275,23 +282,38 @@ public Class<? extends RESTRequest> requestClass() {
   private ConfigResponse config() {
     final List<Endpoint> endpoints = Arrays.stream(Route.values())
         .map(r -> Endpoint.create(r.method.name(), r.pathTemplate)).toList();
-    return castResponse(ConfigResponse.class, 
ConfigResponse.builder().withEndpoints(endpoints).build());
+    return ConfigResponse.builder().withEndpoints(endpoints).build();
+  }
+
+  /** Paging parameters of a list request; present only when the client sent 
pageSize. */
+  private record PageRequest(String token, String size) {
+    static Optional<PageRequest> from(Map<String, String> vars) {
+      return Optional.ofNullable(vars.get(PAGE_SIZE))
+          .map(size -> new PageRequest(vars.get(PAGE_TOKEN), size));
+    }
+  }
+
+  private static <R> R paginateIfRequested(
+      Map<String, String> vars, Supplier<R> fullList, Function<PageRequest, R> 
page) {
+    return PageRequest.from(vars).map(page).orElseGet(fullList);
   }
 
   private ListNamespacesResponse listNamespaces(Map<String, String> vars) {
     Namespace namespace;
-    if (vars.containsKey("parent")) {
-      namespace = 
Namespace.of(RESTUtil.NAMESPACE_SPLITTER.splitToStream(vars.get("parent")).toArray(String[]::new));
+    if (vars.containsKey(PARENT)) {
+      namespace = RESTUtil.namespaceFromQueryParam(vars.get(PARENT));
     } else {
       namespace = Namespace.empty();
     }
-    return castResponse(ListNamespacesResponse.class, 
CatalogHandlers.listNamespaces(asNamespaceCatalog, namespace));
+    return paginateIfRequested(

Review Comment:
   could we simplify it further?
   ````
   /**
    * Paging parameters of a list request. Without pageSize the listing is 
unpaged, expressed as a
    * single unbounded first page. This relies on CatalogHandlers.paginate 
treating a null token as
    * the first page and returning a null next-page-token once the list is 
exhausted.
    */
   private record PageRequest(String token, String size) {
     private static final PageRequest UNPAGED =
         new PageRequest(null, String.valueOf(Integer.MAX_VALUE));
   
     static PageRequest from(Map<String, String> vars) {
       String size = vars.get(PAGE_SIZE);
       if (size == null) {
         return UNPAGED; // token ignored, as upstream; keeping it would 
overflow token + MAX_VALUE
       }
       Preconditions.checkArgument(NumberUtils.toInt(size, 0) > 0,
           "Invalid %s: %s, must be a positive integer", PAGE_SIZE, size);
       return new PageRequest(vars.get(PAGE_TOKEN), size);
     }
   }
   
   private ListNamespacesResponse listNamespaces(Map<String, String> vars) {
     Namespace parent = vars.containsKey(PARENT)
         ? RESTUtil.namespaceFromQueryParam(vars.get(PARENT))
         : Namespace.empty();
     PageRequest page = PageRequest.from(vars);
     return CatalogHandlers.listNamespaces(asNamespaceCatalog, parent, 
page.token(), page.size());
   }
   
   private ListTablesResponse listTables(Map<String, String> vars) {
     Namespace namespace = namespaceFromPathVars(vars);
     PageRequest page = PageRequest.from(vars);
     return CatalogHandlers.listTables(catalog, namespace, page.token(), 
page.size());
   }
   
   private ListTablesResponse listViews(Map<String, String> vars) {
     Namespace namespace = namespaceFromPathVars(vars);
     PageRequest page = PageRequest.from(vars);
     return CatalogHandlers.listViews(asViewCatalog, namespace, page.token(), 
page.size());
   }
   ````



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