Skip to content

REST: Fetch list results lazily with PaginationList - #4483

Open
Anurag-S1ngh wants to merge 1 commit into
apache:mainfrom
Anurag-S1ngh:fix/3365-lazy-pagination
Open

Anurag-S1ngh wants to merge 1 commit into
apache:mainfrom
Anurag-S1ngh:fix/3365-lazy-pagination

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor

Rationale for this change

RestCatalog.list_namespaces, list_tables, and list_views currently walk every page before returning. Callers that only need the first few results still pay for all the network calls.

This adds a PaginationList that loads the first page eagerly and fetches later pages only when iteration or indexing moves past the loaded items. Operations that need the complete result set, such as len(), in, slicing, negative indexes, repr(), sort(), and reverse(), fetch all remaining pages first. The return type stays a list subclass, so existing callers keep their list semantics. Retries are applied to each lazily fetched page.

Closes #3365.

Are these changes tested?

Yes. Added unit tests for PaginationList covering lazy iteration, early exit, indexing, slicing, and list operations, plus a REST test that asserts the second page is not requested until iteration passes the first page.

  • pytest tests/ -m unit --ignore=tests/integration: 4893 passed, 6 skipped
  • ruff check and ruff format --check pass
  • ty check reports only the two pre-existing model_dump diagnostics in typedef.py

Are there any user-facing changes?

The three list methods now return a PaginationList instead of a plain list. It behaves like a list, including len() and equality, but may defer network calls until callers reach later items.

Return a PaginationList from list_namespaces, list_tables, and list_views. Later pages are fetched only when iteration or indexing moves past the loaded items. Operations that need the full result set, such as len, contains, slicing, and repr, fetch all pages first.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement iterator to lazily go through the paged response

1 participant