@@ -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+
122127void MergeTreeReaderCompact::readData (
123128 const NameAndTypePair & name_and_type,
124129 ColumnPtr & column,
0 commit comments