| 36 | |
| 37 | namespace { |
| 38 | std::tuple<std::vector<column_index_t>, std::vector<column_index_t>, RowTypePtr> |
| 39 | reorderInputChannels( |
| 40 | const RowTypePtr& inputType, |
| 41 | const std::vector<core::FieldAccessTypedExprPtr>& partitionKeys, |
| 42 | const std::vector<core::FieldAccessTypedExprPtr>& sortingKeys) { |
| 43 | const auto size = inputType->size(); |
| 44 | |
| 45 | std::vector<column_index_t> channels; |
| 46 | std::vector<column_index_t> inversedChannels; |
| 47 | std::vector<std::string> names; |
| 48 | std::vector<TypePtr> types; |
| 49 | channels.reserve(size); |
| 50 | inversedChannels.resize(size); |
| 51 | names.reserve(size); |
| 52 | types.reserve(size); |
| 53 | |
| 54 | std::unordered_set<std::string> keyNames; |
| 55 | |
| 56 | auto appendChannel = |
| 57 | [&inputType, &channels, &inversedChannels, &names, &types]( |
| 58 | column_index_t channel) { |
| 59 | channels.push_back(channel); |
| 60 | inversedChannels[channel] = channels.size() - 1; |
| 61 | names.push_back(inputType->nameOf(channel)); |
| 62 | types.push_back(inputType->childAt(channel)); |
| 63 | }; |
| 64 | |
| 65 | for (const auto& key : partitionKeys) { |
| 66 | auto channel = exprToChannel(key.get(), inputType); |
| 67 | appendChannel(channel); |
| 68 | keyNames.insert(key->name()); |
| 69 | } |
| 70 | |
| 71 | for (const auto& key : sortingKeys) { |
| 72 | auto channel = exprToChannel(key.get(), inputType); |
| 73 | appendChannel(channel); |
| 74 | keyNames.insert(key->name()); |
| 75 | } |
| 76 | |
| 77 | for (auto i = 0; i < size; ++i) { |
| 78 | if (keyNames.count(inputType->nameOf(i)) == 0) { |
| 79 | appendChannel(i); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return std::make_tuple( |
| 84 | channels, inversedChannels, ROW(std::move(names), std::move(types))); |
| 85 | } |
| 86 | |
| 87 | // Returns a [start, end) slice of the 'types' vector. |
| 88 | std::vector<TypePtr> |
no test coverage detected