Skip to content

Commit

Permalink
Merge pull request ClickHouse#70695 from CurtizJ/fix-filling-missed-a…
Browse files Browse the repository at this point in the history
…rrays

Fixed crash in filling of missed arrays
  • Loading branch information
CurtizJ authored Oct 16, 2024
2 parents f6fa842 + 143683a commit 582c908
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/Storages/MergeTree/IMergeTreeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,21 @@ void IMergeTreeReader::evaluateMissingDefaults(Block additional_columns, Columns
auto it = original_requested_columns.begin();
for (size_t pos = 0; pos < num_columns; ++pos, ++it)
{
auto name_in_storage = it->getNameInStorage();

if (full_requested_columns_set.emplace(name_in_storage).second)
full_requested_columns.emplace_back(name_in_storage, it->getTypeInStorage());

if (res_columns[pos])
{
/// If column is already read, request it as is.
if (full_requested_columns_set.emplace(it->name).second)
full_requested_columns.emplace_back(it->name, it->type);

additional_columns.insert({res_columns[pos], it->type, it->name});
}
else
{
/// If column or subcolumn is missed, request full column for correct evaluation of defaults of subcolumns.
auto name_in_storage = it->getNameInStorage();
if (full_requested_columns_set.emplace(name_in_storage).second)
full_requested_columns.emplace_back(name_in_storage, it->getTypeInStorage());
}
}

auto dag = DB::evaluateMissingDefaults(
Expand All @@ -183,6 +191,12 @@ void IMergeTreeReader::evaluateMissingDefaults(Block additional_columns, Columns
it = original_requested_columns.begin();
for (size_t pos = 0; pos < num_columns; ++pos, ++it)
{
if (additional_columns.has(it->name))
{
res_columns[pos] = additional_columns.getByName(it->name).column;
continue;
}

auto name_in_storage = it->getNameInStorage();
res_columns[pos] = additional_columns.getByName(name_in_storage).column;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
2 ('aaa','bbb') [1,NULL,3]
3 ('ccc','ddd') [4,5,6]
1 foo bar 3 [0,1,0]
2 foo bar 3 [0,1,0]
2 aaa bbb 3 [0,1,0]
3 ccc ddd 3 [0,0,0]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20000
22 changes: 22 additions & 0 deletions tests/queries/0_stateless/03252_fill_missed_arrays.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DROP TABLE IF EXISTS t_fill_arrays;

CREATE TABLE t_fill_arrays
(
`id` String,
`mapCol` Map(String, Array(String)),
)
ENGINE = MergeTree
ORDER BY id
SETTINGS vertical_merge_algorithm_min_rows_to_activate = 1, vertical_merge_algorithm_min_columns_to_activate = 1, min_bytes_for_full_part_storage = 0;

INSERT INTO t_fill_arrays (id) SELECT hex(number) FROM numbers(10000);

ALTER TABLE t_fill_arrays ADD COLUMN arrCol Array(String) DEFAULT [];

INSERT INTO t_fill_arrays (id) SELECT hex(number) FROM numbers(10000);

SELECT count() FROM t_fill_arrays WHERE NOT ignore(arrCol, mapCol.values);

OPTIMIZE TABLE t_fill_arrays FINAL;

DROP TABLE t_fill_arrays;

0 comments on commit 582c908

Please sign in to comment.