eric-maynard commented on code in PR #1528:
URL: https://github.com/apache/polaris/pull/1528#discussion_r2078881363


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/pagination/PageToken.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.persistence.pagination;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * 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 abstract class PageToken {
+
+  public int pageSize;
+
+  public static final PageToken END = null;
+  public static final int DEFAULT_PAGE_SIZE = 1000;
+
+  protected void validate() {
+    if (pageSize <= 0) {
+      throw new IllegalArgumentException("Page size must be greater than 
zero");
+    }
+  }
+
+  /**
+   * Get a new PageTokenBuilder from a PageToken. The PageTokenBuilder type 
should match the
+   * PageToken type. Implementations may also provide a static `builder` 
method to obtain the same
+   * PageTokenBuilder.
+   */
+  protected abstract PageTokenBuilder<?> getBuilder();
+
+  /** Allows `PageToken` implementations to implement methods like `fromLimit` 
*/
+  public abstract static class PageTokenBuilder<T extends PageToken> {
+
+    /**
+     * A prefix that tokens are expected to start with, ideally unique across 
`PageTokenBuilder`
+     * implementations.
+     */
+    public abstract String tokenPrefix();
+
+    /**
+     * The number of expected components in a token. This should match the 
number of components
+     * returned by getComponents and shouldn't account for the prefix or the 
checksum.
+     */
+    public abstract int expectedComponents();
+
+    /** Deserialize a string into a {@link PageToken} */
+    public final PageToken fromString(String tokenString) {
+      if (tokenString == null) {
+        throw new IllegalArgumentException("Cannot build page token from null 
string");
+      } else if (tokenString.isEmpty()) {
+        if (this instanceof 
ReadEverythingPageToken.ReadEverythingPageTokenBuilder) {
+          return ReadEverythingPageToken.get();

Review Comment:
   For at least the first iteration, I want to take a hard line on complying 
with the spec. That means that if there's no page token, we return everything.
   
   Today, we just return all results no matter what the user asks for. I think 
it's okay to keep returning all results if the user asks for it, but at least 
now we will give users the option to ask for something else. If nothing else 
it's an incremental improvement.
   
   wrt. null vs empty string, I'm a bit paranoid about us accidentally 
paginating results when the user doesn't expect it. So I think it's better to 
err on the side of the current (and still spec-compliant) behavior of just 
returning everything. 



-- 
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

Reply via email to