| 970 | } |
| 971 | |
| 972 | Pipe ReadFromMergeTree::readByLayers( |
| 973 | const RangesInDataParts & parts_with_ranges, |
| 974 | SplitPartsByRanges split_parts, |
| 975 | const MergeTreeIndexBuildContextPtr & index_build_context, |
| 976 | const Names & column_names, |
| 977 | const InputOrderInfoPtr & input_order_info) |
| 978 | { |
| 979 | const auto & settings = context->getSettingsRef(); |
| 980 | |
| 981 | LOG_TRACE(log, "Spreading mark ranges among streams (reading by layers)"); |
| 982 | |
| 983 | PartRangesReadInfo info(parts_with_ranges, settings, *data_settings); |
| 984 | if (0 == info.sum_marks) |
| 985 | return {}; |
| 986 | |
| 987 | ReadingInOrderStepGetter reading_step_getter; |
| 988 | Names in_order_column_names_to_read; |
| 989 | SortDescription sort_description; |
| 990 | |
| 991 | if (reader_settings.read_in_order) |
| 992 | { |
| 993 | NameSet column_names_set(column_names.begin(), column_names.end()); |
| 994 | in_order_column_names_to_read = column_names; |
| 995 | |
| 996 | /// Add columns needed to calculate the sorting expression |
| 997 | for (const auto & column_name : storage_snapshot->metadata->getColumnsRequiredForSortingKey()) |
| 998 | { |
| 999 | if (column_names_set.contains(column_name)) |
| 1000 | continue; |
| 1001 | |
| 1002 | in_order_column_names_to_read.push_back(column_name); |
| 1003 | column_names_set.insert(column_name); |
| 1004 | } |
| 1005 | auto sorting_expr = storage_snapshot->metadata->getSortingKey().expression; |
| 1006 | const auto & sorting_columns = storage_snapshot->metadata->getSortingKey().column_names; |
| 1007 | std::vector<bool> reverse_flags = storage_snapshot->metadata->getSortingKeyReverseFlags(); |
| 1008 | |
| 1009 | sort_description.compile_sort_description = settings[Setting::compile_sort_description]; |
| 1010 | sort_description.min_count_to_compile_sort_description = settings[Setting::min_count_to_compile_sort_description]; |
| 1011 | |
| 1012 | sort_description.reserve(input_order_info->used_prefix_of_sorting_key_size); |
| 1013 | for (size_t i = 0; i < input_order_info->used_prefix_of_sorting_key_size; ++i) |
| 1014 | { |
| 1015 | if (!reverse_flags.empty() && reverse_flags[i]) |
| 1016 | sort_description.emplace_back(sorting_columns[i], input_order_info->direction * -1); |
| 1017 | else |
| 1018 | sort_description.emplace_back(sorting_columns[i], input_order_info->direction); |
| 1019 | } |
| 1020 | |
| 1021 | ReadType in_order_read_type = input_order_info->direction > 0 ? ReadType::InOrder : ReadType::InReverseOrder; |
| 1022 | |
| 1023 | reading_step_getter |
| 1024 | = [this, &index_build_context, &in_order_column_names_to_read, &info, sorting_expr, &sort_description, in_order_read_type](auto parts) |
| 1025 | { |
| 1026 | auto pipe = this->read( |
| 1027 | std::move(parts), |
| 1028 | index_build_context, |
| 1029 | in_order_column_names_to_read, |
nothing calls this directly
no test coverage detected