Repository navigation
Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake) - #104531
Conversation
`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 ClickHouse#103674
|
Session: Pre-PR validation gate (per task worker policy):
Reviewers: see following comment. |
|
cc @alesapin @Michicosun @scanhex12 — could you review this? Iceberg REST defect: |
|
@groeneai write a test in tests/integration/test_e2e_catalogs |
|
Workflow [PR], commit [5405aa3] Summary: ❌
AI ReviewSummaryThis PR fixes pagination in ClickHouse Rules
Final Verdict
|
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 ClickHouse#103674.
|
@fm4v @clickhouse-gh — pushed integration test in d66b2b7 ( The test runs ClickHouse against a tiny
Three tests:
Validated locally in both directions:
Implementation followed the existing pattern in |
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 ClickHouse#104531.
|
@clickhouse-gh — addressed in commit 8428115. Monotonic-progress guardBoth if (next_page_token.empty())
break;
if (next_page_token == page_token)
throw DB::Exception(
DB::ErrorCodes::DATALAKE_DATABASE_ERROR,
"Iceberg REST catalog returned the same `next-page-token` (`{}`) twice in a row "
"while listing namespaces under `{}` — refusing to loop.",
next_page_token, base_namespace);
page_token = std::move(next_page_token);Same shape applied to the tables loop. Test coverageExtended
ValidationVerified in both directions on
Full pytest summary with the fix: |
Regression test for ClickHouse#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 ClickHouse#104531).
…ckHouse#104531 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`).
…eview) 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.
LLVM Coverage Report
Changed lines: 73.49% (61/83) · Uncovered code |
|
Test failing without the fix and succeed with the fix: https://github.com/ClickHouse/clickhouse-private/pull/57746 |
Master AST fuzzer hit `Segmentation fault (STID: 0988-2212)` on `AST fuzzer (amd_msan)` for `groupArrayMovingSum` on PR ClickHouse#100394 and on `AST fuzzer (arm_asan_ubsan)` / `amd_debug` for PRs ClickHouse#101033, ClickHouse#101062, ClickHouse#104531 — same bug class as STID 0988-40af / 0988-3351. The fuzzer mutated a query into `groupArrayMovingSumState(...) * N`, which goes through `FunctionBinaryArithmetic::executeAggregateMultiply`. The exponentiation-by-squaring loop called `function->merge(vec_from[i], vec_from[i], arena.get())`, and `MovingImpl::merge` then did `cur_elems.value.insert(rhs_elems.value.begin(), rhs_elems.value.end(), arena)` where `rhs_elems` aliased `cur_elems.value`, so the source iterators referenced the buffer that `insertPrepare` was about to reallocate. The fix in this PR (copy `vec_from` into an independent column before each squaring step) eliminates the self-alias at the call site, so `MovingImpl::merge` is never invoked with `place == rhs` from `executeAggregateMultiply` anymore. The new test exercises every `MovingImpl` instantiation reachable from `groupArrayMovingSum` / `groupArrayMovingAvg`: - integer accumulator, - decimal accumulator (the variant flagged on PR ClickHouse#101062), - windowed parameterisation (`LimitNumElements::value = true`), - the `agg_state_is_const` path through `arrayJoin([state, state])`. Verified locally on Debug build that pre-fix the squaring path aborts with the PODArray `assertNotIntersects` assertion (Server `<Fatal>`), while `state * 1` (no squaring branch) returns `50` — matching the single-state baseline used to derive the reference values. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100394&sha=7309f23dc7ccee494b41416c8fff18c02d0697a7&name_0=PR&name_1=AST%20fuzzer%20%28amd_msan%29
|
Ready to be merged |
d6c1460
Cherry pick #104531 to 26.4: Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake)
…s pagination (Iceberg REST / OneLake / BigLake)
Backport #104531 to 26.4: Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake)
…tNamespaces pagination (Iceberg REST / OneLake / BigLake)
…4531 Backport ClickHouse#104531 to 26.4: Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake)
Regression test for ClickHouse#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.
test_e2e_catalogs::test_list_tables_pagination creates 60 tables through a 10-worker pool and passed an explicit table_name= to BigLakeCatalogManager.create_table. That path is single-attempt by design: PR ClickHouse#109204 added a wall-clock bounded retry to create_table but deliberately carved the caller-supplied-name path out of it, because a same-name retry can resurface its own partial attempt as TableAlreadyExistsError, so exactly-once creation cannot be guaranteed there. That reasoning still holds. The defect is that this test was the only table_name= call site in the whole repo, so it made 60 un-retried live-catalog round-trips and failed whenever any single one blipped. It does not actually need fixed names: it asserts set membership of the names it created, whatever they are. So it now lets create_table generate them and builds `expected` from the returned values. Because every retry attempt uses a fresh unique name, exactly-once creation holds by construction, which is precisely the property the carve-out protects, and the fix therefore does not depend on _drop_failed_attempt being reliable (it is best-effort by its own docstring). The named branch is left in place and unchanged. After this change it has no in-repo caller, but it is public helper API whose single-attempt contract is still correct, so removing it would be an unrelated change. Separately, NoSuchNamespaceError was retried by neither path. Its MRO is [NoSuchNamespaceError, Exception, BaseException, object]: it is not a RESTError and not a requests.RequestException, so it fell outside _TRANSIENT_CREATE_ERRORS. BigLake indexes a just-created namespace asynchronously, so the session namespace can 404 for a few seconds after create_namespace. Adding it to that tuple is safe: _TRANSIENT_CREATE_ERRORS is consumed only by create_table, while the same class in _TABLE_GONE_ERRORS is consumed only by wait_for_table_gone, so its "proof a table is gone" meaning there is untouched. A namespace that is genuinely missing still fails with the same exception, just at the existing deadline instead of immediately. Validated by fault injection against the real functions, since a live run needs GCS/BigLake credentials and the e2e suite is excluded from public CI: with table_name= a transient error raises on attempt 1, and without it the same error is retried and succeeds; reverting either change reddens its own arm, while auth-expiry errors stay non-retryable. The three pagination assertions from PR ClickHouse#104531 are untouched and still fail when the listing is truncated at the page boundary, because detection rests on 60 tables exceeding one ~50-entry page rather than on name sort order (measured identical at 2000 trials per naming scheme). Auto-naming carries a 4.1e-07 collision probability per run, and a collision raises TableAlreadyExistsError, which is not transient and so fails loudly rather than silently. Also fixes two comments naming a caller test_many_tables_pagination that has never existed; the real caller is test_list_tables_pagination.
RestCatalog::getTables(namespace, limit)andRestCatalog::getNamespaces(base_namespace)issued a single HTTPGETand 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-restservers paginate once a namespaceexceeds 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>andsystem.tables, eventhough they existed on the server and
SELECT … FROM lake.<missing>worked via the per-table Load-Table endpoint. The bug is order-dependent
— tables whose identifiers sort lexicographically after the page
boundary disappear; earlier ones don't. Affects
OneLakeCatalog,BigLakeCatalogandRestCatalogdirectly, all of which inheritgetTables/getNamespacesfromRestCatalog. Silent missing data isparticularly dangerous because users have no signal that the listing
was truncated.
Fix: loop on
next-page-tokenin bothgetTables(namespace, limit)and
getNamespaces(base_namespace), mirroring the patterns alreadyshipped in
PaimonRestCatalog::forEachTables(camelCasenextPageToken) andUnityCatalog::getTablesForSchema(snake_casenext_page_token). The Iceberg REST spec uses kebab-casenext-page-token. Empty / null / missing tokens all mean "no morepages".
Implementation:
parseTables/parseNamespacesgain an out-parameterString & next_page_tokenset fromnext-page-tokenin the response(or cleared if absent / null). They still return the parsed
identifiers / namespaces unchanged.
getTables(namespace, limit)loops, attachingpageToken=<token>asa query parameter on subsequent requests. The
limitis honoredacross pages — the inner
parseTablesis given the remaining budgeton each page, and the outer loop short-circuits once
tables.size() >= limit. This preserves theempty()fast-path whichcalls
getTables(ns, /*limit*/ 1).getNamespaces(base_namespace)loops similarly. The pre-existingparentquery parameter is preserved as abase_paramssnapshot andre-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.pyintegration tests against thetabular/iceberg-restreference server.Validation:
amd_debugbuild (ninja -C build clickhouse).PaimonRestCatalog::forEachTables(
src/Databases/DataLake/PaimonRestCatalog.cpp:322-371) andUnityCatalog::getTablesForSchema(
src/Databases/DataLake/UnityCatalog.cpp:303-367).(single-page response, no token in body) and will exercise the new
loop's fast-path.
issue (
test_e2e_catalogs/test.py::*[onelake]against MicrosoftFabric, in
ClickHouse/clickhouse-private). A local OSS regressiontest would require either a live Fabric / BigLake / OneLake instance
or a custom paginating mock REST server. Adding such a mock is
feasible but out of scope for this fix; happy to follow up if review
prefers it inline.
Closes #103674
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
SHOW TABLESandsystem.tablessilently truncating the listing forDataLakeCatalogdatabases backed by Iceberg REST catalogs (iceberg-rest,onelake,biglake). When the catalog server paginates the list-tables or list-namespaces response (e.g. Microsoft Fabric / OneLake beyond ~50 tables per namespace), tables on later pages were silently invisible toSHOW TABLESandsystem.tables, even though they were queryable via directSELECT.RestCatalognow follows thenext-page-tokencontinuation token defined by the Iceberg REST OpenAPI spec, matching the existing behavior ofPaimonRestCatalogandUnityCatalog.Documentation entry for user-facing changes
Version info
26.5.1.65626.4.3.20