| 29 | namespace processor { |
| 30 | |
| 31 | static std::vector<AggregateInfo> getAggregateInputInfos(const expression_vector& keys, |
| 32 | const expression_vector& aggregates, const Schema& schema) { |
| 33 | // Collect unFlat groups from |
| 34 | std::unordered_set<f_group_pos> groupByGroupPosSet; |
| 35 | for (auto& expression : keys) { |
| 36 | groupByGroupPosSet.insert(schema.getGroupPos(*expression)); |
| 37 | } |
| 38 | std::unordered_set<f_group_pos> unFlatAggregateGroupPosSet; |
| 39 | for (auto groupPos : schema.getGroupsPosInScope()) { |
| 40 | if (groupByGroupPosSet.contains(groupPos)) { |
| 41 | continue; |
| 42 | } |
| 43 | if (schema.getGroup(groupPos)->isFlat()) { |
| 44 | continue; |
| 45 | } |
| 46 | unFlatAggregateGroupPosSet.insert(groupPos); |
| 47 | } |
| 48 | std::vector<AggregateInfo> result; |
| 49 | for (auto& expression : aggregates) { |
| 50 | auto aggregateVectorPos = DataPos::getInvalidPos(); |
| 51 | if (expression->getNumChildren() != 0) { // COUNT(*) has no children |
| 52 | auto child = expression->getChild(0); |
| 53 | aggregateVectorPos = DataPos{schema.getExpressionPos(*child)}; |
| 54 | } |
| 55 | std::vector<data_chunk_pos_t> multiplicityChunksPos; |
| 56 | for (auto& groupPos : unFlatAggregateGroupPosSet) { |
| 57 | if (groupPos != aggregateVectorPos.dataChunkPos) { |
| 58 | multiplicityChunksPos.push_back(groupPos); |
| 59 | } |
| 60 | } |
| 61 | auto aggExpr = expression->constPtrCast<AggregateFunctionExpression>(); |
| 62 | auto distinctAggKeyType = aggExpr->isDistinct() ? |
| 63 | expression->getChild(0)->getDataType().copy() : |
| 64 | LogicalType::ANY(); |
| 65 | result.emplace_back(aggregateVectorPos, std::move(multiplicityChunksPos), |
| 66 | std::move(distinctAggKeyType)); |
| 67 | } |
| 68 | return result; |
| 69 | } |
| 70 | |
| 71 | static expression_vector getKeyExpressions(const expression_vector& expressions, |
| 72 | const Schema& schema, bool isFlat) { |
no test coverage detected