Repository navigation
Fix iceberg write for metadata without refs - #106896
Conversation
It can happen when the table was created outside of ClickHouse (BigLake/Lakehouse in my case). ``` Code: 1000. DB::Exception: Null pointer. (POCO_EXCEPTION) (version 26.5.1.882 (official build)) stack_trace: 0. DB::MetadataGenerator::generateNextMetadata(DB::FileNamesGenerator&, DB::Iceberg::IcebergPathFromMetadata const&, long, long, long, long, long, long, long, std::optional<long>, std::optional<long>) @ 0x000000001a063a83 1. DB::IcebergStorageSink::initializeMetadata() @ 0x000000001a03939b 2. DB::IcebergStorageSink::onFinish() @ 0x000000001a038da8 3. DB::runStep(std::function<void ()>, std::shared_ptr<DB::ThreadGroup>&) @ 0x000000001db85880 4. DB::ExceptionKeepingTransform::work() @ 0x000000001db853cb 5. DB::ExecutionThreadContext::executeTask() @ 0x000000001d89b033 6. DB::PipelineExecutor::executeStepImpl(unsigned long, DB::IAcquiredSlot*, std::atomic<bool>*) @ 0x000000001d889f04 7. DB::PipelineExecutor::execute(unsigned long, bool) @ 0x000000001d888294 8. void std::__function::__policy_func<void ()>::__call_func[abi:fqe220101]<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::CompletedPipelineExecutor::execute()::$_0>(DB::CompletedPipelineExecutor::execute()::$_0&&)::'lambda'()>(std::__function::__policy_storage const*) @ 0x000000001d8870c6 9. ThreadPoolImpl<std::thread>::ThreadFromThreadPool::worker() @ 0x00000000173a34c0 10. void* std::__thread_proxy[abi:fqe220101]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x00000000173aaeda 11. ? @ 0x0000000000094ac3 12. ? @ 0x00000000001268d0 ```
|
Workflow [PR], commit [a52c0d0] Summary: ✅
AI ReviewSummaryThis PR fixes the Final Verdict✅ No actionable findings. |
|
The newly added |
thank you! fixed |
… arrays generateNextMetadata (the Iceberg INSERT write path) reads three arrays the Iceberg spec marks optional - snapshots, metadata-log, snapshot-log - without checking they exist. Metadata produced by an external engine may omit any of them, so the INSERT aborts: a missing snapshots makes getParentSnapshot extract an empty Var (Poco::InvalidAccessException), and a missing log array makes getArray return a null Array::Ptr that the following ->add dereferences (Poco::NullPointerException). This is reachable for an empty externally-created table: the read path returns the schema from parseTableSchema and, because current-snapshot-id is absent/-1, returns early before the snapshot-traversal guard that would otherwise reject a missing snapshots, so the write path is reached. Seed each missing array as a Poco::JSON::Array::Ptr (not a raw Array*, which would reproduce the same type-tag trap getObject/getArray hit) before use. This is a follow-up to PR ClickHouse#106896, which fixes the same bug class for the optional refs object; the refs line is intentionally not touched here to avoid conflicting with that one-line change, so the bug class is fully closed only once both land. Related: ClickHouse#106896 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
# Conflicts: # tests/integration/test_database_iceberg/test.py
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 3/4 (75.00%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
08b7e60
|
Hi @AVMusorin @tiandiwonder — while reviewing this PR I found the following:
Happy to discuss — close anything that's wrong or already addressed. |
|
Update on the earlier review: CI on the proof PR #112024 confirmed the suspected bug via
(Automated follow-up. The proof PR has been closed; please track the bug on the Issue.) |
`refs` is optional in the Iceberg spec, so a metadata file written by another engine may not contain it. `generateManifestOnlySnapshot` seeded the missing key with a raw `Poco::JSON::Object *`. `Poco::JSON::Object::set` records the value's static type in a `Dynamic::Var`, and `Object::getObject` matches strictly on `typeid(Object::Ptr)` and returns a null `Ptr` for any other type tag rather than throwing. The `getObject(refs)->has(main)` call three lines below therefore dereferenced a null `SharedPtr` and threw `Poco::NullPointerException`, leaving manifest compaction permanently unavailable on such a table. The sibling builder `generateNextMetadata`, in the same file, already stores an `Object::Ptr`: it was corrected in ClickHouse#106896 for the insert path, and this copy was missed. Store an `Object::Ptr` here too, so `getObject` sees the expected type tag and the `refs.main` branch is written as intended. The same function already seeds `metadata_log` and `snapshot_log` as `Array::Ptr` for exactly this reason. A sweep of `set(..., new Poco::JSON::(Object|Array))` over src, programs and base returns this one site, so the change closes the class rather than one instance. Nothing relied on the null return: no caller of the changed function inspects the pre-seed value, and no setting, serialization format or on-disk state is affected. The regression test extends the existing IcebergMetadataGenerator suite, which already covers this family of omitted optional metadata fields. It asserts `isObject(refs)` rather than only the absence of a throw, because `isObject` uses the same type check as `getObject` and so also rejects re-introducing the raw-pointer spelling. Closes ClickHouse#112082
… arrays generateNextMetadata (the Iceberg INSERT write path) reads three arrays the Iceberg spec marks optional - snapshots, metadata-log, snapshot-log - without checking they exist. Metadata produced by an external engine may omit any of them, so the INSERT aborts: a missing snapshots makes getParentSnapshot extract an empty Var (Poco::InvalidAccessException), and a missing log array makes getArray return a null Array::Ptr that the following ->add dereferences (Poco::NullPointerException). This is reachable for an empty externally-created table: the read path returns the schema from parseTableSchema and, because current-snapshot-id is absent/-1, returns early before the snapshot-traversal guard that would otherwise reject a missing snapshots, so the write path is reached. Seed each missing array as a Poco::JSON::Array::Ptr (not a raw Array*, which would reproduce the same type-tag trap getObject/getArray hit) before use. This is a follow-up to PR ClickHouse#106896, which fixes the same bug class for the optional refs object; the refs line is intentionally not touched here to avoid conflicting with that one-line change, so the bug class is fully closed only once both land. Related: ClickHouse#106896 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
It can happen when the table was created outside of ClickHouse (BigLake/Lakehouse in my case).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix iceberg write for metadata without refs
Version info
26.8.1.182(included in26.8and later)