| 244 | } |
| 245 | |
| 246 | std::unique_ptr<PhysicalOperator> PlanMapper::mapAggregate(const LogicalOperator* logicalOperator) { |
| 247 | auto& agg = logicalOperator->constCast<LogicalAggregate>(); |
| 248 | if (auto packedFilteredCount = tryMapPackedFilteredCount(*this, clientContext, agg)) { |
| 249 | return packedFilteredCount; |
| 250 | } |
| 251 | auto aggregates = agg.getAggregates(); |
| 252 | auto outSchema = agg.getSchema(); |
| 253 | auto child = agg.getChild(0).get(); |
| 254 | auto inSchema = child->getSchema(); |
| 255 | auto prevOperator = mapOperator(child); |
| 256 | if (agg.hasKeys()) { |
| 257 | return createHashAggregate(agg.getKeys(), agg.getDependentKeys(), aggregates, inSchema, |
| 258 | outSchema, std::move(prevOperator)); |
| 259 | } |
| 260 | auto aggFunctions = getAggFunctions(aggregates); |
| 261 | auto aggOutputPos = getDataPos(aggregates, *outSchema); |
| 262 | auto aggregateInputInfos = getAggregateInputInfos(agg.getAllKeys(), aggregates, *inSchema); |
| 263 | auto sharedState = |
| 264 | make_shared<SimpleAggregateSharedState>(clientContext, aggFunctions, aggregateInputInfos); |
| 265 | auto printInfo = std::make_unique<SimpleAggregatePrintInfo>(aggregates); |
| 266 | auto aggregate = make_unique<SimpleAggregate>(sharedState, std::move(aggFunctions), |
| 267 | copyVector(aggregateInputInfos), std::move(prevOperator), getOperatorID(), |
| 268 | printInfo->copy()); |
| 269 | aggregate->setDescriptor(std::make_unique<ResultSetDescriptor>(inSchema)); |
| 270 | auto finalizer = std::make_unique<SimpleAggregateFinalize>(sharedState, |
| 271 | std::move(aggregateInputInfos), getOperatorID(), printInfo->copy()); |
| 272 | finalizer->addChild(std::move(aggregate)); |
| 273 | aggFunctions = getAggFunctions(aggregates); |
| 274 | auto scan = std::make_unique<SimpleAggregateScan>(sharedState, |
| 275 | AggregateScanInfo{std::move(aggOutputPos), getMoveAggResultToVectorFuncs(aggFunctions)}, |
| 276 | getOperatorID(), printInfo->copy()); |
| 277 | scan->addChild(std::move(finalizer)); |
| 278 | return scan; |
| 279 | } |
| 280 | |
| 281 | static FactorizedTableSchema getFactorizedTableSchema(const expression_vector& flatKeys, |
| 282 | const expression_vector& unFlatKeys, const expression_vector& payloads, |
nothing calls this directly
no test coverage detected