| 10 | namespace processor { |
| 11 | |
| 12 | std::unique_ptr<PhysicalOperator> PlanMapper::mapUnionAll(const LogicalOperator* logicalOperator) { |
| 13 | auto& logicalUnionAll = logicalOperator->constCast<LogicalUnion>(); |
| 14 | auto outSchema = logicalUnionAll.getSchema(); |
| 15 | // append result collectors to each child |
| 16 | std::vector<std::unique_ptr<PhysicalOperator>> prevOperators; |
| 17 | std::vector<std::shared_ptr<FactorizedTable>> tables; |
| 18 | for (auto i = 0u; i < logicalOperator->getNumChildren(); ++i) { |
| 19 | auto child = logicalOperator->getChild(i); |
| 20 | auto childSchema = logicalUnionAll.getSchemaBeforeUnion(i); |
| 21 | auto prevOperator = mapOperator(child.get()); |
| 22 | // Use the child's non-deduplicated projection list so the factorized table has |
| 23 | // the correct number of columns (matching expressionsToUnion.size()), even when |
| 24 | // the child projects the same expression more than once (e.g. RETURN b.age, b.age). |
| 25 | auto resultCollector = createResultCollector(AccumulateType::REGULAR, |
| 26 | logicalUnionAll.getChildProjections()[i], childSchema, std::move(prevOperator)); |
| 27 | tables.push_back(resultCollector->getResultFTable()); |
| 28 | prevOperators.push_back(std::move(resultCollector)); |
| 29 | } |
| 30 | // append union all |
| 31 | std::vector<DataPos> outputPositions; |
| 32 | std::vector<uint32_t> columnIndices; |
| 33 | auto expressionsToUnion = logicalUnionAll.getExpressionsToUnion(); |
| 34 | for (auto i = 0u; i < expressionsToUnion.size(); ++i) { |
| 35 | auto expression = expressionsToUnion[i]; |
| 36 | outputPositions.emplace_back(outSchema->getExpressionPos(*expression)); |
| 37 | columnIndices.push_back(i); |
| 38 | } |
| 39 | auto info = UnionAllScanInfo(std::move(outputPositions), std::move(columnIndices)); |
| 40 | auto maxMorselSize = tables[0]->hasUnflatCol() ? 1 : DEFAULT_VECTOR_CAPACITY; |
| 41 | auto unionSharedState = make_shared<UnionAllScanSharedState>(std::move(tables), maxMorselSize); |
| 42 | auto printInfo = std::make_unique<UnionAllScanPrintInfo>(expressionsToUnion); |
| 43 | auto scan = make_unique<UnionAllScan>(std::move(info), unionSharedState, getOperatorID(), |
| 44 | std::move(printInfo)); |
| 45 | for (auto& child : prevOperators) { |
| 46 | scan->addChild(std::move(child)); |
| 47 | } |
| 48 | return scan; |
| 49 | } |
| 50 | |
| 51 | } // namespace processor |
| 52 | } // namespace lbug |
nothing calls this directly
no test coverage detected