eric-maynard commented on code in PR #273: URL: https://github.com/apache/polaris/pull/273#discussion_r1749473480
########## polaris-core/src/main/java/org/apache/polaris/core/catalog/PageToken.java: ########## @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.core.catalog; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.List; + +/** + * Represents a page token that can be used by operations like `listTables`. Clients that specify a + * `pageSize` (or a `pageToken`) may receive a `next-page-token` in the response, the content of + * which is a serialized PageToken. + * + * <p>By providing that in the next query's `pageToken`, the client can resume listing where they + * left off. If the client provides a `pageToken` or `pageSize` but `next-page-token` is null in the + * response, that means there is no more data to read. + */ +public class PageToken { + + public final int offset; + public final int pageSize; + + private static final String TOKEN_PREFIX = "polaris"; + private static final int TOKEN_START = 0; + private static final int DEFAULT_PAGE_SIZE = 1000; + + public static PageToken DONE = null; + + public PageToken(int offset, int pageSize) { + this.offset = offset; + this.pageSize = pageSize; + } + + /** Construct a PageToken from a plain limit */ + public static PageToken fromLimit(int limit) { + return new PageToken(TOKEN_START, limit); + } + + /** Construct a PageToken to read everything */ + public static PageToken readEverything() { + return new PageToken(TOKEN_START, Integer.MAX_VALUE); + } + + /** Deserialize a token string into a PageToken object */ + public static PageToken fromString(String tokenString) { + if (tokenString == null) { + return PageToken.readEverything(); Review Comment: The client is allowed to request a read without pagination. In that case, we could potentially OOM. But solving that is probably not in scope here; the goal of pagination as defined by the spec is to allow the client to _choose_ a smaller page size, not to enforce that it must choose a small 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]
