Skip to content

Add a differential fuzzer for data lake tables written by foreign tools - #128295

Merged
fm4v merged 5 commits into
masterfrom
nik/datalake-foreign-writer-fuzz
Nov 1, 2026
Merged

fm4v merged 5 commits into
masterfrom
nik/datalake-foreign-writer-fuzz

Conversation

@fm4v

@fm4v fm4v commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

A seeded, reproducible differential fuzzer for data lake tables written by other tools and read by ClickHouse, and for tables ClickHouse writes for other tools. It targets the class of bugs behind #114933, #113676, #114994, #113360, #113324, #114350, #114848 and #114854: ClickHouse silently returning different data than the writer, or failing on a table shape the writer produces.

A standalone tool under tests/datalake_fuzzer/ (README there): the library foreign_writer_fuzz/ and a pytest driver test_fuzz.py on top of the integration test harness, one ClickHouse node, MinIO and the Iceberg REST catalog container, one Spark session for all formats. It is not part of the integration test suite and does not run in PRs. Only public images and the libraries already in the integration runner image (pyspark with the Iceberg, Delta, Hudi and Paimon jars, pyiceberg, deltalake) are used.

How it works:

  • A history (JSON) is generated from the seed: random schema over the writer's type matrix (nested lists, maps and structs, nullable fields, decimals of any precision, timestamps with and without zone, UUID, binary), random partitioning (identity, bucket, truncate, year, month, day, hour), random table options (format version 1 to 3, copy-on-write or merge-on-read, deletion vectors, column mapping, primary keys), and a random sequence of appends, overwrites, row-level deletes, updates, merges, add/drop/rename/move/promote column, partition evolution, compaction, position delete rewrite, snapshot expiry, vacuum and checkpoints.
  • The writer executes it: Spark Iceberg (Hadoop catalog), PyIceberg through the REST catalog, Spark Delta, delta-rs, Spark Hudi, Spark Paimon; and in the reverse direction ClickHouse IcebergS3 (read back by PyIceberg and Spark) and DeltaLake (read back by delta-rs and Spark).
  • After every step ClickHouse (icebergS3, DataLakeCatalog, deltaLake, hudi, paimonS3, the engine tables) must match the writer's own read: full row multiset, count() with and without the trivial count, per-column count/min/max, rows and counts under random predicates with NOT/AND/OR/IN/BETWEEN/IS NULL evaluated in Python with three-valued logic, and time travel to a live older snapshot. Each query uses a random variant of the read settings (pruning, manifest statistics, Parquet push-down, Delta engine predicate, query condition cache, max_threads, max_block_size). The server log is checked for <Fatal>, logical errors and sanitizer reports after each step.
  • A failure is shrunk by delta debugging and reported with the seed, the failing query and settings, a row diff, the same query with all optimizations off and with defaults, the minimal operation list, and a replay command; the history is saved as JSON next to the instance logs.
  • Open bugs are steered around by named gates in known_issues.py, so the nightly run reports only new bugs and every other check stays strict; FOREIGN_WRITER_FUZZ_KNOWN_ISSUES=1 opens them.

It runs in the NightlySQLancer workflow next to SQLancer and SQLancer++, as Data lake fuzzer (arm_release) and Data lake fuzzer (arm_asan_ubsan) (ci/jobs/datalake_fuzzer_job.py, integration test runner image with docker-in-docker): random seeds, 20 operations per history, 20 minutes per writer (checked between operations), up to 300 s of shrinking per distinct failure, 4 h job timeout. The job is not cached, since every run draws new seeds. Server logs and the minimal failing histories are attached as datalake_fuzzer_logs.tar.zst. The budget is overridden with --param (FOREIGN_WRITER_FUZZ_BASE_SEED, FOREIGN_WRITER_FUZZ_SEEDS, FOREIGN_WRITER_FUZZ_OPS, FOREIGN_WRITER_FUZZ_TIME_BUDGET, FOREIGN_WRITER_FUZZ_WRITERS, FOREIGN_WRITER_FUZZ_REPLAY), e.g. python -m ci.praktika run "Data lake fuzzer (arm_release)" --workflow NightlySQLancer --param FOREIGN_WRITER_FUZZ_WRITERS=spark_iceberg,spark_delta,FOREIGN_WRITER_FUZZ_TIME_BUDGET=300. A local run with a small budget (2 seeds, 8 operations, 60 s per writer) took 4 minutes 7 seconds for the 8 writers including cluster start, all green.

Bugs found while developing it (on master 26.11.1.1329, none fixed here; details and repros in the README, issues not filed yet, so the gates in known_issues.py carry placeholders):

Related: #123954
Related: #127545
Related: #127547

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Workflow [PR]
Sync PR [sync-upstream/pr/128295]

Version info

  • Merged into: 26.11.1.1038-master (included in 26.11 and later)

`tests/integration/helpers/foreign_writer_fuzz` generates seeded random histories of appends, overwrites, row-level deletes, updates, merges, schema and partition evolution, compaction and snapshot expiry, executes them with Spark Iceberg, PyIceberg through a REST catalog, Spark Delta, delta-rs, Spark Hudi, Spark Paimon, and ClickHouse writing Iceberg and Delta, and after each step checks that ClickHouse returns exactly what the writer's own reader returns (content, counts, aggregates, random filtered reads, time travel). Open ClickHouse bugs are gated in `known_issues.py` so that the PR run stays green.

`test_datalake_foreign_writer_fuzz` runs it with a small budget per PR (one fixed seed, six operations and 30 s per writer); `FOREIGN_WRITER_FUZZ_*` environment variables configure a long fuzzing run or a replay.

Ported from ClickHouse/clickhouse-private#84109, with the ruff `F401` failures of its style check fixed, black formatting applied, and the Spark session stopped at module teardown.
@clickhouse-gh

clickhouse-gh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5eb26fd]

Summary: ✅


AI Review

Summary

Adds a seeded differential fuzzer for data lake interoperability and runs it in nightly jobs. Request changes: detected server failures can lose their saved history during shrinking, and the supplied replay commands cannot reliably load their input.

Findings

⚠️ Majors

  • Save failures before shrinking — test_fuzz.py:80. After a later ClickHouse write terminates the server, shrink starts another history; ClickHouseIcebergWriter.create raises a connection exception before failure_report persists the original failure. A focused reproduction detected the failure after one checked step, then escaped from shrinking with zero report calls. Save the original history first and skip shrinking against an unavailable server.
  • Preserve and resolve replay input — test_fuzz.py:98. Generated replay paths point inside cluster.instances_dir, which the fuzz_context fixture deletes before test_replay opens the file. The documented ci/tmp/... alternative resolves beneath tests/datalake_fuzzer because the job changes the working directory. Resolve repository-relative paths and load the JSON before cluster initialization, preserving the input across setup.
Missing context / blind spots
  • ⚠️ Full Docker/Spark/nightly execution was not run locally. The focused reproductions exercised the current runner, driver and report generator with a simulated server failure, plus the exact cluster cleanup statement; they do not validate all eight live writers.
Tests
  • ⚠️ After fixing, verify that a server failure with shrinking enabled retains its original JSON and diagnostics, and that replay works using both the generated report path and the README's repository-relative path.
Final Verdict

⚠️ Request changes — preserve failure artifacts before minimization and make replay input survive cluster setup with correct path resolution.

The `amd_msan` run aborted the server on the `throw_on_match` masking rule: `deltaLake` is not compiled in without `delta-kernel-rs` (no Rust in MSan builds), so its secret arguments have no spec, and the statement was logged with the MinIO secret before `UNKNOWN_FUNCTION` was thrown (#128372).

Take the credentials of `deltaLake`, `hudi`, `icebergS3` and the `DeltaLake` engine from the `s3` named collection of `configs/config.d/named_collections.xml`, as the Paimon and ClickHouse Iceberg writers already do, so that no secret is in the query text. `DataLakeCatalog` takes no named collection and keeps positional credentials, which its registered spec masks. Skip the writers that need a table function the server does not have (the Delta Lake writers in MSan builds).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128295&sha=106b0b8b1aa1368ac22dc8361e39cde0d55b73d8&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%20targeted%29
PR: #128295
fm4v added 2 commits November 1, 2026 10:25
- `LType.canon`: match struct fields by name for dict and `Row` values instead of by position, so swapped field values are detected.
- `_check_aggregates`: use `minOrNull`/`maxOrNull` instead of overwriting every NULL expectation, so all-NULL nullable columns stay checked.
- `_check_time_travel`: choose the historical snapshot in the order snapshots were taken, not by sorted runtime IDs, so the choice is reproducible on replay and while shrinking.
- `run_history`: check the server log and liveness after a rejected ClickHouse write and after the last operation, so a write that kills the server is reported.
- `shrink`: keep intermediate checks for any failure raised during a time-travel read, including `query_error`.
- `temp_view`: make it a context manager that drops the Spark temp view after the operation.
- `server_alive`: bound the health probe with a 10 s timeout.
… job

The foreign-writer fuzzer is now a standalone tool under `tests/datalake_fuzzer/` (the library `foreign_writer_fuzz/`, the pytest driver `test_fuzz.py` and its cluster fixture) on top of the integration test harness, instead of an integration test module. It no longer runs in PR integration jobs.

It runs in the `NightlySQLancer` workflow next to SQLancer and SQLancer++, as `Data lake fuzzer (arm_release)` and `Data lake fuzzer (arm_asan_ubsan)`: `ci/jobs/datalake_fuzzer_job.py` starts docker-in-docker in the integration test runner image, prefetches the MinIO and Iceberg REST catalog images, and runs every writer with random seeds, 20 operations per history and 20 minutes per writer. The job is not cached, since every run draws new seeds. Server logs and the minimal failing histories are attached as `datalake_fuzzer_logs.tar.zst`.

`--param` overrides the budget; a comma that is not followed by `KEY=` stays in the value, so `FOREIGN_WRITER_FUZZ_WRITERS=a,b` works. The replay command in a failure report points to the new job.

Related: #128295
Comment on lines +80 to +83
shrunk = shrink(
ctx, failing, result.failure, time.monotonic() + BUDGET.shrink_seconds
)
report = failure_report(result, ctx.cluster.instances_dir, shrunk)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [P2] Save the original failure before attempting shrinking

When a later ClickHouse write terminates the server, run_history correctly returns a server failure, but this call immediately tries another history against the unavailable server. For ClickHouseIcebergWriter, the next create raises ClickHouseQueryError; creation is outside the operation-level exception handler in run_history, so the exception escapes shrink before failure_report saves anything. The detected failure loses its replay JSON and detailed report, and pytest reports the subsequent connection error instead.

I reproduced this through the current runner and driver with two writes: the first step was checked, the second terminated the simulated server, and shrinking raised with zero calls to failure_report. Persist the original failure before shrinking, and skip shrinking when the server is unavailable.

Comment on lines +98 to +100
def test_replay(fuzz_context):
with open(BUDGET.replay) as f:
history = json.load(f)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [P2] Preserve and resolve the replay input before cluster setup

failure_report saves the history under cluster.instances_dir and prints a replay command pointing there. However, pytest initializes fuzz_context before reaching this open, and its ClickHouseCluster constructor deletes that same directory (helpers/cluster.py:1148–1149). Following the generated replay command therefore deletes its input and ends with FileNotFoundError. I verified that the JSON created by the current report generator disappears when the constructor's cleanup runs.

The README's alternative of moving the history to ci/tmp/... also fails: the job runs pytest with cwd=FUZZER_DIR, so this relative open looks under tests/datalake_fuzzer/ci/tmp/.... Resolve repository-relative paths and load the history before constructing the cluster, or otherwise preserve the input outside the directory being cleared.

@fm4v
fm4v enabled auto-merge November 1, 2026 20:29
@fm4v
fm4v added this pull request to the merge queue Nov 1, 2026
Merged via the queue into master with commit 816470b Nov 1, 2026
179 checks passed
@fm4v
fm4v deleted the nik/datalake-foreign-writer-fuzz branch November 1, 2026 21:05
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 1, 2026
@fm4v fm4v self-assigned this Nov 2, 2026
@clickhouse-gh clickhouse-gh Bot added comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants