| 1172 | |
| 1173 | namespace { |
| 1174 | core::PartitionFunctionSpecPtr createPartitionFunctionSpec( |
| 1175 | const RowTypePtr& inputType, |
| 1176 | const std::vector<core::TypedExprPtr>& keys, |
| 1177 | memory::MemoryPool* pool) { |
| 1178 | if (keys.empty()) { |
| 1179 | return std::make_shared<core::GatherPartitionFunctionSpec>(); |
| 1180 | } else { |
| 1181 | std::vector<column_index_t> keyIndices; |
| 1182 | keyIndices.reserve(keys.size()); |
| 1183 | |
| 1184 | std::vector<VectorPtr> constValues; |
| 1185 | constValues.reserve(keys.size()); |
| 1186 | |
| 1187 | for (const auto& key : keys) { |
| 1188 | if (auto field = |
| 1189 | std::dynamic_pointer_cast<const core::FieldAccessTypedExpr>( |
| 1190 | key)) { |
| 1191 | keyIndices.push_back(inputType->getChildIdx(field->name())); |
| 1192 | } else if ( |
| 1193 | auto constant = |
| 1194 | std::dynamic_pointer_cast<const core::ConstantTypedExpr>(key)) { |
| 1195 | keyIndices.push_back(kConstantChannel); |
| 1196 | constValues.push_back(constant->toConstantVector(pool)); |
| 1197 | } else { |
| 1198 | BOLT_UNREACHABLE(); |
| 1199 | } |
| 1200 | } |
| 1201 | return std::make_shared<HashPartitionFunctionSpec>( |
| 1202 | inputType, std::move(keyIndices), std::move(constValues)); |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | RowTypePtr concat(const RowTypePtr& a, const RowTypePtr& b) { |
| 1207 | std::vector<std::string> names = a->names(); |
no test coverage detected