Skip to content

Support schema evolution in legacy DeltaLake metadata parser - #101446

Closed
Daedalus-Icarus wants to merge 23 commits into
ClickHouse:masterfrom
Daedalus-Icarus:fix/issue-100438
Closed

Daedalus-Icarus wants to merge 23 commits into
ClickHouse:masterfrom
Daedalus-Icarus:fix/issue-100438

Conversation

@Daedalus-Icarus

@Daedalus-Icarus Daedalus-Icarus commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

The legacy DeltaLakeMetadataImpl (used for Azure and non-kernel S3 paths) threw NOT_IMPLEMENTED when encountering schema changes in _delta_log metadata entries or checkpoint files. This made deltaLakeAzure fail on tables with schema evolution (e.g., added columns).

Instead of throwing, adopt the latest schema — matching the behavior of the DeltaKernel path. Delta log entries are processed in version order, so the last metaData entry always represents the current table schema. Older data files with fewer columns will return NULLs for missing columns, which is the expected behavior.

Closes #100438

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 deltaLakeAzure and legacy deltaLake (non-kernel) failing with NOT_IMPLEMENTED error on schema-evolved tables. Schema evolution (e.g., adding columns) is now handled by adopting the latest schema, matching the DeltaKernel behavior.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

No documentation changes required — this is a bug fix aligning existing behavior with the documented DeltaKernel path.

@Avogar Avogar added the can be tested Allows running workflows for external contributors label Apr 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6c549b2]

Summary: ✅


AI Review

Summary

This PR makes the legacy DeltaLakeMetadata path accept schema evolution in _delta_log JSON files and checkpoints, and it enables Parquet reads with missing columns. The checkpoint/log-order fixes look correct in HEAD, but the fix is still incomplete for persistent DeltaLake / DeltaLakeAzure engine tables: after an external schema change, query analysis still uses stale StorageInMemoryMetadata, so the added column stays invisible unless the table is recreated.

Findings
  • ❌ [src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h:109-118, src/Storages/ObjectStorage/StorageObjectStorage.cpp:434-438] configuration->update recreates the legacy DeltaLakeMetadata object with the latest schema on every query, but updateExternalDynamicMetadataIfExists refreshes StorageInMemoryMetadata only when getTableStateSnapshot returns a state. The legacy parser still returns nullopt, so an existing DeltaLake / DeltaLakeAzure engine table created before an external append keeps its old columns forever: SELECT age still fails during analysis, and SELECT * never exposes the added column. That violates the PR's contract for schema-evolved legacy tables. Suggested fix: either implement a state / buildStorageMetadataFromState path for legacy Delta Lake, or explicitly rebuild and setInMemoryMetadata from the refreshed legacy schema after configuration->update. Add a regression that creates the engine table before the external schema evolution and queries the new column afterward.
Final Verdict

Changes requested. The table-function and checkpoint paths look good now, but the persistent legacy engine path still does not pick up evolved columns.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 1, 2026
@Avogar Avogar self-assigned this Apr 1, 2026

@Avogar Avogar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix is incomplete:

  1. There are no integration tests for schema evolution in legacy DeltaLake metadata parser. Please, try to write an integration test.
  2. If we allow schema evolution, we should also implement DeltaLakeMetadata::modifyFormatSettings that will set format_settings.parquet.allow_missing_columns = true
  3. There are stale comments in DeltaLakeMetadata.cpp:237-238 about not supported schema evolution

Daedalus-Icarus and others added 4 commits April 3, 2026 04:11
1. Add integration test `test_schema_evolution_add_column_legacy` that
   verifies the legacy metadata parser (with DeltaKernel disabled) correctly
   handles schema evolution when columns are added. Old data files return
   NULLs for missing columns.

2. Implement `DeltaLakeMetadata::modifyFormatSettings` to set
   `format_settings.parquet.allow_missing_columns = true`, matching the
   existing `DeltaLakeMetadataDeltaKernel` behavior. Without this, the
   Parquet reader would reject files that lack columns added after initial
   table creation.

3. Fix stale comments in `DeltaLakeMetadata.cpp` that incorrectly stated
   schema evolution is not supported, and fix "partiion" typo.
…lity

Spark writes all columns as nullable in Delta Lake JSON metadata regardless
of the Spark `nullable` flag, so the legacy parser returns `Nullable` types.
Update test expectations to match: `Nullable(Int32)` / `Nullable(String)`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The checkpoint parser had two separate loops: first iterating all rows to
extract schema (updating `file_schema` to the latest version), then iterating
again to extract data files and decode partition values using the final schema.

This is incorrect when a checkpoint contains `metaData` entries from multiple
schema versions interleaved with `add` entries: older rows' partition values
would be decoded against the wrong (latest) schema, potentially throwing
"No such column in schema" or mis-parsing values after a column rename/type change.

Merge into a single pass so each `add` row's partition values are decoded
against the schema active at that row's position, matching the behavior
of `processMetadataFile`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

Checkpoint Parquet files have no guaranteed row ordering. If add rows
with partition values appear before the metaData row that establishes
the schema, the partition value decoder would fail with
"No such column in schema" because `file_schema` is still empty.

Fix: buffer add-row indices that arrive before schema is initialized.
Once the metaData row is processed and `file_schema` is populated,
decode the buffered rows immediately. File paths are still registered
on first encounter regardless of schema availability.

If the checkpoint has no metaData row at all (invalid), log a warning
and skip partition decoding for those files instead of crashing.
@kssenii kssenii self-assigned this Apr 10, 2026
@Daedalus-Icarus

Daedalus-Icarus commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @kssenii is there any update on here?

Daedalus-Icarus and others added 2 commits April 10, 2026 23:24
The `ErrorCodes::NOT_IMPLEMENTED` throws were removed when schema evolution
support was added, but the declaration was left behind. The style check
flags unused error code declarations.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kssenii kssenii reopened this Apr 30, 2026
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/DeltaLakeMetadata.cpp
@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Dear @kssenii, 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.

@kssenii kssenii self-assigned this Jun 4, 2026
alexey-milovidov and others added 3 commits June 11, 2026 00:29
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/DeltaLakeMetadata.cpp
In the no-checkpoint path, `processMetadataFiles` replayed `_delta_log/*.json`
entries in listing order, which is not guaranteed to be version order (e.g.
local object storage lists in directory iteration order). Since schema
evolution adopts the schema of the last processed `metaData` entry, an
out-of-order listing could downgrade `file_schema` to an older schema.
Sort the keys: delta log file names are zero-padded version numbers, so
lexicographic order is version order.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Pushed two updates:

  • Merged master (the previous CI run was on a 9-day-old base; both red checks were master-wide issues already fixed on master: the Unit tests (asan_ubsan) UBSan failure in UntrackedMemoryRegistry was reverted on master, and the 00096_obfuscator_save_load / 00175_obfuscator_schema_inference failures were a one-day master-wide breakage on 2026-06-03 with 104 failures across ~100 PRs including master itself).
  • 6f040f6: sort the listed _delta_log/*.json keys in the no-checkpoint path of processMetadataFiles before replaying, so that entries are applied in version order and the latest metaData entry wins regardless of listing order (addresses the review comment).

@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master to refresh CI: the branch was ~3 days / 1256 commits behind, and the only red check was FunctionsStress.stress (1 threads got stuck) in Unit tests (asan_ubsan, function_prop_fuzzer) — a master-wide flake that fails daily across unrelated PRs and on master itself (PR=0), not caused by this change.

The merge was conflict-free. master's throwFromArrowStatus change in getCheckpointIfExists (which removed the local THROW_ARROW_NOT_OK macro) coexists cleanly with this PR's schema-evolution, single-pass checkpoint parsing, and modifyFormatSettings changes — verified no dangling macro references remain. All review threads are resolved and Avogar's three points (integration test, modifyFormatSettings enabling parquet.allow_missing_columns, stale comments) are addressed. Fresh CI is running.


NamesAndTypesList getTableSchema(ContextPtr /*local_context*/) const override { return schema; }

void modifyFormatSettings(FormatSettings & format_settings, const Context &) const override;

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.

This fixes the Parquet read once the new column is requested, but the persistent engine path can still keep stale columns after external schema evolution.

StorageObjectStorage::updateExternalDynamicMetadataIfExists calls configuration->update, then returns when getTableStateSnapshot is null; legacy DeltaLakeMetadata does not override that API. So an existing DeltaLakeAzure or legacy DeltaLake table created before an appended schema change keeps its old StorageInMemoryMetadata: DESCRIBE and query analysis will not see the added column, and SELECT age fails before modifyFormatSettings or the new parser can help.

The PR body promises the DeltaLakeAzure engine path too. Please refresh the storage metadata for the legacy path (or add a pinned table-state snapshot/rebuild path like DeltaLakeMetadataDeltaKernel) and cover it with a regression that creates the engine before the schema-evolved append.

@alexey-milovidov

alexey-milovidov commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Do we care about the old DeltaLake metadata parser? I don't think so.
CC @kssenii

@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label Jun 17, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master to refresh CI: the branch had drifted past one week behind (merge-base b5fa90e2908 from 2026-06-15, ~3160 commits behind). The merge was conflict-free; the only churn in the PR's footprint was in tests/integration/test_storage_delta/test.py (master's Ruff cleanup and the DeltaLake catalog/cache test updates), which are now incorporated. The DeltaLake parser changes (DeltaLakeMetadata.cpp/.h) are unchanged — master has not touched them. The PR remains blocked on the open question of whether the legacy (non-kernel) DeltaLake metadata parser is worth maintaining.

Refresh CI: the branch was ~11 days behind master (merge-base 2026-06-22).
The merge is conflict-free. Master has not touched DeltaLakeMetadata.cpp/.h;
the only churn in the PR's footprint is in tests/integration/test_storage_delta/test.py
(master's flaky-check tweaks), now incorporated. Verified the PR's
DeltaLakeMetadata.cpp still compiles cleanly (-fsyntax-only) against current master headers.
@CLAassistant

CLAassistant commented Jul 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ Daedalus-Icarus
✅ alexey-milovidov
❌ Desel72


Desel72 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master to refresh CI: the branch was ~11 days behind (merge-base 73f1f3a36d7 from 2026-06-22). The merge was conflict-free. master has not touched DeltaLakeMetadata.cpp/.h; the only churn in the PR's footprint was in tests/integration/test_storage_delta/test.py (master's flaky-check tweaks), now incorporated. Verified the legacy parser's DeltaLakeMetadata.cpp still compiles cleanly against current-master headers.

The previous run's only red — test_quorum_inserts_parallel::test_parallel_quorum_actually_quorum (Timeout) in Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6) — is unrelated to this change (a master-wide flake).

The PR remains blocked on the open question of whether the legacy (non-kernel) DeltaLake metadata parser is worth maintaining, and on the remaining review point that the persistent-engine path (DeltaLakeAzure / legacy DeltaLake engine tables) does not yet refresh StorageInMemoryMetadata after external schema evolution. CC @kssenii

@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.60% +0.10%
Functions 92.60% 92.70% +0.10%
Branches 77.70% 77.70% +0.00%

Changed lines: Changed C/C++ lines covered: 42/69 (60.87%) · Uncovered code

Full report · Diff report

@PedroTadim

Copy link
Copy Markdown
Member

Hello! Is this PR going to be merged?

@alexey-milovidov alexey-milovidov added the hold Skip for auto-updating. label Jul 7, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

It will be closed in ten days if no one answers the question #101446 (comment)

@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Dear @kssenii, 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.

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 close in a month if not active This will be closed in case of no information hold Skip for auto-updating. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deltaLakeAzure throws NOT_IMPLEMENTED (Code 48) on schema-evolved tables

6 participants