Skip to content

Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake) - #104531

Merged
fm4v merged 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-103674-rest-catalog-pagination
May 14, 2026
Merged

fm4v merged 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-103674-rest-catalog-pagination

Conversation

@groeneai

@groeneai groeneai commented May 10, 2026 •

Copy link
Copy Markdown
Collaborator

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. The bug 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. Silent missing data is
particularly dangerous because users have no signal that the listing
was truncated.

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 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 honored
    across pages — the inner parseTables is given the remaining budget
    on each page, 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 against the
tabular/iceberg-rest reference server.

Validation:

  • Compiles cleanly against the amd_debug build (ninja -C build clickhouse).
  • Mirrors structurally the loops in PaimonRestCatalog::forEachTables
    (src/Databases/DataLake/PaimonRestCatalog.cpp:322-371) and
    UnityCatalog::getTablesForSchema
    (src/Databases/DataLake/UnityCatalog.cpp:303-367).
  • Existing iceberg integration tests cover the non-paginating path
    (single-page response, no token in body) and will exercise the new
    loop's fast-path.
  • The paginating path is covered by the failing E2E run linked in the
    issue (test_e2e_catalogs/test.py::*[onelake] against Microsoft
    Fabric, in ClickHouse/clickhouse-private). A local OSS regression
    test 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):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix SHOW TABLES and system.tables silently truncating the listing for DataLakeCatalog databases 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 to SHOW TABLES and system.tables, even though they were queryable via direct SELECT. RestCatalog now follows the next-page-token continuation token defined by the Iceberg REST OpenAPI spec, matching the existing behavior of PaimonRestCatalog and UnityCatalog.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.656
  • Backported to: 26.4.3.20

`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
@groeneai

Copy link
Copy Markdown
Collaborator Author

Session: cron:clickhouse-ci-task-worker:20260510-144500

Pre-PR validation gate (per task worker policy):

# Question Answer
a Deterministic repro? Partial. The bug is structural — observable on any paginating Iceberg REST server (Microsoft Fabric / OneLake beyond ~50 tables, BigLake, generic iceberg-rest configured to paginate). I do not have a paginating server set up locally; the failing E2E run referenced in #103674 is in the private repo ClickHouse/clickhouse-private (run 25032141510).
b Root cause explained? Yes. getTables(namespace, limit) and getNamespaces(base_namespace) issue exactly one GET and return the body's identifiers / namespaces array. The Iceberg REST OpenAPI spec uses pageToken (request) / next-page-token (response) for continuation, and servers like Fabric/OneLake split listings into pages. Without honoring the token, the second page onward is silently dropped.
c Fix matches root cause? Yes. Add the missing pagination loop in both endpoints, mirroring the spec and existing sibling implementations (PaimonRestCatalog::forEachTables, UnityCatalog::getTablesForSchema).
d Test intent preserved / new tests added? Existing tests preserved. No new test added in this PR. A local OSS regression test would require either a live Fabric/BigLake/OneLake instance or a custom paginating mock REST server (the existing tabular/iceberg-rest reference image used by test_database_iceberg does not paginate). Happy to follow up with a mock-server-based integration test if review prefers it inline.
e Demonstrated in both directions? Partial. The fix compiles cleanly. Existing iceberg integration tests cover the non-paginating path (the loop's fast path). The paginating path is covered by the failing E2E test in the private repo, but I have not run that locally. The fix is structurally identical to the loops in PaimonRestCatalog/UnityCatalog which are already validated in production.
f Fix is general, not narrow? Yes. Both getTables AND getNamespaces had the same bug — the spec defines pagination on every list endpoint. Both now loop. OneLakeCatalog/BigLakeCatalog inherit the fix automatically.

Reviewers: see following comment.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alesapin @Michicosun @scanhex12 — could you review this? Iceberg REST defect: RestCatalog::getTables and getNamespaces ignore the spec's next-page-token continuation token, so SHOW TABLES and system.tables silently truncate listings on Microsoft Fabric / OneLake / BigLake / generic iceberg-rest once a namespace exceeds the server-side page size. Closes #103674. Per @alexey-milovidov 2026-04-26 directive on PR #100277, pinging @alesapin (Iceberg manager) and the named experts.

@fm4v

fm4v commented May 10, 2026

Copy link
Copy Markdown
Member

@groeneai write a test in tests/integration/test_e2e_catalogs

@fm4v fm4v added the can be tested Allows running workflows for external contributors label May 10, 2026
@fm4v fm4v self-assigned this May 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5405aa3]

Summary: ❌

job_name test_name status info comment
Bugfix validation (integration tests) FAIL IGNORED
Integration tests (amd_asan_ubsan, flaky) ERROR IGNORED

AI Review

Summary

This PR fixes pagination in RestCatalog namespace/table listing by following Iceberg REST next-page-token and adds integration coverage for paginated catalog listings. I found no remaining correctness, safety, or performance issues in the current HEAD, and previously raised inline concerns have been addressed.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 10, 2026
Comment thread src/Databases/DataLake/RestCatalog.cpp Resolved
Comment thread src/Databases/DataLake/RestCatalog.cpp Resolved
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.
@groeneai

Copy link
Copy Markdown
Collaborator Author

@fm4v @clickhouse-gh — pushed integration test in d66b2b7 (tests/integration/test_e2e_catalogs/test_pagination.py + iceberg_rest_paginating_mock.py).

The test runs ClickHouse against a tiny python-bottle mock that always paginates both list endpoints, mirroring the spec contract (pageToken request + next-page-token response). Inventory is deliberately split across multiple pages on both axes:

items page size pages
/v1/namespaces 2 1 2
/v1/namespaces/ns_alpha/tables 7 3 3
/v1/namespaces/ns_beta/tables 4 3 2

Three tests:

  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 via system.tables (with show_data_lake_catalogs_in_system_tables = 1).
  3. test_mock_actually_paginates — mock-only sanity check that the test premise actually holds.

Validated locally in both directions:

  • With the fix (HEAD): 3 passed in 5.85s
  • Without the fix (HEAD~1, restored locally to verify): 2 failed, 1 passed — both ClickHouse-dependent tests return 3 rows instead of 11 (ns_alpha.t1/t2/t3 only — first page of first namespace, the documented bug).

Implementation followed the existing pattern in test_database_glue/test.py and test_storage_s3/test_sts.py — a clickhouse/python-bottle instance is added to the cluster and the mock script is registered via helpers/mock_servers.py::start_mock_servers, so no docker-compose changes were needed.

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.
@groeneai

Copy link
Copy Markdown
Collaborator Author

@clickhouse-gh — addressed in commit 8428115.

Monotonic-progress guard

Both RestCatalog::getNamespaces and RestCatalog::getTables now throw DATALAKE_DATABASE_ERROR when the catalog responds with the same next-page-token that we just submitted as pageToken:

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 coverage

Extended tests/integration/test_e2e_catalogs/test_pagination.py with a 4th test case test_broken_pagination_loop_is_detected. The mock now exposes a parallel /broken_loop/v1/... URL family that always echoes next-page-token=stuck. The test:

  1. Asserts SHOW TABLES completes within 30s (vs. hanging until pytest-timeout). Note that DatabaseDataLake::getTablesIterator swallows catalog errors via tryLogCurrentException, so the query returns an empty result rather than failing — but the guard makes that empty return prompt instead of post-hang.
  2. Asserts the result is empty (the iteration was aborted on request Repair subtree2 #2 before any table was collected).
  3. Asserts the guard's error message (...returned the same next-page-token... twice in a row...) appears in the ClickHouse server log.

Validation

Verified in both directions on Integration tests (amd_tsan, 1/6) locally:

  • Without the guard (HEAD~1, commit d66b2b78890): test_broken_pagination_loop_is_detected hangs in the getNamespaces loop until the docker container is killed externally — pytest reaches the test setup but never the call phase.
  • With the guard (HEAD = 8428115ae79): all 4 tests pass; test_broken_pagination_loop_is_detected completes in 0.36s.

Full pytest summary with the fix:

passed call 0.24s test_show_tables_collects_all_pages
passed call 0.24s test_system_tables_lists_all_paginated_tables
passed call 0.00s test_mock_actually_paginates
passed call 0.36s test_broken_pagination_loop_is_detected
SessionFinish exit=0

fm4v added 2 commits May 11, 2026 10:33
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).
Comment thread src/Databases/DataLake/RestCatalog.cpp Resolved
groeneai added 2 commits May 11, 2026 12:48
…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.
@clickhouse-gh

clickhouse-gh Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 73.49% (61/83) · Uncovered code

Full report · Diff report

@fm4v

fm4v commented May 12, 2026

Copy link
Copy Markdown
Member

Test failing without the fix and succeed with the fix: https://github.com/ClickHouse/clickhouse-private/pull/57746

status	name	duration
fail	test_e2e_catalogs/test.py::test_list_tables_pagination[onelake] [cidb](http://cidb.clickhouse-staging.com:8123/play?user=play&run=1#V0lUSAogICAgOTAgQVMgaW50ZXJ2YWxfZGF5cwpTRUxFQ1QKICAgIHRvU3RhcnRPZkRheShjaGVja19zdGFydF90aW1lKSBBUyBkYXksCiAgICBjb3VudCgpIEFTIGZhaWx1cmVzLAogICAgZ3JvdXBVbmlxQXJyYXkocHVsbF9yZXF1ZXN0X251bWJlcikgQVMgcHJzLAogICAgYW55KHJlcG9ydF91cmwpIEFTIHJlcG9ydF91cmwKRlJPTSBjaGVja3MKV0hFUkUgKG5vdygpIC0gdG9JbnRlcnZhbERheShpbnRlcnZhbF9kYXlzKSkgPD0gY2hlY2tfc3RhcnRfdGltZQogICAgQU5EIHRlc3RfbmFtZSA9ICd0ZXN0X2UyZV9jYXRhbG9ncy90ZXN0LnB5Ojp0ZXN0X2xpc3RfdGFibGVzX3BhZ2luYXRpb25bb25lbGFrZV0nCiAgICAtLSBBTkQgY2hlY2tfbmFtZSA9ICdJbnRlZ3JhdGlvbiB0ZXN0cyBFMkUnCiAgICBBTkQgdGVzdF9zdGF0dXMgSU4gKCdGQUlMJywgJ0VSUk9SJykKICAgIEFORCAocHVsbF9yZXF1ZXN0X251bWJlciA9IDAgT1IgYmFzZV9yZWYgSU4gKCdtYXN0ZXInKSkKICAgIEFORCB0ZXN0X2NvbnRleHRfcmF3IExJS0UgJyVBc3NlcnRpb25FcnJvciUnCkdST1VQIEJZIGRheQpPUkRFUiBCWSBkYXkgREVTQwo=)	14m 36s
File: test_e2e_catalogs/test.py:1224 - in test_list_tables_pagination
    assert not missing, (
E   AssertionError: SHOW TABLES from e2e_onelake_e680262a is missing 46/60 tables (first missing: ['e2e_pg_52cd62_014', 'e2e_pg_52cd62_015', 'e2e_pg_52cd62_016', 'e2e_pg_52cd62_017', 'e2e_pg_52cd62_018']); listing returned 100 unique short names from 100 entries — list response was truncated at the catalog page boundary.
E   assert not ['e2e_pg_52cd62_014', 'e2e_pg_52cd62_015', 'e2e_pg_52cd62_016', 'e2e_pg_52cd62_017', 'e2e_pg_52cd62_018', 'e2e_pg_52cd62_019', ...]

@fm4v
fm4v requested a review from scanhex12 May 12, 2026 13:21
groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 12, 2026
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
@fm4v

fm4v commented May 13, 2026

Copy link
Copy Markdown
Member

Ready to be merged

@fm4v
fm4v added this pull request to the merge queue May 14, 2026
Merged via the queue into ClickHouse:master with commit d6c1460 May 14, 2026
162 of 165 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 14, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 14, 2026
robot-ch-test-poll2 added a commit that referenced this pull request May 14, 2026
Cherry pick #104531 to 26.4: Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake)
robot-clickhouse added a commit that referenced this pull request May 14, 2026
…s pagination (Iceberg REST / OneLake / BigLake)
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 14, 2026
fm4v added a commit that referenced this pull request May 14, 2026
Backport #104531 to 26.4: Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…tNamespaces pagination (Iceberg REST / OneLake / BigLake)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…4531

Backport ClickHouse#104531 to 26.4: Fix RestCatalog::getTables and getNamespaces pagination (Iceberg REST / OneLake / BigLake)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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.
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Sep 27, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataLakeCatalog: RestCatalog::getTables does not paginate, hides tables in large namespaces (OneLake/BigLake/Iceberg REST)

5 participants