Skip to content

HIVE-29878: Support pagination for list endpoints in HMS REST Catalog and remove redundant type casting in REST Catalog - #6750

Open
Aggarwal-Raghav wants to merge 3 commits into
apache:masterfrom
Aggarwal-Raghav:HIVE-29878
Open

Aggarwal-Raghav wants to merge 3 commits into
apache:masterfrom
Aggarwal-Raghav:HIVE-29878

Conversation

@Aggarwal-Raghav

@Aggarwal-Raghav Aggarwal-Raghav commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR updates HMSCatalogAdapter to correctly extract pageToken and pageSize query parameters for the listNamespaces, listTables, and listViews REST routes.
Additionally, this PR performs several architectural cleanups to modernize the adapter:

  • Removed the redundant castResponse method, leveraging Java generics.
  • Replaced the deprecated NAMESPACE_SPLITTER and decodeNamespace(String) with modern Iceberg 1.11.0 equivalents (namespaceFromQueryParam and decodeNamespace(..., "%1F")).
  • Extracted 'pageToken', 'pageSize', and 'parent' string literals into standard constants.

Why are the changes needed?

Iceberg Rest Catalog Spec supports it as follows and this helps in catalog contains large number of tables.

  1. https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml#L250-L269
  2. https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml#L525-L538

Does this PR introduce any user-facing change?

NO

How was this patch tested?

Added TestHMSCatalogAdapterPagination JUnit test

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor Author

CC @deniskuzZ , can you help with review?

namespace = Namespace.empty();
}
return castResponse(ListNamespacesResponse.class, CatalogHandlers.listNamespaces(asNamespaceCatalog, namespace));
String pageToken = PropertyUtil.propertyAsString(vars, "pageToken", null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we extract pagination to decorator lambda or similar? need test

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor Author

gentle ping for review @deniskuzZ , have handled your review comments.

Class<T> responseType,
Supplier<Object> unpaginatedTask,
BiFunction<String, String, Object> paginatedTask) {
String pageToken = PropertyUtil.propertyAsString(properties, PAGE_TOKEN, null);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only listNamespaces, listTables, and listViews and listFunctions supports pagination based on iceberg spec.

return castResponse(ConfigResponse.class, ConfigResponse.builder().withEndpoints(endpoints).build());
}

private <T extends RESTResponse> T executePaginated(

@deniskuzZ deniskuzZ Sep 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we apply minor changes to design, how about

/** 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);
}

usage

  private ListTablesResponse listTables(Map<String, String> vars) {
    Namespace namespace = namespaceFromPathVars(vars);
    return paginateIfRequested(vars,
        () -> CatalogHandlers.listTables(catalog, namespace),
        p -> CatalogHandlers.listTables(catalog, namespace, p.token(), p.size()));
  }

why did we need castResponse at all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept castResponse because of original author's code. I think almost every return statement is wrapped with castResponse.

@deniskuzZ deniskuzZ Sep 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but is that actually needed? if not - we can drop it in follow-up PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I remove castRespose all together in this PR iteself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but is that actually needed?

i don't think so.

@deniskuzZ deniskuzZ Sep 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I remove castRespose all together in this PR iteself?

if that won't be a huge change, otherwise let's move it to follow-up. but drop it from pagination part of this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed castResponse in this PR and update PR title and description

@Aggarwal-Raghav Aggarwal-Raghav changed the title HIVE-29878: HMS REST Catalog ignores pagination for listTables and listNamespaces HIVE-29878: Support pagination for list endpoints in HMS REST Catalog and remove redundant type casting in REST Catalog Sep 23, 2026
…atalog

- Removed redundant castResponse method and BadResponseType exception
- Replaced deprecated NAMESPACE_SPLITTER with RESTUtil.namespaceFromQueryParam
- Extracted 'parent' string literal into PARENT constant
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants