Skip to content

Commit e43b158

Browse files
Merge pull request ClickHouse#91399 from ClickHouse/backport/25.8/91270
Backport ClickHouse#91270 to 25.8: Fix inserting into CoalescingMergeTree column with Tuple of JSON/Dynamic and LowCardinality
2 parents ec28a5d + f837db0 commit e43b158

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -500,19 +500,12 @@ static void postprocessChunk(
500500
auto column = std::move(columns[next_column]);
501501
++next_column;
502502

503-
if (!desc.is_agg_func_type && !desc.is_simple_agg_func_type && isTuple(desc.function->getResultType()))
503+
if (!desc.aggregate_all_columns && !desc.is_agg_func_type && !desc.is_simple_agg_func_type && isTuple(desc.function->getResultType()))
504504
{
505-
if (desc.aggregate_all_columns)
506-
{
507-
res_columns[desc.column_numbers[0]] = column;
508-
}
509-
else
510-
{
511-
/// Unpack tuple into block.
512-
size_t tuple_size = desc.column_numbers.size();
513-
for (size_t i = 0; i < tuple_size; ++i)
514-
res_columns[desc.column_numbers[i]] = assert_cast<const ColumnTuple &>(*column).getColumnPtr(i);
515-
}
505+
/// Unpack tuple into block.
506+
const size_t tuple_size = desc.column_numbers.size();
507+
for (size_t i = 0; i < tuple_size; ++i)
508+
res_columns[desc.column_numbers[i]] = assert_cast<const ColumnTuple &>(*column).getColumnPtr(i);
516509
}
517510
else if (desc.nested_type)
518511
{
@@ -590,26 +583,14 @@ void SummingSortedAlgorithm::SummingMergedData::initialize(const DB::Block & hea
590583
for (const auto & desc : def.columns_to_aggregate)
591584
{
592585
// Wrap aggregated columns in a tuple to match function signature
593-
if (!desc.is_agg_func_type && !desc.is_simple_agg_func_type && isTuple(desc.function->getResultType()))
586+
if (!desc.aggregate_all_columns && !desc.is_agg_func_type && !desc.is_simple_agg_func_type && isTuple(desc.function->getResultType()))
594587
{
595-
if (desc.aggregate_all_columns)
596-
{
597-
auto column = desc.real_type->createColumn();
598-
size_t tuple_size = static_cast<const ColumnTuple &>(*column).tupleSize();
599-
MutableColumns tuple_columns(tuple_size);
600-
for (size_t i = 0; i < tuple_size; ++i)
601-
tuple_columns[i] = static_cast<const ColumnTuple &>(*column).getColumnPtr(i)->cloneEmpty();
602-
new_columns.emplace_back(ColumnTuple::create(std::move(tuple_columns)));
603-
}
604-
else
605-
{
606-
size_t tuple_size = desc.column_numbers.size();
607-
MutableColumns tuple_columns(tuple_size);
608-
for (size_t i = 0; i < tuple_size; ++i)
609-
tuple_columns[i] = std::move(columns[desc.column_numbers[i]]);
588+
const size_t tuple_size = desc.column_numbers.size();
589+
MutableColumns tuple_columns(tuple_size);
590+
for (size_t i = 0; i < tuple_size; ++i)
591+
tuple_columns[i] = std::move(columns[desc.column_numbers[i]]);
610592

611-
new_columns.emplace_back(ColumnTuple::create(std::move(tuple_columns)));
612-
}
593+
new_columns.emplace_back(ColumnTuple::create(std::move(tuple_columns)));
613594
}
614595
else
615596
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dynamic paths
2+
a
3+
Shared data parhs
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set mutations_sync=1;
2+
drop table if exists test;
3+
create table test (id UInt64, t Tuple(a LowCardinality(String), json JSON)) engine=CoalescingMergeTree order by id settings min_bytes_for_wide_part=1, min_rows_for_wide_part=1, index_granularity=32, merge_max_block_size=32;
4+
insert into test select number, tuple('str', '{}') from numbers(100);
5+
alter table test update t = tuple('str', '{"a" : 42}') where id > 90;
6+
optimize table test final;
7+
select 'Dynamic paths';
8+
select distinct arrayJoin(JSONDynamicPaths(t.json)) from test;
9+
select 'Shared data parhs';
10+
select distinct arrayJoin(JSONSharedDataPaths(t.json)) from test;
11+
drop table test;
12+

0 commit comments

Comments
 (0)