dimas-b commented on code in PR #1838: URL: https://github.com/apache/polaris/pull/1838#discussion_r2144152233
########## polaris-core/src/main/java/org/apache/polaris/core/persistence/pagination/Page.java: ########## @@ -18,25 +18,96 @@ */ package org.apache.polaris.core.persistence.pagination; +import static java.util.Spliterators.iterator; + +import jakarta.annotation.Nullable; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** - * An immutable page of items plus their paging cursor. The {@link PageToken} here can be used to - * continue the listing operation that generated the `items`. + * An immutable page of items plus their paging cursor. The {@link #encodedResponseToken()} here can + * be used to continue the listing operation that generated the `items`. */ public class Page<T> { - public final PageToken pageToken; - public final List<T> items; + private final PageToken request; + private final List<T> items; + @Nullable private final String encodedDataReference; - public Page(PageToken pageToken, List<T> items) { - this.pageToken = pageToken; + private Page(PageToken request, @Nullable String encodedDataReference, List<T> items) { + this.request = request; + this.encodedDataReference = encodedDataReference; this.items = items; } /** - * Used to wrap a {@link List<T>} of items into a {@link Page <T>} when there are no more pages + * Builds a complete response page for the full list of relevant items. No subsequence pages of + * related data exist. */ public static <T> Page<T> fromItems(List<T> items) { - return new Page<>(new DonePageToken(), items); + return new Page<>(PageToken.readEverything(), null, items); + } + + /** + * Produces a response page by consuming the number of items from the provided stream according to + * the {@code request} parameter. Source items can be converted to a different type by providing a + * {@code mapper} function. The page token for the response will be produced from the request data + * combined with the pointer to the next page of data provided by the {@code dataPointer} + * function. + * + * @param request defines pagination parameters that were uses to produce this page of data. + * @param items stream of source data + * @param mapper converter from source data types to response data types. + * @param dataPointer determines the internal pointer to the next page of data given the last item Review Comment: How about keeping current `PageToken` class mostly as it is, but replacing its `String encodedDataReference` with `DataPointer dataPointer`? It does make the code nicer by having a specific type, but IMHO it adds a difficulty from the processing perspective: * Parsing `DataPointer` to a specific sub-type when `PageToken` is constructed will require encoding type information in the token. That is redundant IMHO, but I'm ok with that change. * Persistence methods that need to "understand" a `DataPointer` will have to be type casts, which is not elegant, IMHO. Currently they do not have to, persistence implementations currently just call a known parse method, which then will raise exceptions if the data is malformed. As a middle ground option WDYT about using `DataPointer` to wrap the encoded `String` (no sub-types), but still use static parsing methods to be called from Persistence? -- 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...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org