Skip to content

Do not commit an empty Delta Lake version when an INSERT writes no data file - #122092

Open
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:do-not-commit-empty-delta-version
Open

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:do-not-commit-empty-delta-version

Conversation

@groeneai

@groeneai groeneai commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

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

A 0-row INSERT into an unpartitioned DeltaLake table no longer commits an empty transaction log version. Both Delta Lake writers now skip the commit when no data file was written, matching the partitioned writer and Spark, so a repeated no-op append (a scheduled INSERT SELECT that selects no rows, for example) no longer grows _delta_log. Closes #122020.

Description

A 0-row INSERT behaved differently depending on whether the table was partitioned: an unpartitioned table committed a new version carrying only commitInfo and referencing no data file, while a partitioned table committed nothing. Spark creates no version for an append that writes no files.

WriteTransaction::commit appends a log version unconditionally, so committing an empty file list is not a no-op. Only DeltaLakePartitionedSink::onFinish guarded that call (on partitions_data.empty()); DeltaLakeSink::onFinish did not, and its data_files stays empty because consume is never reached when the SELECT yields no chunk. This adds the symmetric disjunct data_files.empty(). The predicate is the file list and not a row count on purpose: a written-but-0-row data file must still be committed, or the object stays on storage unreferenced by the log.

Sibling surfaces, all measured (the tree has exactly two commit call sites):

Surface Status
Unpartitioned INSERT fixed here
Partitioned INSERT already skips; kept as a no-regression arm
Iceberg writer already skips (writer_per_partition_key.empty()); out of scope
CREATE TABLE initial log commits by design; unchanged

Not a Bug Fix: no released version does anything wrong, since the empty version is valid per the protocol. The consequence is writer-vs-writer divergence plus log growth on no-op refreshes.

New stateless test, 6 arms: 3 red before this change, 3 unchanged by it (the partitioned 0-row arm and both non-empty-INSERT positive controls, which prove the guard is not too wide); 100/100 randomized runs.


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

…ta file

A 0-row INSERT behaved differently depending on whether the table was
partitioned: an unpartitioned table committed a new transaction log version
carrying only commitInfo and referencing no data file, while a partitioned
table committed nothing. Every no-op refresh of a scheduled INSERT SELECT
therefore grew _delta_log on unpartitioned tables only. Spark creates no
version for an append that writes no files.

WriteTransaction::commit always calls ffi::add_files + ffi::commit, so
committing an empty file list is not a no-op: the kernel appends a
commitInfo-only entry. Only DeltaLakePartitionedSink::onFinish guarded that
call, on partitions_data.empty(). DeltaLakeSink::onFinish did not, and its
data_files stays empty because consume is never reached when the SELECT
yields no chunk. This adds the symmetric disjunct.

The predicate is data_files.empty() and deliberately not a row count. A
written-but-0-row data file must still be committed, or the object stays on
storage unreferenced by the log; and returning early with a non-empty
data_files would skip the inner finalize loop, leaving each write buffer
neither finalized nor cancelled. Skipping the commit leaves no dangling
state: the kernel handle stays owned by its wrapper and is freed by
ffi::free_transaction, the same uncommitted-transaction path the
partitioned sink and the Iceberg writer already take today.

Guarding inside WriteTransaction::commit instead would cover both sinks in
one place, but it would make a function named commit a silent no-op and
foreclose a legitimate future metadata-only commit (a remove-action DELETE,
a schema change). The knowledge that an INSERT produced no files belongs to
the sink, which is also where both sibling writers keep theirs.

Sibling surfaces, measured: the tree has exactly two commit call sites, the
unpartitioned sink (fixed here) and the partitioned sink (already held).
IcebergStorageSink::finalizeBuffers already applies the same rule via
writer_per_partition_key.empty(). The CREATE TABLE initial-log commit
always commits by design and is untouched.

No new setting and no default change, so no SettingsChangesHistory entry is
owed. Existing tables and logs are untouched and no version gaps are
created; the removed output was a protocol-valid no-op version that no
reader can depend on.

New stateless test with 6 arms: 3 are red before this change (both 0-row
shapes on an unpartitioned table, and a 0-row INSERT into a table that
already holds data), and 3 are unchanged by it, being the partitioned
0-row arm plus both non-empty-INSERT positive controls that prove the guard
is not too wide. Every table in the test has the same two columns and takes
the same INSERT, so the only difference between the unpartitioned and
partitioned arms is partitionColumns.

Closes ClickHouse#122020.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

An independent cold review plus a second-model gate ran over this diff: no blocker, no major
finding, nothing deferred.

💡 Noted, not blocking: the new test's header gives an over-broad reason for hand-writing the
_delta_log fixture. With allow_delta_lake_create_table = 1 a CREATE TABLE does write the
initial commit; what it cannot create is a partitioned Delta table, which is the actual reason the
fixture is hand-written here. The fixture choice is right, only its stated reason is loose, and
nothing in the test's coverage depends on it.

Verified by reading rather than asserted: the tree has exactly two commit call sites, so the
unpartitioned sink was the only divergent carrier; data_files.empty() cannot be true while a data
file exists; schema validation still runs for a 0-row INSERT; and the three arms that must redden
on a revert are exactly the three that do.

@clickhouse-gh clickhouse-gh Bot closed this Sep 24, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [13c21b2]

Summary: ✅


AI Review

Summary

The PR skips transaction-log commits for DeltaLake inserts that create no data files, matching the partitioned writer while preserving commits for written files. No actionable findings remain at 13c21b225415a6e8ef077dfde7ef91da18924368. The previous zero-row JSONColumns finding was resolved: the current insert pipeline filters these chunks in Squashing::add before they reach the sink. The new regression test covers empty inserts, non-empty inserts into both table layouts, and an empty append to an existing table; its original CI run passed 50 repetitions.

Missing context / blind spots
  • ⚠️ Completed test results for the current merge commit were unavailable, and no local ClickHouse binary was available. A completed head CI run would confirm the regression coverage after merging master.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 13c21b225415a6e8ef077dfde7ef91da18924368 was not compared: the CI logs cluster did not answer (exception 241, code 500: { "meta": [ { "name": "file", "type": "LowCardinality(String)" …).

See the job log for details.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f14cb30

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (arm_release, master_head, 6/6) / serialization_pool_lookup #0 dashboard gate verdict, and the sole red-maker: client_time 0.679 -> 0.840 s (+23.7%), tier confirmed_regression. The shard's own report reads 2 too long with zero slower, and in master_head mode only error_tests or the dashboard gate can fail a shard (ci/jobs/performance_tests.py:2795-2816). The query is recurrently noisy on this metric: slower on 31 distinct pull requests over 7 days, 22 of those rows on true master, against 32014 success rows in 14 days, and 117 distinct pull requests have taken a dashboard-confirmed red shard in the two days since the in-tree half #121847 merged. Measured at the tree that actually ran (c54e883513ce, job 107871874076), #121847 IS present and the shard reddened anyway, so it is not the owner ClickHouse/performance-comparison#5 (external, open; the dashboard confidence-scoring half)
Mergeable Check, PR commit-status rollups of the shard above, no independent failure ClickHouse/performance-comparison#5 (external, open)

Nothing is PR-caused. The diff is src/Storages/ObjectStorage/DataLakes/DeltaLake/DeltaLakeSink.cpp
plus one stateless test, and the failing leaf is a serialization-pool benchmark that reaches no Delta
Lake code path. CH Inc sync measured success at this head (00:51:07Z).

Gates (a) to (d): 0 of 338 check runs on this head are queued or running. 168 of them belong to the
first praktika dispatch, which was cancelled when the run was re-dispatched; the live dispatch finished
with Finish Workflow success at 2026-09-25T01:32:25Z, 2 h 44 min before this post, leaving one genuine
failure, which is owned above.

Session id: cron:our-pr-ci-monitor:20260925-040239

zlareb1 added a commit to zlareb1/ClickHouse that referenced this pull request Sep 25, 2026
…w commit to its fix

- 05227: a Delta `boolean` column fed from an `Int32` source: 0 and 1 round-trip, every other value is stored as `true` with and without the accurate cast (`accurateCast` to `Bool` accepts every value, so no rejection exists to pin).
- 05225: the unpartitioned 0-row INSERT case is dropped; ClickHouse#122092 changes that behaviour and carries its own test. The partitioned case (no version) stays.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@SmitaRKulkarni SmitaRKulkarni self-assigned this Sep 27, 2026
zlareb1 added a commit to zlareb1/ClickHouse that referenced this pull request Oct 12, 2026
…w commit to its fix

- 05227: a Delta `boolean` column fed from an `Int32` source: 0 and 1 round-trip, every other value is stored as `true` with and without the accurate cast (`accurateCast` to `Bool` accepts every value, so no rejection exists to pin).
- 05225: the unpartitioned 0-row INSERT case is dropped; ClickHouse#122092 changes that behaviour and carries its own test. The partitioned case (no version) stays.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@SmitaRKulkarni SmitaRKulkarni self-assigned this Oct 27, 2026
@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-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 19, 2026

This branch has not been deployed

No deployments
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 comp-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeltaLake writes: a 0-row INSERT commits an empty version on an unpartitioned table but nothing on a partitioned one

3 participants