Skip to content

Commit 31a334a

Browse files
authored
Merge pull request ClickHouse#80158 from Avogar/merge-engine-subcolumns
Fix reading subcolumns from Merge engine
2 parents d1e4965 + 4136348 commit 31a334a

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

src/Storages/StorageMerge.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,6 @@ void ReadFromMerge::initializePipeline(QueryPipelineBuilder & pipeline, const Bu
529529
{
530530
auto & child_plan = child_plans->at(i);
531531
const auto & table = *table_it;
532-
533-
const auto storage = std::get<1>(table);
534-
const auto storage_metadata_snapshot = storage->getInMemoryMetadataPtr();
535-
const auto nested_storage_snapshot = storage->getStorageSnapshot(storage_metadata_snapshot, context);
536-
537-
Names column_names_as_aliases;
538-
Aliases aliases;
539-
540532
auto source_pipeline = buildPipeline(child_plan, common_processed_stage);
541533

542534
if (source_pipeline && source_pipeline->initialized())
@@ -580,7 +572,7 @@ void ReadFromMerge::filterTablesAndCreateChildrenPlans()
580572
has_database_virtual_column = false;
581573
has_table_virtual_column = false;
582574
column_names.clear();
583-
column_names.reserve(column_names.size());
575+
column_names.reserve(all_column_names.size());
584576

585577
for (const auto & column_name : all_column_names)
586578
{
@@ -665,7 +657,7 @@ std::vector<ReadFromMerge::ChildPlan> ReadFromMerge::createChildrenPlans(SelectQ
665657

666658
if (storage_metadata_snapshot->getColumns().empty())
667659
{
668-
/// (Assuming that view has empty list of columns iff it's parameterized.)
660+
/// (Assuming that view has empty list of columns if it's parameterized.)
669661
if (storage->isView() && storage->as<StorageView>() && storage->as<StorageView>()->isParameterizedView())
670662
throw Exception(ErrorCodes::STORAGE_REQUIRES_PARAMETER, "Parameterized view can't be queried through a Merge table.");
671663
else
@@ -747,7 +739,7 @@ std::vector<ReadFromMerge::ChildPlan> ReadFromMerge::createChildrenPlans(SelectQ
747739

748740
Names column_names_to_read = column_names_as_aliases.empty() ? std::move(real_column_names) : std::move(column_names_as_aliases);
749741

750-
std::erase_if(column_names_to_read, [existing_columns = nested_storage_snapshot->getAllColumnsDescription()](const auto & column_name){ return !existing_columns.has(column_name); });
742+
std::erase_if(column_names_to_read, [existing_columns = nested_storage_snapshot->getAllColumnsDescription()](const auto & column_name){ return !existing_columns.has(column_name) && !existing_columns.hasSubcolumn(column_name); });
751743

752744
auto child = createPlanForTable(
753745
nested_storage_snapshot,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
1 (2,3) s1
2+
4 (5,6) s2
3+
2
4+
5
5+
3
6+
6
7+
1 2
8+
4 5
9+
s1 2
10+
s2 5
11+
2 3
12+
5 6
13+
1 2 3
14+
4 5 6
15+
s1 2 3
16+
s2 5 6
17+
1 2 3 s1
18+
4 5 6 s2
19+
42 42.42 [1,2,3] 2020-01-01
20+
\N \N \N 2020-01-02
21+
43 43.43 [4,5,6] \N
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
drop table if exists test1;
2+
drop table if exists test2;
3+
drop table if exists test_merge;
4+
5+
create table test1 (x UInt64, t Tuple(a UInt32, b UInt32), y String) engine=Memory;
6+
create table test2 (x UInt64, t Tuple(a UInt32, b UInt32), y String) engine=Memory;
7+
create table test_merge (x UInt64, t Tuple(a UInt32, b UInt32), y String) engine=Merge(currentDatabase(), 'test');
8+
9+
insert into test1 select 1, tuple(2, 3), 's1';
10+
insert into test2 select 4, tuple(5, 6), 's2';
11+
12+
set allow_suspicious_types_in_order_by=1;
13+
14+
select * from test_merge order by all;
15+
select t.a from test_merge order by all;
16+
select t.b from test_merge order by all;
17+
select x, t.a from test_merge order by all;
18+
select y, t.a from test_merge order by all;
19+
select t.a, t.b from test_merge order by all;
20+
select x, t.a, t.b from test_merge order by all;
21+
select y, t.a, t.b from test_merge order by all;
22+
select x, t.a, t.b, y from test_merge order by all;
23+
24+
drop table test_merge;
25+
drop table test1;
26+
drop table test2;
27+
28+
drop table if exists test;
29+
create table test (json JSON) engine=Memory;
30+
create table test_merge (json JSON) engine=Merge(currentDatabase(), 'test');
31+
insert into test values ('{"a" : {"b" : 42, "g" : 42.42}, "c" : [1, 2, 3], "d" : "2020-01-01"}'), ('{"f" : "Hello, World!", "d" : "2020-01-02"}'), ('{"a" : {"b" : 43, "e" : 10, "g" : 43.43}, "c" : [4, 5, 6]}');
32+
33+
select json.a.b, json.a.g, json.c, json.d from test_merge;
34+
drop table test_merge;
35+
drop table test;
36+

0 commit comments

Comments
 (0)