| 135 | } |
| 136 | |
| 137 | void MergeTreeDataMerger::prepareColumnNamesAndTypes( |
| 138 | const StorageSnapshotPtr & storage_snapshot, |
| 139 | const MergeTreeMetaBase::MergingParams & merging_params, |
| 140 | Names & all_column_names, |
| 141 | Names & gathering_column_names, |
| 142 | Names & merging_column_names, |
| 143 | NamesAndTypesList & storage_columns, |
| 144 | NamesAndTypesList & gathering_columns, |
| 145 | NamesAndTypesList & merging_columns) |
| 146 | { |
| 147 | auto metadata_snapshot = storage_snapshot->metadata; |
| 148 | all_column_names = metadata_snapshot->getColumns().getNamesOfPhysical(); |
| 149 | storage_columns = metadata_snapshot->getColumns().getAllPhysical(); |
| 150 | |
| 151 | extendObjectColumns(storage_columns, storage_snapshot->object_columns, false); |
| 152 | |
| 153 | Names sort_key_columns_vec = metadata_snapshot->getSortingKey().expression->getRequiredColumns(); |
| 154 | std::set<String> key_columns(sort_key_columns_vec.cbegin(), sort_key_columns_vec.cend()); |
| 155 | for (const auto & index : metadata_snapshot->getSecondaryIndices()) |
| 156 | { |
| 157 | Names index_columns_vec = index.expression->getRequiredColumns(); |
| 158 | std::copy(index_columns_vec.cbegin(), index_columns_vec.cend(), std::inserter(key_columns, key_columns.end())); |
| 159 | } |
| 160 | |
| 161 | for (const auto & projection : metadata_snapshot->getProjections()) |
| 162 | { |
| 163 | Names projection_columns_vec = projection.required_columns; |
| 164 | std::copy(projection_columns_vec.cbegin(), projection_columns_vec.cend(), std::inserter(key_columns, key_columns.end())); |
| 165 | } |
| 166 | |
| 167 | /// Force unique key columns and extra column for Unique mode, |
| 168 | /// otherwise MergedBlockOutputStream won't have the required columns to generate unique key index file. |
| 169 | if (metadata_snapshot->hasUniqueKey()) |
| 170 | { |
| 171 | auto unique_key_expr = metadata_snapshot->getUniqueKey().expression; |
| 172 | if (!unique_key_expr) |
| 173 | throw Exception("Missing unique key expression for Unique mode", ErrorCodes::LOGICAL_ERROR); |
| 174 | |
| 175 | Names index_columns_vec = unique_key_expr->getRequiredColumns(); |
| 176 | std::copy(index_columns_vec.cbegin(), index_columns_vec.cend(), std::inserter(key_columns, key_columns.end())); |
| 177 | |
| 178 | /// also need version column when building unique key index file |
| 179 | if (merging_params.hasExplicitVersionColumn()) |
| 180 | key_columns.insert(merging_params.version_column); |
| 181 | } |
| 182 | |
| 183 | /// Force sign column for Collapsing mode |
| 184 | if (merging_params.mode == MergeTreeMetaBase::MergingParams::Collapsing) |
| 185 | key_columns.emplace(merging_params.sign_column); |
| 186 | |
| 187 | /// Force version column for Replacing mode |
| 188 | if (merging_params.mode == MergeTreeMetaBase::MergingParams::Replacing) |
| 189 | key_columns.emplace(merging_params.version_column); |
| 190 | |
| 191 | /// Force sign column for VersionedCollapsing mode. Version is already in primary key. |
| 192 | if (merging_params.mode == MergeTreeMetaBase::MergingParams::VersionedCollapsing) |
| 193 | key_columns.emplace(merging_params.sign_column); |
| 194 |
nothing calls this directly
no test coverage detected