Repository navigation
Conversation
1ef19aa to
feb0f8e
Compare
feb0f8e to
10aa714
Compare
| return std::make_shared<ColumnTuple>(columns, std::move(names)); | ||
| auto tuple = any_named ? std::make_shared<ColumnTuple>(columns, std::move(names)) | ||
| : std::make_shared<ColumnTuple>(columns); | ||
| if (ast.meta == TypeAst::Nested) { |
There was a problem hiding this comment.
Nested takes the Tuple path and is wrapped here, so its elements are read from the AST by reference. An earlier version of this PR copied the node into a Tuple first, which costs the subtree at every level: about 180 MiB (macOS arm64) to 215 MiB (Linux aarch64) of peak RSS for 200 levels over 8 000 fields, the pattern #588 removes from LowCardinality. DeepNestedDoesNotCopyAst holds it.
272ddd0 to
9d61241
Compare
The type parser had no entry for Nested, so a column typed Array(Nested(key String, value String)) was created as Array(Void) and the native block stream fell out of sync: an empty server exception without compression, "some data was not read" with LZ4. A top-level Nested column, which the server sends with flatten_nested = 0, was rejected as unsupported. The server defines Nested as a custom name over Array(Tuple(...)) (DataTypeNested.cpp). The parser now recognises Nested as its own node, like Map and SimpleAggregateFunction, and the column factory builds it in the Tuple case, wrapped in an Array. Sharing that case keeps the AST read by reference, so a deeply nested type is not copied at every level. Closes ClickHouse#571
9d61241 to
2a43875
Compare
|
The seven tests of the Do you want these ten tests enabled in this pull request or in a separate one? |
Closes #571.
Summary
TypeParserhad no entry forNested, so the name became aVoidterminal. At the rootValidateASTrejects it ("unsupported column type"), but inside a container nothing checks it:Array(Nested(key String, value String))was created asArray(Void),ColumnNothingreads one byte per row and the block stream desynchronises.Nestedis now its own AST node, next toMapandSimpleAggregateFunction, and the column factory builds it in theTuplecase, wrapped in anArray. That is how the server defines it:DataTypeNested.cppbuildsDataTypeArray(DataTypeTuple(types, names))under a custom name. Sharing theTuplecase keeps the AST read by reference, so a deeply nested type is not copied at every level, the pattern #588 removes fromLowCardinality.Behavior changes
Array(Nested(...))andMap(K, Nested(...))columns decode, with their field names kept on theTuple.Nestedcolumn, which the server sends withflatten_nested = 0, decodes instead of failing with "unsupported column type".Array(Tuple(key String, value UInt8))rather thanNested(...). The server accepts that name onINSERT: a block selected from such a column goes back in as is (ArrayOfNested_ReinsertSelectedRows), and a block built with unnamed tuples goes in too (checked against 25.12, 26.3 and 26.11). A dedicatedNestedcolumn type would add public API for no behavioural gain, so I did not go that way. Happy to discuss.TypeAst::Metagains theNestedvalue.Tests
type_parser_ut: theNestednode with its named elements, and a field itself namedNested.CreateColumnByType_ut:Nested,Array(Nested),Map(String, Nested)andNested(a Nested(...))give the expected column types.DeepNestedDoesNotCopyAstbuilds 200 levels ofNestedover 8 000 fields and checks that peak RSS grows by less than 16 MiB. When the node is copied at each level it grows by about 180 MiB on macOS arm64 and 215 MiB on Linux aarch64. The measure runs in a child process (EXPECT_EXIT, hence theDeathTestsuite), so a peak that an earlier test reached and released does not count. It readsgetrusage, so it runs on Linux and macOS and skips on Windows.client_ut, both fixtures (no compression and LZ4): select from a server-typedArray(Nested(...))column with empty inner and outer arrays, insert a selected block back as is and read it back withtoString, and a top-levelNestedcolumn withflatten_nested = 0.Each new test fails when the
Nestedentry inGetTypeMetais removed. Before this change, onmasterfc5d98f:CreateColumnByType("Array(Nested(key String, value UInt8))")Array(Void)Array(Array(Tuple(key String, value UInt8)))Selecton that column, no compressionArray(Void)in the callback, then an empty server exceptionSelecton that column, LZ4some data was not readSelecton aNestedcolumn,flatten_nested = 0unsupported column type: Nested(key String, value UInt8)Select, then insert the block backSelectFull suite green locally (macOS arm64, Apple clang 21) against ClickHouse 26.11.1 master build, except the
Remote*tests, which need external TLS endpoints, andSocketcase.connecttimeout, not run. The new client tests also pass against 25.12 and 26.3. Under AddressSanitizer and UBSan, the parser and factory suites pass on this branch, and the client and roundtrip suites with #590 on top, UBSan reporting only theInsertDatareads noted below. The branch also builds without warnings with GCC 14 on Linux aarch64, where the server-free suite passes.Out of scope
ValidateASTonly checks the root, so any other unknown type nested in a container still becomes aVoidcolumn and is misread, the second point of the suggested fix in Array(Nested(...)) columns silently decode as Array(Nothing) and desynchronize the native block stream #571. Tracked separately in Unknown type names inside a container are misread instead of rejected #589, with a draft in Reject unknown type names inside containers #590.InsertDatatest reads pastTEST_DATAunder UBSan and depends on block order. Test code only, fixed separately in Make InsertData independent of block boundaries and order #576.