Skip to content

Add Delta Lake write interoperability and concurrency integration tests - #120519

Merged
zlareb1 merged 9 commits into
ClickHouse:masterfrom
zlareb1:delta-lake-writes-integration-coverage
Oct 12, 2026
Merged

zlareb1 merged 9 commits into
ClickHouse:masterfrom
zlareb1:delta-lake-writes-integration-coverage

Conversation

@zlareb1

@zlareb1 zlareb1 commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Integration tests for Delta Lake writes where a foreign reader or a second writer is the oracle (test_storage_delta/test_writes_interop.py):

  • type matrix and partition-type matrix written by ClickHouse, read back by Spark (also via s3a on MinIO) and delta-rs, including Spark partition pruning on the values ClickHouse serializes (the decimal partition column is Spark-only until DeltaLake writes: decimal partition value committed without scale (1.5 for decimal(10,2)), the table is then unreadable by ClickHouse and delta-rs #120521);
  • Spark DESCRIBE HISTORY, VERSION AS OF and data skipping over ClickHouse commits; interleaved Spark/ClickHouse appends; Spark checkpoints around ClickHouse commits, and a ClickHouse commit conflict across a checkpoint boundary; VACUUM keeps ClickHouse-written live files;
  • write to a table with an unsupported writer feature (CDF-enabled) fails closed;
  • read-after-write across two nodes; Spark and delta-rs read-back of MinIO and Azurite writes;
  • barrier-synchronised concurrent writers (version contiguity, loser cleanup, Spark history) and ClickHouse racing delta-rs with conditional PUT;
  • KILL QUERY and cancel-in-commit-window on S3 and Azure (only local was covered);
  • failed writes do not leak credentials into query_log or text_log.

Also fixes two assertions that could not fail: the object recount in test_truncate re-counted a pre-computed list, and the row check in test_azure_cluster.py was a bare expression.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.2190-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [823c9a7]

Summary: ✅


AI Review

Summary

This PR substantially improves Delta Lake write coverage across Spark/delta-rs, object storage, cancellation, and concurrency. Most earlier false-green gaps are closed, but one checkpoint-boundary race test still misses the invariant it claims to cover: it proves committed files remain reachable, yet it still does not prove the losing ClickHouse write cleaned up its own uncommitted parquet.

Findings
  • ⚠️ Majors
    • [tests/integration/test_storage_delta/test_writes_interop.py:565] test_conflict_across_checkpoint_boundary only checks that every committed add.path still exists. It never asserts the opposite condition that matters for this race: that the losing version-3 ClickHouse write did not leave an unreferenced ClickHouse parquet behind. Readers follow the Delta log, so a leaked loser file would not change the row-count assertions and assert_committed_files_exist would still pass green.
    • Suggested fix: after the failed version-3 write and the version-4 retry, compare list_delta_data_files(started_cluster, "s3", path) with the committed ClickHouse add.paths, or at minimum assert the exact expected count of ClickHouse parquet files at the end of the test.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: make test_conflict_across_checkpoint_boundary assert loser-file cleanup, not just committed-file existence.

# The same rows with and without stats-based file skipping (Spark must not skip a
# ClickHouse-written file it should read, nor read one it must not).
predicate = "id BETWEEN 105 AND 210"
with_skipping = sorted(r.id for r in spark.sql(f"SELECT id FROM {table} WHERE {predicate}").collect())

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.

with_skipping == without_skipping only proves result correctness. It does not prove that Spark used ClickHouse-written file statistics when skipping was enabled. If those stats become missing or unparsable, both branches can full-scan the table and still satisfy this equality, so the advertised data-skipping coverage disappears.

Please assert some scan-level evidence that skipping actually happened when enabled, for example fewer files read than in the stats.skipping = false branch, or another Spark metric/plan field that records data skipping.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not asserting a skipping metric here: ClickHouse currently commits add.stats nested under a stats_json key (#120522), so Spark cannot use the statistics and such an assertion cannot pass today. The equality check stays as the correctness guard; a files-read assertion should be added when #120522 is fixed.

zlareb1 added a commit to zlareb1/ClickHouse that referenced this pull request Sep 19, 2026
The ClickHouse transaction is opened when the sink is created, so a delta-rs commit during a slow
SELECT always makes the ClickHouse commit lose. The interleaved rounds stay as a consistency check.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120519&sha=020e3c9f7a10f5fd3795fd2582b5b31030d81d70&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan%2C%20flaky)
PR: ClickHouse#120519

Co-Authored-By: Claude Fable 5.1 <[email protected]>
assert node.query(f"SELECT count(), uniqExact(id), countIf(id >= 100) FROM {fresh}").strip() == "60\t60\t10"
assert spark.sql(f"SELECT count(*) AS c, count(DISTINCT id) AS d FROM {table}").collect()[0][:] == (60, 60)
assert len(deltars_rows(deltars_table(started_cluster, "s3", path), "id")) == 60
assert_committed_files_exist(started_cluster, path)

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.

assert_committed_files_exist only proves that every committed add.path is still present. It does not prove the opposite condition that matters for this checkpoint-boundary race: that the losing ClickHouse write cleaned up its own uncommitted parquet.

If the failed version-3 INSERT leaks one extra ClickHouse data file, every assertion below still goes green because fresh readers use the log, not stray files. Since this is the only checkpoint-snapshot conflict case in the PR, can we also compare list_delta_data_files(started_cluster, "s3", path) against the committed ClickHouse adds (or at least assert there is exactly one ClickHouse parquet after the version-4 retry)?

zlareb1 and others added 9 commits October 12, 2026 10:47
Spark and delta-rs read back ClickHouse writes (type and partition matrices,
MinIO via s3a, Azurite), Spark history/time travel/skipping/checkpoints/VACUUM
over ClickHouse commits, concurrent ClickHouse writers and ClickHouse racing
delta-rs, read-after-write across nodes, cancel on S3/Azure, credential
masking. Also fixes two assertions in test.py and test_azure_cluster.py that
could not fail.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…, capture the killed worker's error, cover the unpartitioned sink on object storage

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…te the credential-leak check by query_id

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Retried on a fresh table up to three times, like the barrier test.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The ClickHouse transaction is opened when the sink is created, so a delta-rs commit during a slow
SELECT always makes the ClickHouse commit lose. The interleaved rounds stay as a consistency check.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120519&sha=020e3c9f7a10f5fd3795fd2582b5b31030d81d70&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan%2C%20flaky)
PR: ClickHouse#120519

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…artition-type matrix

- The data-file lister deliberately skips `*.snappy.parquet` (files from other writers), so it cannot be compared against every `add.path`; assert instead that the loser left no ClickHouse file and that every committed file of either writer exists.
- The partition-type matrix is read back by delta-rs on a twin table without the decimal column, which delta-rs cannot open because of ClickHouse#120521.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The fixed one-second sleep only guessed that the ClickHouse transaction was open. The INSERT now
carries a query id and the delta-rs commit waits until `system.processes` shows it has read rows,
which happens after the sink (and its kernel transaction) was created; the slow SELECT lasts ten
seconds so the delta-rs commit always lands first.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
- Barrier race: at least one writer must succeed, not only lose.
- ClickHouse vs delta-rs: alternate a one-second head start between the writers, so the schedule makes each side win rounds; both must have committed at least once in the interleaved rounds.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@zlareb1
zlareb1 force-pushed the delta-lake-writes-integration-coverage branch from 96a4cf4 to 823c9a7 Compare October 12, 2026 05:19
@zlareb1
zlareb1 marked this pull request as ready for review October 12, 2026 06:39
@zlareb1
zlareb1 added this pull request to the merge queue Oct 12, 2026
Merged via the queue into ClickHouse:master with commit 24bea92 Oct 12, 2026
173 checks passed
@zlareb1
zlareb1 deleted the delta-lake-writes-integration-coverage branch October 12, 2026 09:43
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2026
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Oct 13, 2026
`test_storage_iceberg_concurrent/test_concurrent_reads.py::test_concurrent_reads` fails in
`Integration tests (arm_binary[, distributed plan], 1/4)` on master since ClickHouse#120519 added
`test_storage_delta/test_writes_interop.py`, the second Spark module that reads MinIO through
`s3a://root`:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=56e72cfad0e82b5dfd2e3be5202aff91757dc920&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%201%2F4%29
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=360bb0de656eb8f83cea4ca307f8480348494eb4&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%201%2F4%29

`ResilientSparkSession` reuses a live py4j gateway, so one pytest worker keeps one JVM across
modules. Hadoop caches `FileSystem` instances JVM-wide by scheme and authority only, and
`SparkSession.stop()` does not clear them, so the iceberg session got the interop module's
`S3AFileSystem` for `s3a://root`, still bound to the interop cluster's MinIO, while its own
configuration named its own MinIO.

In 32 CI jobs carrying both modules, the iceberg test failed 7/7 times when it ran on the same xdist
worker after the interop module, and passed 25/25 times on a different worker. In the failed job on
56e72cf, the interop MinIO's released address 172.16.2.4 went to another module's MinIO at 13:56:53Z,
Spark's Iceberg metadata write landed there, and ClickHouse's `CREATE TABLE` 6 s later reported
Code 107 against its own MinIO.

Call `FileSystem.closeAll()` when reusing a live JVM with no active context. The JVM is still reused,
so the reuse contract of `test_spark_session_recovery` is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... 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-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... 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