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?
````
/** Unpaged listing is expressed as a single unbounded first page of the
paged CatalogHandlers API. */
private static final String UNBOUNDED = String.valueOf(Integer.MAX_VALUE);
/** The token only applies together with pageSize; unpaged listings always
start at the first page. */
private static String pageToken(Map<String, String> vars) {
return vars.containsKey(PAGE_SIZE) ? vars.get(PAGE_TOKEN) : null;
}
private static String pageSize(Map<String, String> vars) {
String size = vars.getOrDefault(PAGE_SIZE, UNBOUNDED);
Preconditions.checkArgument(NumberUtils.toInt(size, 0) > 0,
"Invalid %s: %s, must be a positive integer", PAGE_SIZE, size);
return size;
}
private ListNamespacesResponse listNamespaces(Map<String, String> vars) {
Namespace parent = vars.containsKey(PARENT)
? RESTUtil.namespaceFromQueryParam(vars.get(PARENT))
: Namespace.empty();
return CatalogHandlers.listNamespaces(asNamespaceCatalog, parent,
pageToken(vars), pageSize(vars));
}
private ListTablesResponse listTables(Map<String, String> vars) {
return CatalogHandlers.listTables(
catalog, namespaceFromPathVars(vars), pageToken(vars), pageSize(vars));
}
private ListTablesResponse listViews(Map<String, String> vars) {
return CatalogHandlers.listViews(
asViewCatalog, namespaceFromPathVars(vars), pageToken(vars),
pageSize(vars));
}
````
--
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]