From ea59e1f8fc7e197f955d15afa38bb645b7963f5b Mon Sep 17 00:00:00 2001 From: Moaaz Assali <66834697+moaazassali@users.noreply.github.com> Date: Mon, 1 Jul 2024 01:54:29 +0400 Subject: [PATCH] bug fix in Append() for nullable columns If Append() of the nested column fails, the nulls column will be incremented despite nothing being appended. It will also be marked as not null, causing an error to be thrown if this new "fake" value in the column is accessed later. this fixes that by moving the appending of the nulls markers to the end of the Append() operation of the nested column --- clickhouse/columns/nullable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clickhouse/columns/nullable.h b/clickhouse/columns/nullable.h index 1946e8b9..3140ccd1 100644 --- a/clickhouse/columns/nullable.h +++ b/clickhouse/columns/nullable.h @@ -95,12 +95,13 @@ class ColumnNullableT : public ColumnNullable { } 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{}); } + // Must be called after Append to nested column because it might fail + ColumnNullable::Append(!value.has_value()); } /** Create a ColumnNullableT from a ColumnNullable, without copying data and offsets, but by