This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git


The following commit(s) were added to refs/heads/main by this push:
     new f0d30ef3 fix: skip pageSize query param when value is 0 (#778)
f0d30ef3 is described below

commit f0d30ef388e78e679462bdf9f42c4f0c01394801
Author: Alessandro Nori <[email protected]>
AuthorDate: Mon Mar 16 22:57:47 2026 +0100

    fix: skip pageSize query param when value is 0 (#778)
    
    ## Key changes
    - Replace `pageSize >= 0` with `pageSize > 0` in `listTablesPage`,
    `listNamespacesPage`, and `listViewsPage`
    
    ## Motivation
    A page size of 0 is meaningless and results in errors returned by
    certain catalogs. The param should only be sent for positive values.
---
 catalog/rest/rest.go      |  6 +++---
 catalog/rest/rest_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/catalog/rest/rest.go b/catalog/rest/rest.go
index b54dc4ff..943b98da 100644
--- a/catalog/rest/rest.go
+++ b/catalog/rest/rest.go
@@ -673,7 +673,7 @@ func (r *Catalog) listTablesPage(ctx context.Context, 
namespace table.Identifier
        uri := r.baseURI.JoinPath("namespaces", ns, "tables")
 
        v := url.Values{}
-       if pageSize >= 0 {
+       if pageSize > 0 {
                v.Set("pageSize", strconv.Itoa(pageSize))
        }
        if pageToken != "" {
@@ -1030,7 +1030,7 @@ func (r *Catalog) listNamespacesPage(ctx context.Context, 
parent table.Identifie
        if len(parent) != 0 {
                v.Set("parent", strings.Join(parent, namespaceSeparator))
        }
-       if pageSize >= 0 {
+       if pageSize > 0 {
                v.Set("pageSize", strconv.Itoa(pageSize))
        }
        if pageToken != "" {
@@ -1159,7 +1159,7 @@ func (r *Catalog) listViewsPage(ctx context.Context, 
namespace table.Identifier,
        uri := r.baseURI.JoinPath("namespaces", ns, "views")
 
        v := url.Values{}
-       if pageSize >= 0 {
+       if pageSize > 0 {
                v.Set("pageSize", strconv.Itoa(pageSize))
        }
        if pageToken != "" {
diff --git a/catalog/rest/rest_test.go b/catalog/rest/rest_test.go
index 255a346a..046c415a 100644
--- a/catalog/rest/rest_test.go
+++ b/catalog/rest/rest_test.go
@@ -1878,6 +1878,55 @@ func (r *RestCatalogSuite) TestListViewsPagination() {
        r.Require().NoError(lastErr)
 }
 
+func (r *RestCatalogSuite) TestListTablesZeroPageSizeNotSent() {
+       namespace := "examples"
+       r.mux.HandleFunc("/v1/namespaces/"+namespace+"/tables", func(w 
http.ResponseWriter, req *http.Request) {
+               r.Require().Equal(http.MethodGet, req.Method)
+               r.Equal("", req.URL.Query().Get("pageSize"), "pageSize must not 
be sent when set to 0")
+               json.NewEncoder(w).Encode(map[string]any{"identifiers": 
[]any{}})
+       })
+
+       cat, err := rest.NewCatalog(context.Background(), "rest", r.srv.URL, 
rest.WithOAuthToken(TestToken))
+       r.Require().NoError(err)
+
+       ctx := cat.SetPageSize(context.Background(), 0)
+       for _, err := range cat.ListTables(ctx, 
catalog.ToIdentifier(namespace)) {
+               r.Require().NoError(err)
+       }
+}
+
+func (r *RestCatalogSuite) TestListNamespacesZeroPageSizeNotSent() {
+       r.mux.HandleFunc("/v1/namespaces", func(w http.ResponseWriter, req 
*http.Request) {
+               r.Require().Equal(http.MethodGet, req.Method)
+               r.Equal("", req.URL.Query().Get("pageSize"), "pageSize must not 
be sent when set to 0")
+               json.NewEncoder(w).Encode(map[string]any{"namespaces": []any{}})
+       })
+
+       cat, err := rest.NewCatalog(context.Background(), "rest", r.srv.URL, 
rest.WithOAuthToken(TestToken))
+       r.Require().NoError(err)
+
+       ctx := cat.SetPageSize(context.Background(), 0)
+       _, err = cat.ListNamespaces(ctx, nil)
+       r.Require().NoError(err)
+}
+
+func (r *RestCatalogSuite) TestListViewsZeroPageSizeNotSent() {
+       namespace := "accounting"
+       r.mux.HandleFunc("/v1/namespaces/"+namespace+"/views", func(w 
http.ResponseWriter, req *http.Request) {
+               r.Require().Equal(http.MethodGet, req.Method)
+               r.Equal("", req.URL.Query().Get("pageSize"), "pageSize must not 
be sent when set to 0")
+               json.NewEncoder(w).Encode(map[string]any{"identifiers": 
[]any{}})
+       })
+
+       cat, err := rest.NewCatalog(context.Background(), "rest", r.srv.URL, 
rest.WithOAuthToken(TestToken))
+       r.Require().NoError(err)
+
+       ctx := cat.SetPageSize(context.Background(), 0)
+       for _, err := range cat.ListViews(ctx, catalog.ToIdentifier(namespace)) 
{
+               r.Require().NoError(err)
+       }
+}
+
 func (r *RestCatalogSuite) TestListViewsPaginationErrorOnSubsequentPage() {
        namespace := "accounting"
        r.mux.HandleFunc("/v1/namespaces/"+namespace+"/views", func(w 
http.ResponseWriter, req *http.Request) {

Reply via email to