Skip to content

Commit 13b27a8

Browse files
committed
refactoring of reading from compact parts
1 parent efe5373 commit 13b27a8

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/Storages/MergeTree/MergeTreeReaderCompact.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,7 @@ void MergeTreeReaderCompact::fillColumnPositions()
7878
/// we have to read its offsets if they exist.
7979
if (!position && is_array)
8080
{
81-
NameAndTypePair column_to_read_with_subcolumns = column_to_read;
82-
auto [name_in_storage, subcolumn_name] = Nested::splitName(column_to_read.name);
83-
84-
/// If it is a part of Nested, we need to get the column from
85-
/// storage metadata which is converted to Nested type with subcolumns.
86-
/// It is required for proper counting of shared streams.
87-
if (!subcolumn_name.empty())
88-
{
89-
/// If column is renamed get the new name from storage metadata.
90-
if (alter_conversions->columnHasNewName(name_in_storage))
91-
name_in_storage = alter_conversions->getColumnNewName(name_in_storage);
92-
93-
if (!storage_columns_with_collected_nested)
94-
{
95-
auto options = GetColumnsOptions(GetColumnsOptions::AllPhysical).withExtendedObjects();
96-
auto storage_columns_list = Nested::collect(storage_snapshot->getColumns(options));
97-
storage_columns_with_collected_nested = ColumnsDescription(std::move(storage_columns_list));
98-
}
99-
100-
column_to_read_with_subcolumns = storage_columns_with_collected_nested
101-
->getColumnOrSubcolumn(
102-
GetColumnsOptions::All,
103-
Nested::concatenateName(name_in_storage, subcolumn_name));
104-
}
105-
81+
auto column_to_read_with_subcolumns = getColumnConvertedToSubcolumnOfNested(column_to_read);
10682
auto name_level_for_offsets = findColumnForOffsets(column_to_read_with_subcolumns);
10783

10884
if (name_level_for_offsets.has_value())
@@ -119,6 +95,35 @@ void MergeTreeReaderCompact::fillColumnPositions()
11995
}
12096
}
12197

98+
NameAndTypePair MergeTreeReaderCompact::getColumnConvertedToSubcolumnOfNested(const NameAndTypePair & column)
99+
{
100+
if (!isArray(column.type))
101+
return column;
102+
103+
/// If it is a part of Nested, we need to get the column from
104+
/// storage metadata which is converted to Nested type with subcolumns.
105+
/// It is required for proper counting of shared streams.
106+
auto [name_in_storage, subcolumn_name] = Nested::splitName(column.name);
107+
108+
if (subcolumn_name.empty())
109+
return column;
110+
111+
/// If column is renamed get the new name from storage metadata.
112+
if (alter_conversions->columnHasNewName(name_in_storage))
113+
name_in_storage = alter_conversions->getColumnNewName(name_in_storage);
114+
115+
if (!storage_columns_with_collected_nested)
116+
{
117+
auto options = GetColumnsOptions(GetColumnsOptions::AllPhysical).withExtendedObjects();
118+
auto storage_columns_list = Nested::collect(storage_snapshot->getColumns(options));
119+
storage_columns_with_collected_nested = ColumnsDescription(std::move(storage_columns_list));
120+
}
121+
122+
return storage_columns_with_collected_nested->getColumnOrSubcolumn(
123+
GetColumnsOptions::All,
124+
Nested::concatenateName(name_in_storage, subcolumn_name));
125+
}
126+
122127
void MergeTreeReaderCompact::readData(
123128
const NameAndTypePair & name_and_type,
124129
ColumnPtr & column,

src/Storages/MergeTree/MergeTreeReaderCompact.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ class MergeTreeReaderCompact : public IMergeTreeReader
3131
const ReadBufferFromFileBase::ProfileCallback & profile_callback_,
3232
clockid_t clock_type_);
3333

34-
bool canReadIncompleteGranules() const override final { return false; }
34+
bool canReadIncompleteGranules() const final { return false; }
3535

3636
protected:
3737
void fillColumnPositions();
38+
NameAndTypePair getColumnConvertedToSubcolumnOfNested(const NameAndTypePair & column);
3839

3940
using InputStreamGetter = ISerialization::InputStreamGetter;
4041

0 commit comments

Comments
 (0)