dttung2905 commented on code in PR #290: URL: https://github.com/apache/iceberg-go/pull/290#discussion_r1955333313
########## catalog/rest/rest.go: ########## @@ -989,3 +992,95 @@ func (r *Catalog) CheckTableExists(ctx context.Context, identifier table.Identif } return true, nil } + +func (r *Catalog) ListViews(ctx context.Context, namespace table.Identifier) iter.Seq2[table.Identifier, error] { + return func(yield func(table.Identifier, error) bool) { + pageSize := r.getPageSize(ctx) + var pageToken string + + for { + views, nextPageToken, err := r.listViewsPage(ctx, namespace, pageToken, pageSize) + if err != nil { + yield(table.Identifier{}, err) + return + } + for _, view := range views { + if !yield(view, nil) { + return + } + } + if nextPageToken == "" { + return + } + pageToken = nextPageToken + } + } +} + +func (r *Catalog) listViewsPage(ctx context.Context, namespace table.Identifier, pageToken string, pageSize int) ([]table.Identifier, string, error) { + if err := checkValidNamespace(namespace); err != nil { + return nil, "", err + } + ns := strings.Join(namespace, namespaceSeparator) + uri := r.baseURI.JoinPath("namespaces", ns, "views") + + v := url.Values{} + if pageSize >= 0 { + v.Set("page-size", strconv.Itoa(pageSize)) + } + if pageToken != "" { + v.Set("page-token", pageToken) + } + + uri.RawQuery = v.Encode() + type resp struct { + Identifiers []identifier `json:"identifiers"` + NextPageToken string `json:"next-page-token,omitempty"` + } + + rsp, err := doGet[resp](ctx, uri, []string{}, r.cl, map[int]error{http.StatusNotFound: catalog.ErrNoSuchNamespace}) + if err != nil { + return nil, "", err + } + + out := make([]table.Identifier, len(rsp.Identifiers)) + for i, id := range rsp.Identifiers { + out[i] = append(id.Namespace, id.Name) + } + return out, rsp.NextPageToken, nil +} + +func (r *Catalog) getPageSize(ctx context.Context) int { + if pageSize, ok := ctx.Value("page_size").(int); ok { Review Comment: My attempt would be ``` func (r *Catalog) SetPageSize(ctx context.Context, sz int) context.Context { return context.WithValue(ctx, pageSizeKey, sz) } ``` not sure its ok to park it under r *Catalog method receiver. Let me know if you think otherwise :pray: -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org