Repository navigation
Open
Labels
Description
Source audit of Altinity/ClickHouse PR #2289
AI audit note: This report was generated by AI (GPT-6.1 Sol).
PR: #2289
Reviewed revision: 4b7cfeb53115c65f034d494408c1610b65071a49.
Confirmed defects
Medium: Same-type reordering rejects optional complex columns
- Anchor:
src/Storages/ObjectStorage/DataLakes/Iceberg/MetadataGenerator.cpp:861–887,generateModifyColumnMetadata. - Trigger: An externally written optional Iceberg list is exposed as
Array(Int32). RequestMODIFY COLUMN arr Array(Int32) FIRSTor an equivalentAFTERmove. - Impact: Valid same-type positioning fails with
BAD_ARGUMENTS; omitting the type succeeds. Optional structs and maps have the same problem. This is a gap in the new positioning feature, not a newly introduced type-evolution regression. - Why:
IcebergSchemaProcessor::getFieldTypeignores top-level optionality for complex types, butgetIcebergTypereturnsrequired=truefor arrays, tuples, and maps. The equality branch therefore fails for a stored optional complex field, sending the unchanged descriptor intocheckValidSchemaEvolution, which rejects list/struct/map descriptors.
if (current_field->getValue<bool>(Iceberg::f_required) == new_type.second
&& icebergTypesEqualIgnoringIds(current_field->get(Iceberg::f_type), new_type.first))- Fix direction: Recognize unchanged complex types while preserving their stored optionality; do not interpret restating the reader's type as a request to tighten optionality.
- Regression test direction: Reorder externally defined optional list/struct/map fields with explicit unchanged types; verify order, field IDs, and optionality. Compare with position-only syntax.
Medium: A committed positional add can be reported as failed on retry
- Anchor:
src/Storages/ObjectStorage/DataLakes/Iceberg/MetadataGenerator.cpp:366–368,isAddColumnApplied;Mutations.cpp,alterAlreadyAppliedandalter;MetadataGenerator.cpp:790, duplicate-column rejection. - Trigger: The catalog commits
ADD COLUMN c ... AFTER a, producing[a, c, b], but returns a retryable 5xx. Before the retry reads metadata, another writer commitsADD COLUMN d ... AFTER a, producing[a, d, c, b]. The equivalent interleaving exists forFIRST. - Impact: The original request reports
BAD_ARGUMENTS(Column c already exists) despite having successfully persisted its change. This is a correctness/reliability failure under narrow concurrency and integration-error conditions, not merely a diagnostic issue. - Why: The new adjacency check rejects the already committed add after a later legitimate DDL changes its position. The retry then attempts to add the existing column again. Before this PR, the retry predicate ignored position.
return field->getValue<bool>(Iceberg::f_required) == expected_type.second
&& icebergTypesEqualIgnoringIds(field->get(Iceberg::f_type), expected_type.first)
&& isFieldAtRequestedPosition(fields, i, column_name, first, after_column);- Fix direction: Recognize the attempted change in committed schema history, ideally tied to the attempted commit, rather than requiring its original adjacency in the latest schema. Simply removing the position check is insufficient: it can report false success if the original commit did not land and another writer independently added the same column/type at the wrong position.
- Regression test direction: Cover both interleavings: own commit landed, then adjacency changed (success); own commit rejected, then another writer added the same column at the wrong position (must not report success). Ordinary duplicate rejection when a user issues a fresh
ADD COLUMNafterward is expected, not a separate defect.
Low: Already-satisfied positioning creates redundant schemas
- Anchor:
src/Storages/ObjectStorage/DataLakes/Iceberg/MetadataGenerator.cpp:848,907–956,generateModifyColumnMetadata. - Trigger: Repeatedly request
FIRSTfor the first column, orAFTERwhen the column is already immediately after its target, without changing its type. - Impact: File-backed tables append an identical schema and write another metadata version on every execution, unnecessarily growing metadata and parsing costs. Only self-
AFTERis recognized as a positional no-op. The REST catalog's equivalent-schema handling limits schema duplication there; it does not remove the file-backed issue. - Why: The decision to reposition depends on the presence of a clause, not whether the current position already satisfies it.
bool needs_reposition = first || (!after_column.empty() && after_column != column_name);- Fix direction: Check the current position before deciding to generate a schema, while still applying any genuine type change.
- Regression test direction: Repeat already-satisfied positioning and assert unchanged schema count, schema ID, and metadata version.
Coverage summary
- Scope reviewed: All 12 changed files at the reviewed revision, including test source; parsing/preparation, Iceberg clause validation, metadata generation, schema reading/transformation, filesystem and REST/Glue commit boundaries, retries, and cache invalidation.
- Call graph:
ALTERparsing → command validation/preparation → Iceberg clause checks → in-memory command application and metadata generation → filesystem/catalog commit → retry recognition → cache invalidation/schema refresh. - Invariants checked: Reordering preserves field IDs and historical schemas; rejected commands do not persist partial changes; same-type positioning preserves stored types/optionality; retry recognition distinguishes applied changes from conflicting changes; genuine no-ops avoid unnecessary metadata mutations.
- Transitions reviewed: Add at end/first/after; modify type-only/position-only/combined; self-
AFTER; already-satisfied position; missing/duplicate columns and missing positioning targets; unsupported clauses; successful/rejected/unknown-outcome commits; cancellation and retry exhaustion; subsequent reading and schema transformation.
| Logical fault category | Status | Outcome |
|---|---|---|
| Type identity, optionality, and evolution | Executed (static reasoning) | Failed: optional complex same-type positioning |
| Positional generation, IDs, and historical schemas | Executed (static reasoning) | No additional confirmed defect |
| Invalid targets and unsupported clauses | Executed (static reasoning) | No additional confirmed defect |
| Commit errors, retries, and concurrent DDL | Executed (static reasoning) | Failed: successful positional add reported as failed |
| No-op behavior and resource growth | Executed (static reasoning) | Failed: redundant schemas in file-backed tables |
| Lifetime, iterator invalidation, ownership, casts, and integer bounds | Executed (static reasoning) | No additional confirmed defect |
| Lock ordering, shared-state interleavings, and exception/partial-update paths | Executed (static reasoning) | No additional confirmed defect |
| Authentication/authorization changes | Not applicable | No changed authentication or authorization logic |
| Runtime fault injection, builds, and test execution | Deferred | Explicitly excluded by the requested source-only review |
- Interleavings considered: Concurrent commit before a filesystem/catalog commit attempt; catalog commit followed by an unknown-outcome response and retry; intervening positional DDL before retry; cancellation between retry attempts. Metadata JSON is parsed into per-attempt objects rather than sharing a mutable cached JSON object.
- Coverage accounting: Changed nodes and the listed transitions were reviewed; external service implementations, the full unchanged storage subsystem, and runtime timing were not exhaustively audited. Static in-scope coverage is complete with the explicit limits above; this is not runtime verification.
- Assumptions/limits: No builds or tests were run. External catalog timing and runtime behavior remain unverified. Findings are source-confirmed, not experimentally reproduced. No confirmed high-severity memory-safety, deadlock, or data-corruption defect was found in the reviewed scope.
- Confidence: High for the three demonstrated code paths. Regression tests, especially controlled commit-unknown/concurrent-DDL fault injection, would provide runtime confirmation.
Activity