MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / createHashAggregate

Method createHashAggregate

src/processor/map/map_aggregate.cpp:316–365  ·  view source on GitHub ↗

Payloads are also group by keys except that they are functional dependent on keys so we don't need to hash or compare payloads.

Source from the content-addressed store, hash-verified

314// Payloads are also group by keys except that they are functional dependent on keys so we don't
315// need to hash or compare payloads.
316std::unique_ptr<PhysicalOperator> PlanMapper::createHashAggregate(const expression_vector& keys,
317 const expression_vector& payloads, const expression_vector& aggregates, Schema* inSchema,
318 Schema* outSchema, std::unique_ptr<PhysicalOperator> prevOperator) {
319 // Create hash aggregate
320 auto aggFunctions = getAggFunctions(aggregates);
321 expression_vector allKeys;
322 allKeys.insert(allKeys.end(), keys.begin(), keys.end());
323 allKeys.insert(allKeys.end(), payloads.begin(), payloads.end());
324 auto aggregateInputInfos = getAggregateInputInfos(allKeys, aggregates, *inSchema);
325 auto flatKeys = getKeyExpressions(keys, *inSchema, true /* isFlat */);
326 auto unFlatKeys = getKeyExpressions(keys, *inSchema, false /* isFlat */);
327 std::vector<LogicalType> keyTypes, payloadTypes;
328 for (auto& key : flatKeys) {
329 keyTypes.push_back(key->getDataType().copy());
330 }
331 for (auto& key : unFlatKeys) {
332 keyTypes.push_back(key->getDataType().copy());
333 }
334 for (auto& payload : payloads) {
335 payloadTypes.push_back(payload->getDataType().copy());
336 }
337 auto tableSchema = getFactorizedTableSchema(flatKeys, unFlatKeys, payloads, aggFunctions);
338 HashAggregateInfo aggregateInfo{getDataPos(flatKeys, *inSchema),
339 getDataPos(unFlatKeys, *inSchema), getDataPos(payloads, *inSchema), std::move(tableSchema)};
340
341 auto sharedState =
342 std::make_shared<HashAggregateSharedState>(clientContext, std::move(aggregateInfo),
343 aggFunctions, aggregateInputInfos, std::move(keyTypes), std::move(payloadTypes));
344 auto printInfo = std::make_unique<HashAggregatePrintInfo>(allKeys, aggregates);
345 auto aggregate = make_unique<HashAggregate>(sharedState, std::move(aggFunctions),
346 std::move(aggregateInputInfos), std::move(prevOperator), getOperatorID(),
347 printInfo->copy());
348 aggregate->setDescriptor(std::make_unique<ResultSetDescriptor>(inSchema));
349 // Create AggScan.
350 expression_vector outputExpressions;
351 outputExpressions.insert(outputExpressions.end(), flatKeys.begin(), flatKeys.end());
352 outputExpressions.insert(outputExpressions.end(), unFlatKeys.begin(), unFlatKeys.end());
353 outputExpressions.insert(outputExpressions.end(), payloads.begin(), payloads.end());
354 auto aggOutputPos = getDataPos(aggregates, *outSchema);
355 auto finalizer =
356 std::make_unique<HashAggregateFinalize>(sharedState, getOperatorID(), printInfo->copy());
357 finalizer->addChild(std::move(aggregate));
358 aggFunctions = getAggFunctions(aggregates);
359 auto scan =
360 std::make_unique<HashAggregateScan>(sharedState, getDataPos(outputExpressions, *outSchema),
361 AggregateScanInfo{std::move(aggOutputPos), getMoveAggResultToVectorFuncs(aggFunctions)},
362 getOperatorID(), printInfo->copy());
363 scan->addChild(std::move(finalizer));
364 return scan;
365}
366
367} // namespace processor
368} // namespace lbug

Callers

nothing calls this directly

Calls 13

getAggFunctionsFunction · 0.85
getAggregateInputInfosFunction · 0.85
getKeyExpressionsFunction · 0.85
getOperatorIDFunction · 0.85
getDataTypeMethod · 0.80
getFactorizedTableSchemaFunction · 0.70
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected