Merge pull request #28762 from CurtizJ/fix-nested-1

Fix usage of nested columns with non-array columns with the same prefix [2]
This commit is contained in:
Anton Popov 2021-09-10 17:34:43 +03:00 committed by GitHub
commit 0bb74f8eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -135,10 +135,11 @@ void IMergeTreeReader::fillMissingColumns(Columns & res_columns, bool & should_e
String offsets_name = Nested::extractTableName(name);
auto offset_it = offset_columns.find(offsets_name);
if (offset_it != offset_columns.end())
const auto * array_type = typeid_cast<const DataTypeArray *>(type.get());
if (offset_it != offset_columns.end() && array_type)
{
const auto & nested_type = array_type->getNestedType();
ColumnPtr offsets_column = offset_it->second;
DataTypePtr nested_type = typeid_cast<const DataTypeArray &>(*type).getNestedType();
size_t nested_rows = typeid_cast<const ColumnUInt64 &>(*offsets_column).getData().back();
ColumnPtr nested_column =

View File

@ -0,0 +1,2 @@
123 asd [1,2]
123 asd [1,2] 0

View File

@ -0,0 +1,18 @@
DROP TABLE IF EXISTS test_nested;
CREATE TABLE test_nested
(
`id` String,
`with_dot.str` String,
`with_dot.array` Array(Int32)
)
ENGINE = MergeTree()
ORDER BY id;
INSERT INTO test_nested VALUES('123', 'asd', [1,2]);
SELECT * FROM test_nested;
ALTER TABLE test_nested ADD COLUMN `with_dot.bool` UInt8;
SELECT * FROM test_nested;
DROP TABLE test_nested;