diff --git a/src/Processors/Formats/Impl/MsgPackRowInputFormat.cpp b/src/Processors/Formats/Impl/MsgPackRowInputFormat.cpp index f8e80355f77c..8068879f3910 100644 --- a/src/Processors/Formats/Impl/MsgPackRowInputFormat.cpp +++ b/src/Processors/Formats/Impl/MsgPackRowInputFormat.cpp @@ -401,11 +401,6 @@ bool MsgPackVisitor::start_array(size_t size) // NOLINT } else if (isTuple(removeNullable(info_stack.top().type))) { - const auto & tuple_type = assert_cast(*removeNullable(info_stack.top().type)); - const auto & nested_types = tuple_type.getElements(); - if (size != nested_types.size()) - throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Cannot insert MessagePack array with size {} into Tuple column with {} elements", size, nested_types.size()); - /// If the type is Nullable, reaching start_array means the value /// is non-null (for nulls, the parser calls visit_nil instead). /// So we can safely unwrap the Nullable to work with the inner @@ -418,6 +413,11 @@ bool MsgPackVisitor::start_array(size_t size) // NOLINT column_ptr = &nullable_column.getNestedColumn(); } + const auto & tuple_type = assert_cast(*removeNullable(info_stack.top().type)); + const auto & nested_types = tuple_type.getElements(); + if (size != nested_types.size()) + throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Cannot insert MessagePack array with size {} into Tuple column with {} elements", size, nested_types.size()); + ColumnTuple & column_tuple = assert_cast(*column_ptr); /// Push nested columns into stack in reverse order. for (ssize_t i = static_cast(nested_types.size()) - 1; i >= 0; --i)