RQ - request typeRS - response typeT - item typepublic class Paginator<RQ,RS,T> extends Object implements Iterable<T>
Databricks APIs use two pagination strategies. Token-based APIs may return an empty page that
still carries a next_page_token, so iteration must continue until nextPageFn
returns null (newTokenPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>)). Offset/limit APIs (SCIM, legacy SQL) carry no token
and stop on the first empty page (newOffsetPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>)).
| Constructor and Description |
|---|
Paginator(RQ request,
Function<RQ,RS> requestFn,
Function<RS,Collection<T>> itemsFn,
Function<RS,RQ> nextPageFn)
Deprecated.
Use
newTokenPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>) or newOffsetPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>) instead, which make
the pagination strategy explicit. Token-based APIs must use newTokenPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>) to
avoid stopping early on an empty page that still carries a next-page token. |
| Modifier and Type | Method and Description |
|---|---|
Iterator<T> |
iterator() |
static <RQ,RS,T> Paginator<RQ,RS,T> |
newOffsetPagination(RQ request,
Function<RQ,RS> requestFn,
Function<RS,Collection<T>> itemsFn,
Function<RS,RQ> nextPageFn)
Creates a paginator for offset/limit-based APIs, which stop on the first empty page.
|
static <RQ,RS,T> Paginator<RQ,RS,T> |
newTokenPagination(RQ request,
Function<RQ,RS> requestFn,
Function<RS,Collection<T>> itemsFn,
Function<RS,RQ> nextPageFn)
Creates a paginator for token-based APIs, which continue past empty pages until
nextPageFn returns null. |
<ID> Iterable<T> |
withDedupe(Function<T,ID> idGetter)
De-duplicate results across all pages with an ID
This call is only necessary for offset/limit pagination, where additions/removals may get
inconsistent results across multiple page calls
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliterator@Deprecated public Paginator(RQ request, Function<RQ,RS> requestFn, Function<RS,Collection<T>> itemsFn, Function<RS,RQ> nextPageFn)
newTokenPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>) or newOffsetPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>) instead, which make
the pagination strategy explicit. Token-based APIs must use newTokenPagination(RQ, java.util.function.Function<RQ, RS>, java.util.function.Function<RS, java.util.Collection<T>>, java.util.function.Function<RS, RQ>) to
avoid stopping early on an empty page that still carries a next-page token.request - initial request to `requestFn` implementation, possibly with filters.requestFn - implementation of request, that takes modified `request` and returns some
results.itemsFn - reference to the getter method, that returns `CollectionnextPageFn - return non-null request in case we need to fetch another page of results.public static <RQ,RS,T> Paginator<RQ,RS,T> newTokenPagination(RQ request, Function<RQ,RS> requestFn, Function<RS,Collection<T>> itemsFn, Function<RS,RQ> nextPageFn)
nextPageFn returns null.
Example:
return Paginator.newTokenPagination(request, impl::list, ListTablesResponse::getTables,
response -> {
String token = response.getNextPageToken();
if (token == null || token.isEmpty()) {
return null;
}
return request.setPageToken(token);
});
request - initial request to `requestFn` implementation, possibly with filters.requestFn - implementation of request, that takes modified `request` and returns some
results.itemsFn - reference to the getter method, that returns `CollectionnextPageFn - return non-null request in case we need to fetch another page of results,
null once the page token is absent.public static <RQ,RS,T> Paginator<RQ,RS,T> newOffsetPagination(RQ request, Function<RQ,RS> requestFn, Function<RS,Collection<T>> itemsFn, Function<RS,RQ> nextPageFn)
Example:
return Paginator.newOffsetPagination(request, impl::listRuns, ListRunsResponse::getRuns,
response -> {
Long offset = request.getOffset();
if (offset == null) {
offset = 0L;
}
offset += response.getRuns().size();
return request.setOffset(offset);
}).withDedupe(BaseRun::getRunId);
request - initial request to `requestFn` implementation, possibly with filters.requestFn - implementation of request, that takes modified `request` and returns some
results.itemsFn - reference to the getter method, that returns `CollectionnextPageFn - return non-null request in case we need to fetch another page of results.public <ID> Iterable<T> withDedupe(Function<T,ID> idGetter)
This call is only necessary for offset/limit pagination, where additions/removals may get inconsistent results across multiple page calls
ID - ID type, like LongidGetter - reference to ID getterCopyright © 2026. All rights reserved.