Skip to content

Cherry pick #104531 to 26.4: Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake) - #104977

Merged
robot-ch-test-poll2 merged 10 commits into
backport/26.4/104531from
cherrypick/26.4/104531
May 14, 2026
Merged

robot-ch-test-poll2 merged 10 commits into
backport/26.4/104531from
cherrypick/26.4/104531

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #104531

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 10 commits May 10, 2026 14:55
`RestCatalog::getTables(namespace, limit)` and
`RestCatalog::getNamespaces(base_namespace)` issued a single HTTP GET and
returned the first page of identifiers / namespaces. The Iceberg REST
OpenAPI spec defines `pageToken` (request) / `next-page-token` (response)
on the list endpoints, and Microsoft Fabric / OneLake / BigLake / generic
`iceberg-rest` servers paginate once a namespace exceeds the server-side
page size (~50 for Fabric/OneLake).

Effect of the bug: tables (or sub-namespaces) on later pages were
silently invisible to `SHOW TABLES FROM <db>` and `system.tables`, even
though they existed on the server and `SELECT … FROM lake.<missing>`
worked via the per-table Load-Table endpoint. This is order-dependent —
tables whose identifiers sort lexicographically after the page boundary
disappear; earlier ones don't. Affects `OneLakeCatalog`, `BigLakeCatalog`
and `RestCatalog` directly, all of which inherit `getTables`/
`getNamespaces` from `RestCatalog`.

Fix: loop on `next-page-token` in both `getTables(namespace, limit)` and
`getNamespaces(base_namespace)`, mirroring the patterns already shipped
in `PaimonRestCatalog::forEachTables` (camelCase `nextPageToken`) and
`UnityCatalog::getTablesForSchema` (snake_case `next_page_token`). The
Iceberg REST spec uses kebab-case `next-page-token`. Empty / null /
missing tokens all mean "no more pages".

Implementation:

- `parseTables` / `parseNamespaces` gain an out-parameter
  `String & next_page_token` which is set from `next-page-token` in the
  response (or cleared if absent / null). They still return the parsed
  identifiers / namespaces unchanged.
- `getTables(namespace, limit)` loops, attaching `pageToken=<token>` as
  a query parameter on subsequent requests. The `limit` is still honored
  across pages — the inner `parseTables` is given the remaining budget,
  and the outer loop short-circuits once `tables.size() >= limit`. This
  preserves the `empty()` fast-path which calls `getTables(ns, /*limit*/1)`.
- `getNamespaces(base_namespace)` loops similarly. The pre-existing
  `parent` query parameter is preserved as a `base_params` snapshot and
  re-attached on every page.

Backward-compatibility: servers that don't paginate omit
`next-page-token`, so the loop short-circuits after the first iteration
— behaviorally identical to the previous code. Caught by the existing
`test_database_iceberg/test.py` integration tests.

Closes #103674
Pins the fix from the previous commit by running ClickHouse against a
tiny Python-bottle mock that serves a paginating Iceberg REST API
(`/v1/config`, `/v1/namespaces`, `/v1/namespaces/{ns}/tables`).

The mock returns `next-page-token` on both list endpoints and uses a
fixed inventory split across multiple pages:

* 2 namespaces with namespace-page size 1  → 2 namespace pages
* 7 + 4 tables with table-page size 3      → 3 + 2 table pages, 11 total

Three test cases:

1. `test_show_tables_collects_all_pages` — `SHOW TABLES FROM <db>` must
   return all 11 tables across both namespaces.
2. `test_system_tables_lists_all_paginated_tables` — same thing via
   `system.tables` with `show_data_lake_catalogs_in_system_tables = 1`.
3. `test_mock_actually_paginates` — sanity check the mock itself.

Without the fix the first two assertions fail (3 rows instead of 11),
which guards both `RestCatalog::getTables` and
`RestCatalog::getNamespaces` continuation loops against regression.

Mirrors the python-bottle fixture pattern already used by
`test_database_glue/test.py` and `test_storage_s3/test_sts.py`. The mock
is registered through `helpers/mock_servers.py::start_mock_servers`, so
no docker-compose changes are needed.

Closes #103674.
Without this, a buggy or malicious Iceberg REST catalog server that
returns the same `next-page-token` on every response could hang
`SHOW TABLES` / `system.tables` indefinitely. Both pagination loops
in `RestCatalog::getNamespaces` and `RestCatalog::getTables` now
abort with `DATALAKE_DATABASE_ERROR` when the catalog responds with
the same `next-page-token` we just submitted as `pageToken`.

Also extends `tests/integration/test_e2e_catalogs/test_pagination.py`
with a 4th test case `test_broken_pagination_loop_is_detected`, plus
a parallel `/broken_loop/v1/...` family of routes in the paginating
mock that always echo `next-page-token=stuck`. The test verifies
that `SHOW TABLES` against a broken-loop catalog returns promptly
with an empty result (rather than hanging) and that the guard's
error message ends up in the server log.

Addresses bot review feedback on PR #104531.
Regression test for #104531: Iceberg REST catalogs paginate
list-tables / list-namespaces responses via a `next-page-token`
continuation (Fabric / OneLake pages at ~50 per namespace). Before
the fix, `RestCatalog::getTables` and `getNamespaces` returned only
the first page, so identifiers sorted after the page boundary were
silently invisible to `SHOW TABLES` and `system.tables`.

The new test creates 60 tables in a fresh `DataLakeCatalog`
database and asserts every one is listed by `SHOW TABLES` and
`system.tables`, then loads the last-sorting table end-to-end. The
test is parametrized over all backends (`biglake`, `glue`,
`onelake`); each places the tables according to its own
convention (single shared namespace for the REST backends, one
namespace per table for Glue), so the same test exercises both
`getTables` pagination and many-namespace listing.
The new `test_list_tables_pagination` in `test_e2e_catalogs/test.py`
exercises the same `RestCatalog::getTables` / `getNamespaces`
pagination loops against the real `biglake` / `glue` / `onelake`
backends, so the standalone Python-bottle mock and its companion
test file are no longer needed.
Switch the membership check in test_list_tables_pagination from
substring matching (``t in line``) to exact set membership.

Catalog backends render each table as ``<namespace>.<short_name>``
(``dbo.<X>`` for OneLake, ``<session_ns>.<X>`` for BigLake, a
per-table ``ch_e2e_glue_<hex>.<X>`` for Glue). The previous check
used ``not any(t in line for line in listed)``, which has a false-
negative for prefix-collision cases: if the catalog truncates
``..._001`` but still returns ``..._0010``, the substring ``001``
is satisfied by ``..._0010`` and silent truncation slips through.

The fix extracts the short name with ``rsplit('.', 1)[-1]`` and
uses exact set membership. Verified against a standalone harness:
the OLD check returns ``[]`` (no missing) for the prefix-collision
case while the NEW check correctly reports ``['e2e_pg_001']``.

Addresses clickhouse-gh[bot] inline review comment on
``tests/integration/test_e2e_catalogs/test.py`` (PR #104531).
…4531 review)

In `RestCatalog::parseNamespaces`, when `getCatalogType() == ICEBERG_BIGLAKE`
and `base_namespace` is non-empty, every entry returned by the catalog is
dropped via `continue` (BigLake ignores `parent` and returns unrelated
top-level namespaces, which would otherwise produce fake multi-level
paths the server then rejects with HTTP 400).

Before this commit, the outer `getNamespaces` loop kept following
`next-page-token` even though every subsequent page also drops all
entries -- burning O(pages) REST calls per parent namespace for zero
contribution to the result. With `getNamespacesRecursive` calling this
once per root namespace, `SHOW TABLES` / `system.tables` could degrade
from one probe per namespace to scanning the full namespace listing
repeatedly.

Leave `next_page_token` empty when the BigLake-drop-everything condition
holds so the outer loop terminates after the first page. No behavior
change for any other catalog type (the new check is gated by
`ICEBERG_BIGLAKE`).
Replaces the previous single-token monotonic-progress guard (which only
caught the immediate `A -> A` repeat) with an `std::unordered_set<String>`
that records every `next-page-token` seen on a request. Any duplicate
`insert` throws `DATALAKE_DATABASE_ERROR`, so a malformed catalog that
alternates two non-empty tokens (e.g. `A -> B -> A -> B -> ...`) is now
also detected and `SHOW TABLES` / `system.tables` stay bounded.

Applied symmetrically to both `RestCatalog::getNamespaces` and
`RestCatalog::getTables`. The new guard is a strict superset of the
prior immediate-repeat check, so behaviour for well-formed catalogs is
unchanged.

Addresses bot inline review on discussion_r3219176987.
…alog-pagination

Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake)
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels May 14, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 merged commit f8bc3fd into backport/26.4/104531 May 14, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 deleted the cherrypick/26.4/104531 branch May 14, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants