You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "rahil-c (via GitHub)" <gi...@apache.org> on 2024/02/22 18:49:57 UTC

[PR] Add Pagination To List Apis [iceberg]

rahil-c opened a new pull request, #9782:
URL: https://github.com/apache/iceberg/pull/9782

   Implemented pagination in list apis based on the spec: https://github.com/apache/iceberg/pull/9660
   @jackye1995 @nastra @danielcweeks @geruh 
   
   ## Testing
   * Ran gradle build 
   * Manual test passed
   


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1499864124


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -490,12 +522,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    }
+    if (restPaginationEnabled) {
+      List<Namespace> namespaces = Lists.newArrayList();
+      String pageToken = "";
+      queryParams.put("pageSize", restPageSize);
+
+      while (pageToken != null) {
+        queryParams.put("pageToken", pageToken);
+        LOG.error("Sending list namespaces request");

Review Comment:
   Did you mean to put this here



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558307800


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -83,6 +83,23 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid namespace: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() {
+    ListNamespacesResponse response =
+        ListNamespacesResponse.builder().addAll(NAMESPACES).nextPageToken(null).build();
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.namespaces()).isEqualTo(NAMESPACES);
+  }
+
+  @Test
+  public void testWithPaginationToken() {

Review Comment:
   will add this



##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -105,6 +105,23 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid table identifier: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() {
+    ListTablesResponse response =
+        ListTablesResponse.builder().addAll(IDENTIFIERS).nextPageToken(null).build();
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.identifiers()).isEqualTo(IDENTIFIERS);
+  }
+
+  @Test
+  public void testWithPaginationToken() {

Review Comment:
   will add this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1539170095


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -105,6 +105,14 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid table identifier: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() {

Review Comment:
   I feel like there should also be tests where the token is set



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1571188458


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,119 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/namespaces"),
+            any(),

Review Comment:
   will fix this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567745943


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -36,7 +36,7 @@ public class TestListTablesResponse extends RequestResponseTestBase<ListTablesRe
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
     String fullJson =
-        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}]}";
+        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"},\"next-page-token\":null]}";

Review Comment:
   will fix this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567855351


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,36 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    String viewName = "newview";
+
+    // create initial namespace
+    catalog().createNamespace(Namespace.of(namespaceName));
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from " + namespaceName + "." + tableName)

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567077122


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -1796,6 +1799,48 @@ public void testCatalogExpiredBearerTokenIsRefreshedWithCredential(String oauth2
             any());
   }
 
+
+  @Test
+  public void testCatalogWithPagaintionTokenIssue() {
+    //TODO remove this test, Used to highlight issue with namespaces

Review Comment:
   alternatively you can also add the mockito verifications on `adapter` to the other tests that you added (`testPaginationForListNamespaces()` / `testPaginationForListTables()` / `testPaginationForListViews()`).
   
   For `testPaginationForListNamespaces()` this test would do some additional checks after creating all namespaces and listing them. Those verification checks would be:
   
   // verify config endpoint was called (which is e.g. what you already have in L1822ff)
   // verify create namespace was called X times
   // verify list namespaces was called. Here is where you would verify that the pagination token is properly exchanged via query params



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1580469059


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +157,65 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+    String viewName = "newview";
+
+    // create initial namespace
+    catalog().createNamespace(Namespace.of(namespaceName));
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from ns.tbl")
+          .create();
+    }
+    List<TableIdentifier> views = catalog.listViews(Namespace.of(namespaceName));
+    assertThat(views).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            any(),
+            any(),
+            eq(LoadViewResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),

Review Comment:
   @nastra I am able to make two separate requests with `.handleRequest` instead of `execute`, and send the correct query params for each call.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1587968616


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -136,6 +137,7 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private FileIO io = null;
   private MetricsReporter reporter = null;
   private boolean reportingViaRestEnabled;
+  private Integer restPageSize = null;

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2091903148

   @danielcweeks Seems to be green now


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1556370624


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +226,7 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = mergedProps.get(REST_PAGE_SIZE);

Review Comment:
   We should probably add a validation that this is a positive integer if set.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1557800399


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -83,6 +83,23 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid namespace: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() {
+    ListNamespacesResponse response =
+        ListNamespacesResponse.builder().addAll(NAMESPACES).nextPageToken(null).build();
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.namespaces()).isEqualTo(NAMESPACES);
+  }
+
+  @Test
+  public void testWithPaginationToken() {

Review Comment:
   this should also do a JSON round-trip check similar to `testRoundTripSerDe()`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559608101


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,39 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    String viewName = "newview";
+
+    TableIdentifier tableIdentifier = TableIdentifier.of(namespaceName, tableName);
+
+    // create initial namespace and table
+    catalog().createNamespace(tableIdentifier.namespace());
+    tableCatalog().buildTable(tableIdentifier, SCHEMA).create();
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from " + namespaceName + "." + tableName)
+          .create();
+    }
+
+    List<TableIdentifier> views = catalog.listViews(Namespace.of(namespaceName));
+    assertThat(views.size()).isEqualTo(numberOfItems);

Review Comment:
   same as previously mentioned



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1575784851


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +157,65 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+    String viewName = "newview";
+
+    // create initial namespace
+    catalog().createNamespace(Namespace.of(namespaceName));
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from ns.tbl")
+          .create();
+    }
+    List<TableIdentifier> views = catalog.listViews(Namespace.of(namespaceName));
+    assertThat(views).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            any(),
+            any(),
+            eq(LoadViewResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),

Review Comment:
   rather than verifying that there have been `numberOfInvocations` where `pageToken` / `pageSize` are 10, I think there should be a separate check where `pageToken = ""`/ `pageSize = "10"`.
   
   What I mean is the below check as this also checks for the initial request:
   ```
   .... // config + namespace creation checks
    
   // the initial request
   Mockito.verify(adapter)
           .execute(
               eq(HTTPMethod.GET),
               eq(String.format("v1/namespaces/%s/views", namespaceName)),
               eq(ImmutableMap.of("pageToken", "", "pageSize", "10")),
               any(),
               eq(ListTablesResponse.class),
               any(),
               any());
   
   // the subsequent request after the server returned a paginated result
   Mockito.verify(adapter)
           .execute(
               eq(HTTPMethod.GET),
               eq(String.format("v1/namespaces/%s/views", namespaceName)),
               eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),
               any(),
               eq(ListTablesResponse.class),
               any(),
               any());
   ```
   
   This would also apply for the other paginated tests



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581860457


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -136,6 +137,7 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private FileIO io = null;
   private MetricsReporter reporter = null;
   private boolean reportingViaRestEnabled;
+  private String restPageSize = null;

Review Comment:
   We should make this `Integer` not `String`



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   I think he was recommending something like:
   
   ```java
   ImmutableList.Builder<TableIdentifier> result = ImmutableList.<TableIdentifier>builder();
   
   return result.build();
   ```



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -228,6 +230,13 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = mergedProps.get(REST_PAGE_SIZE);

Review Comment:
   Looking at where we ended up here, I think it make smore sense now to use:
   
   ```java
   import org.apache.iceberg.util.PropertyUtil;
   
   this.restPageSize =PropertyUtil.propertyAsNullableInt(mergedProps, REST_PAGE_SIZE);
   ```
   
   This avoids needing to do the parsing and lets the property util class expose the parse error.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581389185


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -494,22 +514,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
     }
+    List<Namespace> namespaces = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageSize", restPageSize);
+    }

Review Comment:
   will fix



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1580985211


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -494,22 +514,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
     }
+    List<Namespace> namespaces = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageSize", restPageSize);
+    }

Review Comment:
   nit: the codebase usually adds a newline after the closing } from if statements



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -494,22 +514,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
     }
+    List<Namespace> namespaces = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageSize", restPageSize);
+    }

Review Comment:
   nit: the codebase usually has a newline after the closing } from if statements



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1499953848


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +229,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    String restPaginationEnabledValue = mergedProps.get(REST_PAGINATION_ENABLED);

Review Comment:
   Do we need the feature flag? We designed these changes in a way that makes the pagination backwards compatible. Therefore, if the service response includes more results than the page size it should still work. Then we can simplify the logic in the listing methods to handle pagination but still accommodate for services sending  all results in single response.
   
   What do you think?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567097286


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   I've replied in https://github.com/apache/iceberg/pull/9782/files#r1567071915



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566940267


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,36 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));

Review Comment:
   same as above



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558712520


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);

Review Comment:
   > Shouldn't we only set pageSize if it's set?
   
   Im not sure I fully understand, I think this check `restPageSize != null` is checking if there is a value for `restPageSize`, and if so then we add pageSize to the query param map. 
   cc @danielcweeks 
   
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566939429


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));

Review Comment:
   no need for `Mockito.spy()` here as you're not doing any verifications on the `adapter` in this test (and in the other tests)



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results).hasSize(numberOfItems);
+  }
+
+  @Test
+  public void testPaginationForListTables() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));

Review Comment:
   same as above



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567730841


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   Will take a look thanks



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1546625002


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   @danielcweeks Can you elaborate on what you mean by prefetching? Did you want the client to retrieve all the paginated results from the service in one go ( by repeatedly sending requests until `next-page-token` is `null`)?
   
   I had this before:
   
   ```
    List<Namespace> namespaces = Lists.newArrayList();
         String pageToken = "";
         queryParams.put("pageSize", restPageSize);
    
         while (pageToken != null) {
           queryParams.put("pageToken", pageToken);
           LOG.error("Sending list namespaces request");
           ListNamespacesResponse response =
                   client.get(
                           paths.namespaces(),
                           queryParams,
                           ListNamespacesResponse.class,
                           headers(context),
                           ErrorHandlers.namespaceErrorHandler());
           pageToken = response.nextPageToken();
           namespaces.addAll(response.namespaces());
         }
   ```
   
    but i think the other reviewers of the pr mentioned that we want to do lazily loading of the results, and shared this `PaginatedList` as an idea https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/PaginatedList.html which is what i tried following.
   
   cc @rdblue @jackye1995 @nastra 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "sachet (via GitHub)" <gi...@apache.org>.
sachet commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1548998658


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   +1, Current implementation of paginated list seems wrong as caller can get unexpected results. Two possible options are:
   1. Pre-fetch all items (as suggested above)
   2. methods like size(), contains(), isEmpty(), toArray(), get() .. first paginates across all items before performing the operation. 
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1550695864


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   @danielcweeks @sachet Have done a revision for this using a prefetch approach if you can take a look whenever would be ideal. 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1550695864


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   @danielcweeks @sachet Have done a revision for this, if you can take a look whenever would be ideal.  Let me know if this aligns better with the direction for what we want or if there is another idea in mind? 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1556399763


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +226,7 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = mergedProps.get(REST_PAGE_SIZE);

Review Comment:
   will fix this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558712520


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);

Review Comment:
   > Shouldn't we only set pageSize if it's set?
   
   Im not sure I fully understand, I think this check `restPageSize != null` is checking if there is a value, and if so then we add it to the query param map. 
   
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559611564


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -34,7 +34,7 @@ public class TestListNamespacesResponse extends RequestResponseTestBase<ListName
 
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
-    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]]}";
+    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";

Review Comment:
   Older clients won't send this field, so I think we want to keep how the JSON was here for backward compatibility. 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581598929


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -494,22 +514,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
     }
+    List<Namespace> namespaces = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageSize", restPageSize);
+    }

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1580991187


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,129 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {

Review Comment:
   ```suggestion
     public void testInvalidPageSize() {
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2080224394

   Thanks @nastra for the help I appreciate it, will wait on @danielcweeks review. 


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2092390890

   Thanks for working on this @rahil-c 


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500369784


##########
core/src/main/java/org/apache/iceberg/rest/responses/ListNamespacesResponse.java:
##########
@@ -29,13 +29,15 @@
 public class ListNamespacesResponse implements RESTResponse {
 
   private List<Namespace> namespaces;
+  private String nextPageToken;

Review Comment:
   please also add some tests to `TestListNamespacesResponse`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1499864124


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -490,12 +522,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    }
+    if (restPaginationEnabled) {
+      List<Namespace> namespaces = Lists.newArrayList();
+      String pageToken = "";
+      queryParams.put("pageSize", restPageSize);
+
+      while (pageToken != null) {
+        queryParams.put("pageToken", pageToken);
+        LOG.error("Sending list namespaces request");

Review Comment:
   Did you mean to leave this here



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500065202


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1045,6 +1094,27 @@ public void commitTransaction(SessionContext context, List<TableCommit> commits)
   public List<TableIdentifier> listViews(SessionContext context, Namespace namespace) {
     checkNamespaceIsValid(namespace);
 
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (restPaginationEnabled) {
+      List<TableIdentifier> identifiers = Lists.newArrayList();
+      String pageToken = "";
+      queryParams.put("pageSize", restPageSize);
+
+      while (pageToken != null) {

Review Comment:
   Makes sense, will revise this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500375047


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -490,12 +522,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {

Review Comment:
   we would also need some more tests in `TestRESTCatalog` with paginated namespace / table listings



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559602987


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2330,46 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testPaginationForListNameSpaces() {

Review Comment:
   ```suggestion
     public void testPaginationForListNamespaces() {
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1556673446


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -490,12 +522,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {

Review Comment:
   added test



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558712520


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);

Review Comment:
   > Shouldn't we only set pageSize if it's set?
   Im not sure I fully understand, I think this check `restPageSize !=null` is checking if there is a value, and if so then we add it to the query param map. 
   
   



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);

Review Comment:
   > Shouldn't we only set pageSize if it's set?
   
   Im not sure I fully understand, I think this check `restPageSize !=null` is checking if there is a value, and if so then we add it to the query param map. 
   
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567967380


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -1796,6 +1799,48 @@ public void testCatalogExpiredBearerTokenIsRefreshedWithCredential(String oauth2
             any());
   }
 
+
+  @Test
+  public void testCatalogWithPagaintionTokenIssue() {
+    //TODO remove this test, Used to highlight issue with namespaces
+    String token =
+            "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE5OTk5OTk5OTk5fQ._3k92KJi2NTyTG6V1s2mzJ__GiQtL36DnzsZSkBdYPw";
+    Map<String, String> catalogHeaders = ImmutableMap.of("Authorization", "Bearer " + token);
+
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+
+    String credential = "catalog:12345";
+    Map<String, String> contextCredentials =
+            ImmutableMap.of("token", token, "credential", credential);
+    SessionCatalog.SessionContext context =
+            new SessionCatalog.SessionContext(
+                    UUID.randomUUID().toString(), "user", contextCredentials, ImmutableMap.of());
+
+    RESTCatalog catalog = new RESTCatalog(context, (config) -> adapter);
+    catalog.initialize("prod", ImmutableMap.of(CatalogProperties.URI, "ignored", "token", token));
+
+    Mockito.verify(adapter)
+            .execute(
+                    eq(HTTPMethod.GET),
+                    eq("v1/config"),
+                    any(),
+                    any(),
+                    eq(ConfigResponse.class),
+                    eq(catalogHeaders),
+                    any());
+
+    Mockito.verify(adapter)

Review Comment:
   Thank you for catching this, now able to get past this issue



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566939950


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results).hasSize(numberOfItems);
+  }
+
+  @Test
+  public void testPaginationForListTables() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    catalog.createNamespace(Namespace.of(namespaceName));
+
+    // create several tables under namespace for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier tableIdentifier = TableIdentifier.of(namespaceName, tableName + i);
+      catalog.createTable(tableIdentifier, SCHEMA);
+    }
+
+    List<TableIdentifier> tables = catalog.listTables(Namespace.of(namespaceName));
+    assertThat(tables).hasSize(numberOfItems);

Review Comment:
   ```suggestion
       assertThat(catalog.listTables(Namespace.of(namespaceName))).hasSize(numberOfItems);
   ```



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,36 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));

Review Comment:
   same as above



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567734951


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -34,7 +34,7 @@ public class TestListNamespacesResponse extends RequestResponseTestBase<ListName
 
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
-    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]]}";
+    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";

Review Comment:
   Will fix this thanks



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581388814


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   will fix.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2027829487

   I just want to add a few high-level comments here:
   1. It looks like `pageSize` is currently required, but I believe the default should be that if it is not set, no pagination should be requested and all results are returned.  This is going to be the typical behavior for any REST catalog that does not support paging.
   2. If a REST server has a specific page limit, it should return that as part of the config route properties as an override.  Implementations may have different limits and we should not require users to configure the client to correspond to the limitations of the server.
   
   As a follow up to #2, it seems there may be a chase were some servers require pagination, so they will probably need to return a 400 BadRequest if a client is asking for all values in a request and the server requires they support pagination.


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1536646978


##########
core/src/main/java/org/apache/iceberg/rest/responses/ListNamespacesResponse.java:
##########
@@ -59,6 +68,7 @@ public static Builder builder() {
 
   public static class Builder {
     private final ImmutableList.Builder<Namespace> namespaces = ImmutableList.builder();
+    private String nextPageToken = null;

Review Comment:
   will add



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1520289302


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +229,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    String restPaginationEnabledValue = mergedProps.get(REST_PAGINATION_ENABLED);

Review Comment:
   @geruh @jackye1995 @nastra 
   
   Thanks for taking a look, I think its fine to remove the `REST_PAGINATION_ENABLED` flag.
   
    Im not sure though why we have to remove the configuration `REST_PAGE_SIZE` as how does the client (configure their engine such as spark) to set `pageSize` correctly?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1538216438


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -114,6 +114,9 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private static final String DEFAULT_FILE_IO_IMPL = "org.apache.iceberg.io.ResolvingFileIO";
   private static final String REST_METRICS_REPORTING_ENABLED = "rest-metrics-reporting-enabled";
   private static final String REST_SNAPSHOT_LOADING_MODE = "snapshot-loading-mode";
+  public static final String REST_PAGINATION_ENABLED = "rest-pagination-enabled";

Review Comment:
   (just noticed others made the same comments below)



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1538536990


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -114,6 +114,9 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private static final String DEFAULT_FILE_IO_IMPL = "org.apache.iceberg.io.ResolvingFileIO";
   private static final String REST_METRICS_REPORTING_ENABLED = "rest-metrics-reporting-enabled";
   private static final String REST_SNAPSHOT_LOADING_MODE = "snapshot-loading-mode";
+  public static final String REST_PAGINATION_ENABLED = "rest-pagination-enabled";

Review Comment:
   Thanks @danielcweeks for taking a look. I have removed the `REST_PAGINATION_ENABLED` but I think we still need a configuration for the `REST_PAGE_SIZE`. Let me know if you also think we do not require this configuration.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2019317801

   @jackye1995 @danielcweeks @nastra If you can take a look at the revision for this whenever you guys get a chance would be appreciated. 


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566933302


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -34,7 +34,7 @@ public class TestListNamespacesResponse extends RequestResponseTestBase<ListName
 
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
-    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]]}";
+    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";

Review Comment:
   for now I think we don't need to do anything other than adding `"next-page-token":null` to the expected json (as you've already done that). 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567077122


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -1796,6 +1799,48 @@ public void testCatalogExpiredBearerTokenIsRefreshedWithCredential(String oauth2
             any());
   }
 
+
+  @Test
+  public void testCatalogWithPagaintionTokenIssue() {
+    //TODO remove this test, Used to highlight issue with namespaces

Review Comment:
   alternatively you can also add the mockito verifications on `adapter` to the other tests that you added (`testPaginationForListNamespaces()` / `testPaginationForListTables()` / `testPaginationForListViews()`)



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566944912


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,36 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    String viewName = "newview";
+
+    // create initial namespace
+    catalog().createNamespace(Namespace.of(namespaceName));
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from " + namespaceName + "." + tableName)

Review Comment:
   ```suggestion
             .withQuery("spark", "select * from ns.tbl")
   ```
   
   and then you can remove the `tableName` variable



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1569180280


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,120 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566941917


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -105,9 +105,32 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid table identifier: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() throws JsonProcessingException {
+    String jsonWithNullPageToken =
+        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}],\"next-page-token\":null}";
+    ListTablesResponse response =
+        ListTablesResponse.builder().addAll(IDENTIFIERS).nextPageToken(null).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithNullPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.identifiers()).isEqualTo(IDENTIFIERS);
+  }
+
+  @Test
+  public void testWithPaginationToken() throws JsonProcessingException {
+    String pageToken = "token";
+    String jsonWithPageToken =
+        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}],\"next-page-token\":\"token\"}";
+    ListTablesResponse response =
+        ListTablesResponse.builder().addAll(IDENTIFIERS).nextPageToken(pageToken).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNotNull();

Review Comment:
   ```suggestion
       Assertions.assertThat(response.nextPageToken()).isEqualTo("token");
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567967116


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -1796,6 +1799,48 @@ public void testCatalogExpiredBearerTokenIsRefreshedWithCredential(String oauth2
             any());
   }
 
+
+  @Test
+  public void testCatalogWithPagaintionTokenIssue() {
+    //TODO remove this test, Used to highlight issue with namespaces

Review Comment:
   Will fix this, either by modifying the other tests i created or create a new test



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1544047140


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -105,6 +105,14 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid table identifier: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() {

Review Comment:
   Will fix this.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1556366558


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -274,14 +277,34 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();

Review Comment:
   I feel like this could be consolidated using a `do ... while (...)` since we always need to make a single call.  That might simplify and prevent having two separate call paths.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1561341671


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   you can basically look at any of the tests that uses `Mockito.verify`. Those tests verify that a particular request with specific headers/params/x is being sent  (and so on). One example would be `testCatalogExpiredBearerTokenIsRefreshedWithCredential()`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1571188458


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,119 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/namespaces"),
+            any(),

Review Comment:
   will fix this
   
   @nastra Update: So when trying to verify the following `eq(ImmutableMap.of("pageToken", "", "pageSize", "10)` I  was running into issues as the endpoint as the list namespaces is called twice and was hitting a `TooManyActualInvocations`.
   
    Once i changed this to `Mockito.verify(adapter, times(numberOfInvocations))` im unable to verify the first param request, as it hits this last `eq(ImmutableMap.of("pageToken", "10", "pageSize", "10"))`. 
   
   When i changed to the following was able to get the test to pass
   ```
       Mockito.verify(adapter, times(numberOfInvocations))
           .execute(
               eq(HTTPMethod.GET),
               eq("v1/namespaces"),
               eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),
               any(),
               eq(ListNamespacesResponse.class),
               any(),
               any());
   ```
   
   Ive also tried called mockito.verify in two seperate calls similar to what we do in a test like `testCatalogTokenRefresh` but was not able to get this to work for similar reasons, either due to `TooManyActualInvocations` or due to arguments not expected 
   ```
   Argument(s) are different! Wanted:
   rESTCatalogAdapter.execute(
       GET,
       "v1/namespaces",
       {"pageToken" = "", "pageSize" = "10"},
       <any>,
       class org.apache.iceberg.rest.responses.ListNamespacesResponse,
       <any>,
       <any>
   );
   ```
   Any suggestions/thoughts on this?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1580469059


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +157,65 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+    String viewName = "newview";
+
+    // create initial namespace
+    catalog().createNamespace(Namespace.of(namespaceName));
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from ns.tbl")
+          .create();
+    }
+    List<TableIdentifier> views = catalog.listViews(Namespace.of(namespaceName));
+    assertThat(views).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            any(),
+            any(),
+            eq(LoadViewResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),

Review Comment:
   @nastra I am able to make two separate requests with `.handleRequest` instead of `execute`, and send the correct query params for each call, updated the pr with this change



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1585614340


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -136,6 +137,7 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private FileIO io = null;
   private MetricsReporter reporter = null;
   private boolean reportingViaRestEnabled;
+  private String restPageSize = null;

Review Comment:
   will fix



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1587205432


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -136,6 +137,7 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private FileIO io = null;
   private MetricsReporter reporter = null;
   private boolean reportingViaRestEnabled;
+  private Integer restPageSize = null;

Review Comment:
   nit: I think we can omit `rest` from the name



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559623826


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   I feel like there should be a test that verifies that the respective endpoint was called X times with the correct page token in the query params. We have plenty of tests in `TestRESTCatalog` that do something similar to this, so you could take a look at those as a reference for how to add such a test when doing pagination for namespaces/tables/views



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500369207


##########
core/src/main/java/org/apache/iceberg/rest/responses/ListTablesResponse.java:
##########
@@ -60,6 +69,7 @@ public static Builder builder() {
 
   public static class Builder {
     private final ImmutableList.Builder<TableIdentifier> identifiers = ImmutableList.builder();
+    private String nextPageToken = null;

Review Comment:
   I think this also needs a builder method so that this token can actually be configured



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1557801099


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -105,6 +105,23 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid table identifier: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() {
+    ListTablesResponse response =
+        ListTablesResponse.builder().addAll(IDENTIFIERS).nextPageToken(null).build();
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.identifiers()).isEqualTo(IDENTIFIERS);
+  }
+
+  @Test
+  public void testWithPaginationToken() {

Review Comment:
   this should also do a JSON round-trip check similar to `testRoundTripSerDe()`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1557807369


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +226,7 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = mergedProps.get(REST_PAGE_SIZE);

Review Comment:
   @rahil-c please also add a test that verifies this behavior



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1546625002


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   @danielcweeks Can you elaborate on what you mean by prefetching? Did you want the client to retrieve all the paginated results from the service in one go ( by repeatedly sending requests until `next-page-token` is `null`)?
   
   I had this before:
   
   ```
    List<Namespace> namespaces = Lists.newArrayList();
         String pageToken = "";
         queryParams.put("pageSize", restPageSize);
    
         while (pageToken != null) {
           queryParams.put("pageToken", pageToken);
           LOG.error("Sending list namespaces request");
           ListNamespacesResponse response =
                   client.get(
                           paths.namespaces(),
                           queryParams,
                           ListNamespacesResponse.class,
                           headers(context),
                           ErrorHandlers.namespaceErrorHandler());
           pageToken = response.nextPageToken();
           namespaces.addAll(response.namespaces());
         }
   ```
   
    but i think the other reviewers of the pr mentioned that we want to do lazily loading of the results, and shared this `PaginatedList` as an idea https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/PaginatedList.html which is what i tried following. 
   
   
   
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1575784851


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +157,65 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+    String viewName = "newview";
+
+    // create initial namespace
+    catalog().createNamespace(Namespace.of(namespaceName));
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from ns.tbl")
+          .create();
+    }
+    List<TableIdentifier> views = catalog.listViews(Namespace.of(namespaceName));
+    assertThat(views).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            any(),
+            any(),
+            eq(LoadViewResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),

Review Comment:
   rather than verifying that there have been `numberOfInvocations` where `pageToken` / `pageSize` are 10, I think there should be a separate check where `pageToken = ""`/ `pageSize = "10"`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1568398951


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,120 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+

Review Comment:
   nit: unnecessary newline



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558712520


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);

Review Comment:
   > Shouldn't we only set pageSize if it's set?
   
   Im not sure I fully understand, I think this check `restPageSize != null` is checking if there is a value for `restPageSize`, and if so then we add pageSize to the query param map. 
   
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1561347274


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   Thanks



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   Thanks



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2087717449

   @danielcweeks @nastra Have made recent revisions, hoping we can land this if no other concerns and if CI run is green.


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1568086253


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -1796,6 +1799,48 @@ public void testCatalogExpiredBearerTokenIsRefreshedWithCredential(String oauth2
             any());
   }
 
+
+  @Test
+  public void testCatalogWithPagaintionTokenIssue() {
+    //TODO remove this test, Used to highlight issue with namespaces

Review Comment:
   @nastra Have made the revisions to use mockito within 
   ```
   (testPaginationForListNamespaces() / testPaginationForListTables() / testPaginationForListViews()
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1570117531


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,119 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/namespaces"),
+            any(),

Review Comment:
   I think we should actually make sure that this is called with 
   * `eq(ImmutableMap.of("pageToken", "", "pageSize", "10")),`
   * `eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1571188458


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,119 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/namespaces"),
+            any(),

Review Comment:
   will fix this
   
   Update: So when trying to verify the following `eq(ImmutableMap.of("pageToken", "", "pageSize", "10)` I  was running into issues as the endpoint as the list namespaces is called twice and was hitting a `TooManyActualInvocations`.
   
    Once i changed this to `Mockito.verify(adapter, times(numberOfInvocations))` im unable to verify the first param request, as it hits this last `eq(ImmutableMap.of("pageToken", "10", "pageSize", "10"))`. 
   
   When i changed to the following was able to get the test to pass
   ```
       Mockito.verify(adapter, times(numberOfInvocations))
           .execute(
               eq(HTTPMethod.GET),
               eq("v1/namespaces"),
               eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),
               any(),
               eq(ListNamespacesResponse.class),
               any(),
               any());
   ```
   
   Ive also tried called mockito.verify in two seperate calls similar to what we do in a test like `testCatalogTokenRefresh` but was not able to get this to work for similar reasons, either due to `TooManyActualInvocations` or due to arguments not expected 
   ```
   Argument(s) are different! Wanted:
   rESTCatalogAdapter.execute(
       GET,
       "v1/namespaces",
       {"pageToken" = "", "pageSize" = "10"},
       <any>,
       class org.apache.iceberg.rest.responses.ListNamespacesResponse,
       <any>,
       <any>
   );
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567853170


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -83,9 +83,32 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid namespace: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() throws JsonProcessingException {
+    String jsonWithNullPageToken =
+        "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";
+    ListNamespacesResponse response =
+        ListNamespacesResponse.builder().addAll(NAMESPACES).nextPageToken(null).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithNullPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.namespaces()).isEqualTo(NAMESPACES);
+  }
+
+  @Test
+  public void testWithPaginationToken() throws JsonProcessingException {
+    String pageToken = "token";
+    String jsonWithPageToken =
+        "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":\"token\"}";
+    ListNamespacesResponse response =
+        ListNamespacesResponse.builder().addAll(NAMESPACES).nextPageToken(pageToken).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNotNull();

Review Comment:
   will fix



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566583155


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -34,7 +34,7 @@ public class TestListNamespacesResponse extends RequestResponseTestBase<ListName
 
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
-    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]]}";
+    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";

Review Comment:
   @nastra Yea I think i see what you mean now, the test calls this at the end
   ```
     protected void assertRoundTripSerializesEquallyFrom(String json, T expected)
         throws JsonProcessingException {
       // Check that the JSON deserializes into the expected value;
       T actual = deserialize(json);
       assertEquals(actual, expected);
   
       // Check that the deserialized value serializes back into the original JSON
       Assertions.assertThat(serialize(expected)).isEqualTo(json);
     }
   ```
   
   The issue seems to be occuring at this `Assertions.assertThat(serialize(expected)).isEqualTo(json);` since when we call the `serialize(expected)`  it does not go back to the original string json `"{"identifiers":[{"namespace":["accounting","tax"],"name":"paid"}]}"`  and instead takes the shape of the ListNameSpacesResponse(which now has the nextPageToken field).
   
   Im not sure what we can do here besides either modify the json the test expects, or we need to to add another ListNameSpacesResponse class that contains a page token field(which seems not ideal)?
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566934826


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(

Review Comment:
   ```suggestion
      Assertions.assertThatThrownBy(
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567748849


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(

Review Comment:
   will fix 



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results).hasSize(numberOfItems);

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500378492


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1045,6 +1094,27 @@ public void commitTransaction(SessionContext context, List<TableCommit> commits)
   public List<TableIdentifier> listViews(SessionContext context, Namespace namespace) {
     checkNamespaceIsValid(namespace);
 
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (restPaginationEnabled) {
+      List<TableIdentifier> identifiers = Lists.newArrayList();
+      String pageToken = "";
+      queryParams.put("pageSize", restPageSize);
+
+      while (pageToken != null) {

Review Comment:
   +1



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "jackye1995 (via GitHub)" <gi...@apache.org>.
jackye1995 commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1499966845


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +229,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    String restPaginationEnabledValue = mergedProps.get(REST_PAGINATION_ENABLED);

Review Comment:
   Similar comment for pageSize, do we really need to expose configuration of this value in the library integration?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500365522


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +229,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    String restPaginationEnabledValue = mergedProps.get(REST_PAGINATION_ENABLED);

Review Comment:
   I agree that we don't need this flag



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500368758


##########
core/src/main/java/org/apache/iceberg/rest/responses/ListTablesResponse.java:
##########
@@ -30,13 +30,15 @@
 public class ListTablesResponse implements RESTResponse {

Review Comment:
   please also add some tests to `TestListTablesResponse` where the `nextPageToken` is set to `null` / `-1` / ...



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1536645727


##########
core/src/main/java/org/apache/iceberg/rest/responses/ListTablesResponse.java:
##########
@@ -30,13 +30,15 @@
 public class ListTablesResponse implements RESTResponse {

Review Comment:
   will add



##########
core/src/main/java/org/apache/iceberg/rest/responses/ListTablesResponse.java:
##########
@@ -60,6 +69,7 @@ public static Builder builder() {
 
   public static class Builder {
     private final ImmutableList.Builder<TableIdentifier> identifiers = ImmutableList.builder();
+    private String nextPageToken = null;

Review Comment:
   will add



##########
core/src/main/java/org/apache/iceberg/rest/responses/ListNamespacesResponse.java:
##########
@@ -29,13 +29,15 @@
 public class ListNamespacesResponse implements RESTResponse {
 
   private List<Namespace> namespaces;
+  private String nextPageToken;

Review Comment:
   will add



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1520289302


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +229,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    String restPaginationEnabledValue = mergedProps.get(REST_PAGINATION_ENABLED);

Review Comment:
   @geruh @jackye1995 @nastra @rdblue 
   
   Thanks for taking a look, I think its fine to remove the `REST_PAGINATION_ENABLED` flag.
   
    Im not sure though why we have to remove the configuration `REST_PAGE_SIZE` as how does the client (configure their engine such as spark) to set `pageSize` correctly?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1587974890


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -494,22 +515,30 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    }

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1569192411


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,120 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    Map<String, String> queryParams = ImmutableMap.of("pageToken", "", "pageSize", "10");
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter)

Review Comment:
   Thanks @nastra for catching this and also for the code pointers and suggestions appreciate the help. Will take a look at this and make the revision today.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1568415371


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,120 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    Map<String, String> queryParams = ImmutableMap.of("pageToken", "", "pageSize", "10");
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter)

Review Comment:
   this only tests the initial request with `pageSize = 10` and `pageToken = ""`. Since there's no server-side handling in `RESTCatalogAdapter` / `CatalogHandlers`, the server always responds with all namespaces, thus ignoring the pagination and not returning `next-page-token` in the response. 
   
   `CatalogHandlers` can be seen as a reference implementation for how the behavior would be done on the server-side, so I believe we also need to update `RESTCatalogAdapter` / `CatalogHandlers`. So you would probably need something similar to
   ```
   diff --git a/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java b/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java
   index e4e3c065f..8ce73784a 100644
   --- a/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java
   +++ b/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java
   @@ -117,6 +117,21 @@ public class CatalogHandlers {
        return ListNamespacesResponse.builder().addAll(results).build();
      }
    
   +  public static ListNamespacesResponse listNamespaces(
   +          SupportsNamespaces catalog, Namespace parent, String pageToken, Integer pageSize) {
   +    List<Namespace> results;
   +    if (parent.isEmpty()) {
   +      results = catalog.listNamespaces();
   +    } else {
   +      results = catalog.listNamespaces(parent);
   +    }
   +
   +    // only return subResults to match pageToken/pageSize
   +    subResults = results.subList(from, to)
   +
   +    return ListNamespacesResponse.builder().addAll(subResults).nextPageToken(...).build();
   +  }
   +
   ```
   ```
   diff --git a/core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java b/core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java
   index 7fccc4e97..6c6fa061b 100644
   --- a/core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java
   +++ b/core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java
   @@ -298,7 +298,17 @@ public class RESTCatalogAdapter implements RESTClient {
                ns = Namespace.empty();
              }
    
   -          return castResponse(responseType, CatalogHandlers.listNamespaces(asNamespaceCatalog, ns));
   +          String pageToken = PropertyUtil.propertyAsString(vars, "pageToken", null);
   +          Integer pageSize = PropertyUtil.propertyAsNullableInt(vars, "pageSize");
   +
   +          if (null != pageSize) {
   +            return castResponse(
   +                responseType,
   +                CatalogHandlers.listNamespaces(asNamespaceCatalog, ns, pageToken, pageSize));
   +          } else {
   +            return castResponse(
   +                responseType, CatalogHandlers.listNamespaces(asNamespaceCatalog, ns));
   +          }
            }
            break;
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567854386


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -105,9 +105,32 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid table identifier: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() throws JsonProcessingException {
+    String jsonWithNullPageToken =
+        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}],\"next-page-token\":null}";
+    ListTablesResponse response =
+        ListTablesResponse.builder().addAll(IDENTIFIERS).nextPageToken(null).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithNullPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.identifiers()).isEqualTo(IDENTIFIERS);
+  }
+
+  @Test
+  public void testWithPaginationToken() throws JsonProcessingException {
+    String pageToken = "token";
+    String jsonWithPageToken =
+        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}],\"next-page-token\":\"token\"}";
+    ListTablesResponse response =
+        ListTablesResponse.builder().addAll(IDENTIFIERS).nextPageToken(pageToken).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNotNull();

Review Comment:
   will fix



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558551506


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   I don't think we're updating the `pageToken` value properly for subsequent requests.  We capture it here, but it needs to be set as the query param for the next invocation.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558549404


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);

Review Comment:
   Shouldn't we only set `pageSize` if it's set?  This would result in an empty query param being sent and I don't think  we describe that behavior.  I would expect we omit the param since the server can also manage page size just through the opaque `pageToken`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1556425249


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -274,14 +277,34 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();

Review Comment:
   Sure will fix this.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560470048


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   @nastra do have a specific example of which test in `TestRESTCatalog` does this?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566583155


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -34,7 +34,7 @@ public class TestListNamespacesResponse extends RequestResponseTestBase<ListName
 
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
-    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]]}";
+    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";

Review Comment:
   Yea I think i see what you mean now, the test calls this at the end
   ```
     protected void assertRoundTripSerializesEquallyFrom(String json, T expected)
         throws JsonProcessingException {
       // Check that the JSON deserializes into the expected value;
       T actual = deserialize(json);
       assertEquals(actual, expected);
   
       // Check that the deserialized value serializes back into the original JSON
       Assertions.assertThat(serialize(expected)).isEqualTo(json);
     }
   ```
   
   The issue seems to be occuring at this `Assertions.assertThat(serialize(expected)).isEqualTo(json);` since when we call the `serialize(expected)`  it does not go back to the original string json `"{"identifiers":[{"namespace":["accounting","tax"],"name":"paid"}]}"`  and instead takes the shape of the ListNameSpacesResponse(which now has the nextPageToken field).
   
   Im not sure what we can do here besides either modify the json the test expects, or we need to to add another ListNameSpacesResponse class that contains a page token field(which seems not ideal)?
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566713074


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   @nastra I was wondering if I get your thoughts on this issue I have been seeing with the tests that leverage `Mockito.verify`. For demo purposes I added a test called `testCatalogWithPagaintionTokenIssue` which is basically similar to the test you mentioned above but i haved added this snippet, hitting the list namespaces endpoint
   ```
   Mockito.verify(adapter)
               .execute(
                       eq(HTTPMethod.GET),
                       eq("v1/namespaces"),
                       any(),
                       any(),
                       eq(ListNamespacesResponse.class),
                       eq(catalogHeaders),
                       any());
   ```
   
   This test however always fail for the following exception
   ```
   Wanted but not invoked:
   rESTCatalogAdapter.execute(
       GET,
       "v1/namespaces",
       <any>,
       <any>,
       class org.apache.iceberg.rest.responses.ListNamespacesResponse,
       {"Authorization" = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE5OTk5OTk5OTk5fQ._3k92KJi2NTyTG6V1s2mzJ__GiQtL36DnzsZSkBdYPw"},
       <any>
   );
   -> at org.apache.iceberg.rest.RESTCatalogAdapter.execute(RESTCatalogAdapter.java:517)
   
   However, there were exactly 4 interactions with this mock:
   ```
   
   When i setup a debugger, for some reason when it goes into the `RestCatalogAdapater.execute` it does not recognize any params of the function and then errors out. Any thoughts on how to get past this?
   ```
   public <T extends RESTResponse> T execute(
         HTTPMethod method,
         String path,
         Map<String, String> queryParams,
         Object body,
         Class<T> responseType,
         Map<String, String> headers,
         Consumer<ErrorResponse> errorHandler) {
       ErrorResponse.Builder errorBuilder = ErrorResponse.builder();
   
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566937039


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results).hasSize(numberOfItems);

Review Comment:
   nit: can be inlined
   ```suggestion
       assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1550695864


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   @danielcweeks @sachet Have done a revision for this using the loop approach if you can take a look whenever would be ideal. 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1544946200


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -114,6 +114,9 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private static final String DEFAULT_FILE_IO_IMPL = "org.apache.iceberg.io.ResolvingFileIO";
   private static final String REST_METRICS_REPORTING_ENABLED = "rest-metrics-reporting-enabled";
   private static final String REST_SNAPSHOT_LOADING_MODE = "snapshot-loading-mode";
+  public static final String REST_PAGINATION_ENABLED = "rest-pagination-enabled";

Review Comment:
   @rdblue  @danielcweeks we had a sync, and just wanted to confirm if we wanted to have this `REST_PAGE_SIZE` as configurable from the client side or have the server return back an optimal number for what `pageSize` should be?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558181883


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2288,6 +2289,34 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testPaginationForListApis() {

Review Comment:
   will fix and add test in `TestRESTViewCatalog`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560030414


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +226,7 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = mergedProps.get(REST_PAGE_SIZE);

Review Comment:
   Will do so 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1570124615


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -117,6 +118,29 @@ public static ListNamespacesResponse listNamespaces(
     return ListNamespacesResponse.builder().addAll(results).build();
   }
 
+  public static ListNamespacesResponse listNamespaces(
+      SupportsNamespaces catalog, Namespace parent, String pageToken, String pageSize) {
+    List<Namespace> results;
+    List<Namespace> subResults;
+
+    if (parent.isEmpty()) {
+      results = catalog.listNamespaces();
+    } else {
+      results = catalog.listNamespaces(parent);
+    }
+
+    int start = pageToken.equals(INTIAL_PAGE_TOKEN) ? 0 : Integer.parseInt(pageToken);

Review Comment:
   ```suggestion
       int start = INTIAL_PAGE_TOKEN.equals(pageToken) ? 0 : Integer.parseInt(pageToken);
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1571017091


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -117,6 +118,29 @@ public static ListNamespacesResponse listNamespaces(
     return ListNamespacesResponse.builder().addAll(results).build();
   }
 
+  public static ListNamespacesResponse listNamespaces(
+      SupportsNamespaces catalog, Namespace parent, String pageToken, String pageSize) {
+    List<Namespace> results;
+    List<Namespace> subResults;
+
+    if (parent.isEmpty()) {
+      results = catalog.listNamespaces();
+    } else {
+      results = catalog.listNamespaces(parent);
+    }
+
+    int start = pageToken.equals(INTIAL_PAGE_TOKEN) ? 0 : Integer.parseInt(pageToken);

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1585624769


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   Will fix thanks



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581204955


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,129 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;

Review Comment:
   Will do so thanks man 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581389185


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -494,22 +514,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
     }
+    List<Namespace> namespaces = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageSize", restPageSize);
+    }

Review Comment:
   will fix



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1580993539


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,129 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;

Review Comment:
   I would probably increase this to 30 and then add one additional check below with pageToken=20 / pageSize=10 just so that we don't hide any potential bugs. Same for the other pagination tests



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581591136


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,129 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;

Review Comment:
   have added this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1499894821


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -490,12 +522,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    }
+    if (restPaginationEnabled) {
+      List<Namespace> namespaces = Lists.newArrayList();
+      String pageToken = "";
+      queryParams.put("pageSize", restPageSize);
+
+      while (pageToken != null) {
+        queryParams.put("pageToken", pageToken);
+        LOG.error("Sending list namespaces request");

Review Comment:
   Need to remove this 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "jackye1995 (via GitHub)" <gi...@apache.org>.
jackye1995 commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1499965680


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -224,6 +229,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    String restPaginationEnabledValue = mergedProps.get(REST_PAGINATION_ENABLED);

Review Comment:
   +1, I think we don't need the feature flag. 
   
   I see the pagination configs more for raw API usages (e.g. UI displaying list of namespaces, tables, etc.).



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2091882544

   > Approved, pending checks. There's one that failed, but may have been a transient failure.
   
   @danielcweeks yea I think it is transient, since every time I go to check this link it still keeps running.


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2091881609

   Approved, pending checks.  There's one that failed, but may have been a transient failure.


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1587205432


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -136,6 +137,7 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog
   private FileIO io = null;
   private MetricsReporter reporter = null;
   private boolean reportingViaRestEnabled;
+  private Integer restPageSize = null;

Review Comment:
   nit: I think we can omit `rest` from the name and just name it `pageSize`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1538538607


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -490,12 +522,29 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {

Review Comment:
   I have some questions for this, will reach out over iceberg slack.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567730841


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   Will take a look thanks and fix this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566939429


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));

Review Comment:
   no need for `Mockito.spy()` here as you're not doing any verifications on the `adapter` in this test (and in the other tests)



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results).hasSize(numberOfItems);
+  }
+
+  @Test
+  public void testPaginationForListTables() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));

Review Comment:
   same as above



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566946785


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -1796,6 +1799,48 @@ public void testCatalogExpiredBearerTokenIsRefreshedWithCredential(String oauth2
             any());
   }
 
+
+  @Test
+  public void testCatalogWithPagaintionTokenIssue() {
+    //TODO remove this test, Used to highlight issue with namespaces

Review Comment:
   I don't think we should remove this test. We actually want a test that makes sure we get the expected behavior



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1580983794


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   we should probably use a builder to have a `ImmutableList` here and in the other places



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581390737


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,129 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581590662


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   Actually when using `ImmutableList` I get the following exception, so not sure if this is ideal
   ```
   RESTSessionCatalog.java:305: error: [DoNotCall] This method should not be called: Always throws UnsupportedOperationException
         tables.addAll(response.identifiers());
                      ^
       (see https://errorprone.info/bugpattern/DoNotCall)
   ```
   I see that in other areas in the `RESTSessionCatalog` that we do initialize `List` like so, so think keeping this line should be fine?
   ```
       private final List<ViewRepresentation> representations = Lists.newArrayList();
   
       List<UpdateTableRequest> tableChanges = Lists.newArrayListWithCapacity(commits.size());
   
   ```
   



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   will fix.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1581590662


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   Actually when using `ImmutableList` I get the following exception, so not sure if this is ideal
   ```
   RESTSessionCatalog.java:305: error: [DoNotCall] This method should not be called: Always throws UnsupportedOperationException
         tables.addAll(response.identifiers());
                      ^
       (see https://errorprone.info/bugpattern/DoNotCall)
   ```
   I see that in other areas in the `RESTSessionCatalog` that we do initialize `List` like so, so I think keeping this line should be fine, unless you see some concerns with this?
   ```
       private final List<ViewRepresentation> representations = Lists.newArrayList();
   
       List<UpdateTableRequest> tableChanges = Lists.newArrayListWithCapacity(commits.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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1584794537


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();

Review Comment:
   > I think he was recommending something like:
   > 
   > ```java
   > ImmutableList.Builder<TableIdentifier> result = ImmutableList.<TableIdentifier>builder();
   > 
   > return result.build();
   > ```
   
   Yep that's exactly what I meant



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2093492003

   Thanks @nastra and @danielcweeks for the help on this!


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1587206338


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -228,6 +230,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = PropertyUtil.propertyAsNullableInt(mergedProps, REST_PAGE_SIZE);
+    if (restPageSize != null) {
+      Preconditions.checkArgument(
+          restPageSize > 0, "Invalid value for pageSize, must be a positive integer");

Review Comment:
   ```suggestion
             restPageSize > 0, "Invalid value for %s, must be a positive integer", REST_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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1548945175


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   To clarify my comment, I think there are really two issues:
   
   1) The current implementation does not properly adhere to the List behaviors.  The dynamodb example that's referenced will eagerly fetch if certain methods are called, which is necessary to get the correct behavior out of the List interface.  
   
   2) The second issue is more about the utility of a lazy pagination since it seems the original motivation is more to address server side limitations (like Glue's 100 results per request limit) as opposed to a client side memory limitation.  While you might be able to optimize something like the `SHOW TABLES LIKE` command client-side, we haven't see the client-side as the limiting factor.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1546625002


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   @danielcweeks Can you elaborate on what you mean by prefetching? Did you want to the client to retrieve all the paginated results from the service in one go ( by repeatedly sending requests until `next-page-token` is `null`)?
   
   I had this before:
   
   ```
    List<Namespace> namespaces = Lists.newArrayList();
         String pageToken = "";
         queryParams.put("pageSize", restPageSize);
    
         while (pageToken != null) {
           queryParams.put("pageToken", pageToken);
           LOG.error("Sending list namespaces request");
           ListNamespacesResponse response =
                   client.get(
                           paths.namespaces(),
                           queryParams,
                           ListNamespacesResponse.class,
                           headers(context),
                           ErrorHandlers.namespaceErrorHandler());
           pageToken = response.nextPageToken();
           namespaces.addAll(response.namespaces());
         }
   ```
   
    but i think the other reviewers of the pr mentioned that we want to do lazily loading of the results, and shared this `PaginatedList` as an idea https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/PaginatedList.html which is what i tried following. 
   
   
   
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559605425


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2330,46 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testPaginationForListNameSpaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results.size()).isEqualTo(numberOfItems);

Review Comment:
   ```suggestion
       assertThat(results).hasSize(numberOfItems);
   ```
   
   same for other assertions



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559602390


##########
core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java:
##########
@@ -68,7 +68,7 @@
 import org.junit.jupiter.api.Test;
 
 public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
-  protected static final Namespace NS = Namespace.of("newdb");
+  private static final Namespace NS = Namespace.of("newdb");

Review Comment:
   seems like an unrelated change



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559607741


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,39 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    String viewName = "newview";
+
+    TableIdentifier tableIdentifier = TableIdentifier.of(namespaceName, tableName);
+
+    // create initial namespace and table
+    catalog().createNamespace(tableIdentifier.namespace());
+    tableCatalog().buildTable(tableIdentifier, SCHEMA).create();

Review Comment:
   we don't need to create the table. The query of the view can just have a random SQL



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1557169245


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2288,6 +2289,34 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testPaginationForListApis() {

Review Comment:
   I think this should be testing pagination for namespaces and tables separately. Additionally, we need to test pagination of views in `TestRESTViewCatalog`



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560093868


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,39 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    String viewName = "newview";
+
+    TableIdentifier tableIdentifier = TableIdentifier.of(namespaceName, tableName);
+
+    // create initial namespace and table
+    catalog().createNamespace(tableIdentifier.namespace());
+    tableCatalog().buildTable(tableIdentifier, SCHEMA).create();

Review Comment:
   will fix 



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +151,39 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    String viewName = "newview";
+
+    TableIdentifier tableIdentifier = TableIdentifier.of(namespaceName, tableName);
+
+    // create initial namespace and table
+    catalog().createNamespace(tableIdentifier.namespace());
+    tableCatalog().buildTable(tableIdentifier, SCHEMA).create();
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from " + namespaceName + "." + tableName)
+          .create();
+    }
+
+    List<TableIdentifier> views = catalog.listViews(Namespace.of(namespaceName));
+    assertThat(views.size()).isEqualTo(numberOfItems);

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560187545


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -34,7 +34,7 @@ public class TestListNamespacesResponse extends RequestResponseTestBase<ListName
 
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
-    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]]}";
+    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";

Review Comment:
   One issue though is that since we have changed the `ListNamespaceResponse` to now include `next-page-token` which if not set by the server, will be `null`, and included in the `toString` representation.
   
   ```
     public String nextPageToken() {
       return nextPageToken;
     }
   
     @Override
     public String toString() {
       return MoreObjects.toStringHelper(this)
           .add("namespaces", namespaces())
           .add("next-page-token", nextPageToken())
           .toString();
     }
   
   ```
   Thus when running these `testRoundTripSerDe` tests they will fail, as they will have the `next-page-token` in them.
   ```
   Expected :"{"identifiers":[{"namespace":["accounting","tax"],"name":"paid"}]}"
   Actual   :"{"identifiers":[{"namespace":["accounting","tax"],"name":"paid"}],"next-page-token":null}"
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "jackye1995 (via GitHub)" <gi...@apache.org>.
jackye1995 commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1499968208


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1045,6 +1094,27 @@ public void commitTransaction(SessionContext context, List<TableCommit> commits)
   public List<TableIdentifier> listViews(SessionContext context, Namespace namespace) {
     checkNamespaceIsValid(namespace);
 
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (restPaginationEnabled) {
+      List<TableIdentifier> identifiers = Lists.newArrayList();
+      String pageToken = "";
+      queryParams.put("pageSize", restPageSize);
+
+      while (pageToken != null) {

Review Comment:
   I think we should not run the full execution in a loop directly. We should lazily load the list, something like https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/PaginatedList.html



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1500371045


##########
core/src/main/java/org/apache/iceberg/rest/responses/ListNamespacesResponse.java:
##########
@@ -59,6 +68,7 @@ public static Builder builder() {
 
   public static class Builder {
     private final ImmutableList.Builder<Namespace> namespaces = ImmutableList.builder();
+    private String nextPageToken = null;

Review Comment:
   this would require a builder method so that the value can be set



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#issuecomment-2035897279

   > I just want to add a few high-level comments here:
   > 
   > 1. It looks like `pageSize` is currently required, but I believe the default should be that if it is not set, no pagination should be requested and all results are returned.  This is going to be the typical behavior for any REST catalog that does not support paging.
   > 2. If a REST server has a specific page limit, it should return that as part of the config route properties as an override.  Implementations may have different limits and we should not require users to configure the client to correspond to the limitations of the server.
   > 
   > As a follow up to #2, it seems there may be a chase were some servers require pagination, so they will probably need to return a 400 BadRequest if a client is asking for all values in a request and the server requires they support pagination.
   
   @danielcweeks @nastra @rdblue @jackye1995 
   Im curious for `2.` if this page limit is to be returned by the rest server, should this be apart of the capabilities pr? I think from the pr https://github.com/apache/iceberg/pull/9940 we did not want to have pagination listed there it seems but just wanted to bring this up.


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1561325160


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -34,7 +34,7 @@ public class TestListNamespacesResponse extends RequestResponseTestBase<ListName
 
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
-    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]]}";
+    String fullJson = "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";

Review Comment:
   `toString()` shouldn't matter when the object is serialized to JSON. I guess this is the downside of serializing to JSON via reflection (since we don't have a separate parser for this class to better control what we serialize/deserialize)



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1558704222


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);
+    }
+    do {
+      ListTablesResponse response =
+          client.get(
+              paths.tables(ns),
+              queryParams,
+              ListTablesResponse.class,
+              headers(context),
+              ErrorHandlers.namespaceErrorHandler());
+      pageToken = response.nextPageToken();

Review Comment:
   Will fix this, thanks for catching this.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1559612907


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -36,7 +36,7 @@ public class TestListTablesResponse extends RequestResponseTestBase<ListTablesRe
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
     String fullJson =
-        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}]}";
+        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"},\"next-page-token\":null]}";

Review Comment:
   same as previously mentioned



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560039876


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2330,46 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testPaginationForListNameSpaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results.size()).isEqualTo(numberOfItems);

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560038289


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2330,46 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testPaginationForListNameSpaces() {

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560187855


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListTablesResponse.java:
##########
@@ -36,7 +36,7 @@ public class TestListTablesResponse extends RequestResponseTestBase<ListTablesRe
   @Test
   public void testRoundTripSerDe() throws JsonProcessingException {
     String fullJson =
-        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}]}";
+        "{\"identifiers\":[{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"},\"next-page-token\":null]}";

Review Comment:
   have responded above.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1560180427


##########
core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java:
##########
@@ -68,7 +68,7 @@
 import org.junit.jupiter.api.Test;
 
 public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
-  protected static final Namespace NS = Namespace.of("newdb");
+  private static final Namespace NS = Namespace.of("newdb");

Review Comment:
   will remove 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566524213


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -278,14 +286,26 @@ public void setConf(Object newConf) {
   @Override
   public List<TableIdentifier> listTables(SessionContext context, Namespace ns) {
     checkNamespaceIsValid(ns);
+    Map<String, String> queryParams = Maps.newHashMap();
+    List<TableIdentifier> tables = Lists.newArrayList();
+    String pageToken = "";
+    if (restPageSize != null) {
+      queryParams.put("pageToken", pageToken);
+      queryParams.put("pageSize", restPageSize);

Review Comment:
   It looks like this was updated and is now set correctly.  Resolving.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1566941616


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestListNamespacesResponse.java:
##########
@@ -83,9 +83,32 @@ public void testBuilderDoesNotCreateInvalidObjects() {
         .hasMessage("Invalid namespace: null");
   }
 
+  @Test
+  public void testWithNullPaginationToken() throws JsonProcessingException {
+    String jsonWithNullPageToken =
+        "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":null}";
+    ListNamespacesResponse response =
+        ListNamespacesResponse.builder().addAll(NAMESPACES).nextPageToken(null).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithNullPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNull();
+    Assertions.assertThat(response.namespaces()).isEqualTo(NAMESPACES);
+  }
+
+  @Test
+  public void testWithPaginationToken() throws JsonProcessingException {
+    String pageToken = "token";
+    String jsonWithPageToken =
+        "{\"namespaces\":[[\"accounting\"],[\"tax\"]],\"next-page-token\":\"token\"}";
+    ListNamespacesResponse response =
+        ListNamespacesResponse.builder().addAll(NAMESPACES).nextPageToken(pageToken).build();
+    assertRoundTripSerializesEquallyFrom(jsonWithPageToken, response);
+    Assertions.assertThat(response.nextPageToken()).isNotNull();

Review Comment:
   ```suggestion
       Assertions.assertThat(response.nextPageToken()).isEqualTo("token");
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1545017898


##########
core/src/main/java/org/apache/iceberg/rest/PaginatedList.java:
##########
@@ -0,0 +1,269 @@
+/*
+ * 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.iceberg.rest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Supplier;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.Route;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PaginatedList<T> implements List<T> {

Review Comment:
   I have some concerns about the way we're implementing the pagination.  It doesn't appear like we're properly adhering to the List interface behavior.  For example, if we perform a `namespaces = catalog.listNamespaces(...)` and then check `namespaces.size()` we would get zero even if there are results.  Other methods like `contains` would appear to not have the right behavior either.
   
   Overall, it seems like we're trying to hide the pagination behind the List interface but not really getting the behavior we want.  We might want to consider just prefetching as it seems the primary limitation is expected to be on the server side (client will likely need to fit the whole result in memory anyway).  That may simplify this and not require the paginated list implementation.



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567071915


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -1796,6 +1799,48 @@ public void testCatalogExpiredBearerTokenIsRefreshedWithCredential(String oauth2
             any());
   }
 
+
+  @Test
+  public void testCatalogWithPagaintionTokenIssue() {
+    //TODO remove this test, Used to highlight issue with namespaces
+    String token =
+            "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE5OTk5OTk5OTk5fQ._3k92KJi2NTyTG6V1s2mzJ__GiQtL36DnzsZSkBdYPw";
+    Map<String, String> catalogHeaders = ImmutableMap.of("Authorization", "Bearer " + token);
+
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+
+    String credential = "catalog:12345";
+    Map<String, String> contextCredentials =
+            ImmutableMap.of("token", token, "credential", credential);
+    SessionCatalog.SessionContext context =
+            new SessionCatalog.SessionContext(
+                    UUID.randomUUID().toString(), "user", contextCredentials, ImmutableMap.of());
+
+    RESTCatalog catalog = new RESTCatalog(context, (config) -> adapter);
+    catalog.initialize("prod", ImmutableMap.of(CatalogProperties.URI, "ignored", "token", token));
+
+    Mockito.verify(adapter)
+            .execute(
+                    eq(HTTPMethod.GET),
+                    eq("v1/config"),
+                    any(),
+                    any(),
+                    eq(ConfigResponse.class),
+                    eq(catalogHeaders),
+                    any());
+
+    Mockito.verify(adapter)

Review Comment:
   @rahil-c this fails because you're verifying that the namespaces endpoint has been called but you're actually not calling `catalog.listNamespaces(..)` in this test



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1571188458


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,119 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/namespaces"),
+            any(),

Review Comment:
   will fix this
   
   @nastra Update: So when trying to verify the following `eq(ImmutableMap.of("pageToken", "", "pageSize", "10)` I  was running into issues as the endpoint as the list namespaces is called twice and was hitting a `TooManyActualInvocations`.
   
    Once i changed this to `Mockito.verify(adapter, times(numberOfInvocations))` im unable to verify the first param request, as it hits this last `eq(ImmutableMap.of("pageToken", "10", "pageSize", "10"))`. 
   
   When i changed to the following was able to get the test to pass
   ```
       Mockito.verify(adapter, times(numberOfInvocations))
           .execute(
               eq(HTTPMethod.GET),
               eq("v1/namespaces"),
               eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),
               any(),
               eq(ListNamespacesResponse.class),
               any(),
               any());
   ```
   
   Ive also tried called mockito.verify in two seperate calls similar to what we do in a test like `testCatalogTokenRefresh` but was not able to get this to work for similar reasons, either due to `TooManyActualInvocations` or due to arguments not expected 
   ```
   Argument(s) are different! Wanted:
   rESTCatalogAdapter.execute(
       GET,
       "v1/namespaces",
       {"pageToken" = "", "pageSize" = "10"},
       <any>,
       class org.apache.iceberg.rest.responses.ListNamespacesResponse,
       <any>,
       <any>
   );
   ```
   Any suggestions/thoughts?



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1567755548


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2374,57 @@ public void multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+            new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    org.assertj.core.api.Assertions.assertThatThrownBy(
+            () -> catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "-1")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    List<Namespace> results = catalog.listNamespaces();
+    assertThat(results).hasSize(numberOfItems);
+  }
+
+  @Test
+  public void testPaginationForListTables() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 100;
+    String namespaceName = "newdb";
+    String tableName = "newtable";
+    catalog.createNamespace(Namespace.of(namespaceName));
+
+    // create several tables under namespace for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier tableIdentifier = TableIdentifier.of(namespaceName, tableName + i);
+      catalog.createTable(tableIdentifier, SCHEMA);
+    }
+
+    List<TableIdentifier> tables = catalog.listTables(Namespace.of(namespaceName));
+    assertThat(tables).hasSize(numberOfItems);

Review Comment:
   will fix



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1587974593


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -228,6 +230,12 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = PropertyUtil.propertyAsNullableInt(mergedProps, REST_PAGE_SIZE);
+    if (restPageSize != null) {
+      Preconditions.checkArgument(
+          restPageSize > 0, "Invalid value for pageSize, must be a positive integer");

Review Comment:
   will fix 



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra merged PR #9782:
URL: https://github.com/apache/iceberg/pull/9782


-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1577061740


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTViewCatalog.java:
##########
@@ -144,6 +157,65 @@ public void closeCatalog() throws Exception {
     }
   }
 
+  @Test
+  public void testPaginationForListViews() {
+    RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter);
+    catalog.initialize("test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+    String viewName = "newview";
+
+    // create initial namespace
+    catalog().createNamespace(Namespace.of(namespaceName));
+
+    // create several views under namespace, based off a table for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      TableIdentifier viewIndentifier = TableIdentifier.of(namespaceName, viewName + i);
+      catalog
+          .buildView(viewIndentifier)
+          .withSchema(SCHEMA)
+          .withDefaultNamespace(viewIndentifier.namespace())
+          .withQuery("spark", "select * from ns.tbl")
+          .create();
+    }
+    List<TableIdentifier> views = catalog.listViews(Namespace.of(namespaceName));
+    assertThat(views).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            any(),
+            any(),
+            eq(LoadViewResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq(String.format("v1/namespaces/%s/views", namespaceName)),
+            eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),

Review Comment:
   Yea I had tried out a similar example to what you shared above, and mentioned the issues i faced here https://github.com/apache/iceberg/pull/9782#discussion_r1571188458, when i tried make two seperate requests, like so :
   
   ```
   
       Mockito.verify(adapter)
           .execute(
               eq(HTTPMethod.GET),
               eq("v1/namespaces"),
               eq(ImmutableMap.of("pageToken", "", "pageSize", "10")),
               any(),
               eq(ListNamespacesResponse.class),
               any(),
               any());
   
       Mockito.verify(adapter)
               .execute(
                       eq(HTTPMethod.GET),
                       eq("v1/namespaces"),
                       eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),
                       any(),
                       eq(ListNamespacesResponse.class),
                       any(),
                       any());
   
   ``` 
   
   It  always fail on the first request, i think because this list namespaces endpoint is hit multiple times and the last value of the query params is `"pageToken", "10", "pageSize", "10"` is what gets called thus leading to this exception, instead of what was sent intially.
   
   ```
   Argument(s) are different! Wanted:
   rESTCatalogAdapter.execute(
       GET,
       "v1/namespaces",
       {"pageToken" = "", "pageSize" = "10"},
       <any>,
       class org.apache.iceberg.rest.responses.ListNamespacesResponse,
       <any>,
       <any>
   );
   ```



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "rahil-c (via GitHub)" <gi...@apache.org>.
rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1585614568


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -228,6 +230,13 @@ public void initialize(String name, Map<String, String> unresolved) {
               client, tokenRefreshExecutor(), token, expiresAtMillis(mergedProps), catalogAuth);
     }
 
+    this.restPageSize = mergedProps.get(REST_PAGE_SIZE);

Review Comment:
   Will fix



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Add Pagination To List Apis [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1587208312


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -494,22 +515,30 @@ public void createNamespace(
 
   @Override
   public List<Namespace> listNamespaces(SessionContext context, Namespace namespace) {
-    Map<String, String> queryParams;
-    if (namespace.isEmpty()) {
-      queryParams = ImmutableMap.of();
-    } else {
-      // query params should be unescaped
-      queryParams = ImmutableMap.of("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    Map<String, String> queryParams = Maps.newHashMap();
+    if (!namespace.isEmpty()) {
+      queryParams.put("parent", RESTUtil.NAMESPACE_JOINER.join(namespace.levels()));
+    }

Review Comment:
   nit: newline after this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org