Fix NullableT append exception guarantee#535
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes exception-safety for ColumnNullableT::Append(...) so that if the nested column’s Append() throws, the nullable column does not end up with an extra (incorrect) null-flag entry. This addresses the inconsistent-size/invalid-access behavior described in PR #376.
Changes:
- Add rollback logic to
ColumnNullableT::Append(...)to erase the last null-flag when nested append throws. - Apply the same rollback behavior to the
ColumnNullableT<ColumnJSON>specialization. - Add a unit test covering the regression case using
ColumnFixedStringthrowing validation errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ut/Column_ut.cpp |
Adds a regression test ensuring nullable size/nulls/nested sizes remain consistent when nested append throws. |
clickhouse/columns/nullable.h |
Adds exception rollback to keep nulls_ consistent if nested append fails. |
clickhouse/columns/json.h |
Mirrors the rollback behavior for the ColumnJSON nullable specialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
97
to
+99
| inline void Append(ValueType value) { | ||
| ColumnNullable::Append(!value.has_value()); | ||
| if (value.has_value()) { | ||
| typed_nested_data_->Append(std::move(*value)); | ||
| } else { | ||
| typed_nested_data_->Append(typename ValueType::value_type{}); | ||
| try { |
| typed_nested_data_->Append(typename ValueType::value_type{}); | ||
| } | ||
| } catch (...) { | ||
| Nulls()->template As<ColumnUInt8>()->Erase(Size() - 1); |
mshustov
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #376