| 126 | } |
| 127 | |
| 128 | void getBlockSortPermutationImpl(const Block & block, const SortDescription & description, IColumn::PermutationSortStability stability, UInt64 limit, IColumn::Permutation & permutation) |
| 129 | { |
| 130 | if (block.empty()) |
| 131 | return; |
| 132 | |
| 133 | ColumnsWithSortDescriptions columns_with_sort_descriptions = getColumnsWithSortDescription(block, description); |
| 134 | |
| 135 | bool all_const = true; |
| 136 | for (const auto & column : columns_with_sort_descriptions) |
| 137 | { |
| 138 | if (!column.column_const) |
| 139 | { |
| 140 | all_const = false; |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (unlikely(all_const)) |
| 146 | return; |
| 147 | |
| 148 | /// If only one column to sort by |
| 149 | if (columns_with_sort_descriptions.size() == 1) |
| 150 | { |
| 151 | auto & column_with_sort_description = columns_with_sort_descriptions[0]; |
| 152 | |
| 153 | IColumn::PermutationSortDirection direction = column_with_sort_description.description.direction == -1 ? IColumn::PermutationSortDirection::Descending : IColumn::PermutationSortDirection::Ascending; |
| 154 | int nan_direction_hint = column_with_sort_description.description.nulls_direction; |
| 155 | const auto & column = column_with_sort_description.column; |
| 156 | |
| 157 | if (isCollationRequired(column_with_sort_description.description)) |
| 158 | column->getPermutationWithCollation( |
| 159 | *column_with_sort_description.description.collator, direction, stability, limit, nan_direction_hint, permutation); |
| 160 | else |
| 161 | column->getPermutation(direction, stability, limit, nan_direction_hint, permutation); |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | size_t size = block.rows(); |
| 166 | permutation.resize(size); |
| 167 | iota(permutation.data(), size, IColumn::Permutation::value_type(0)); |
| 168 | |
| 169 | if (limit >= size) |
| 170 | limit = 0; |
| 171 | |
| 172 | EqualRanges ranges; |
| 173 | ranges.emplace_back(0, permutation.size()); |
| 174 | |
| 175 | for (const auto & column_with_sort_description : columns_with_sort_descriptions) |
| 176 | { |
| 177 | while (!ranges.empty() && limit && limit <= ranges.back().from) |
| 178 | ranges.pop_back(); |
| 179 | |
| 180 | if (ranges.empty()) |
| 181 | break; |
| 182 | |
| 183 | if (column_with_sort_description.column_const) |
| 184 | continue; |
| 185 |
no test coverage detected