| 101 | } |
| 102 | |
| 103 | void HashAggregation::initialize() { |
| 104 | Operator::initialize(); |
| 105 | |
| 106 | BOLT_CHECK(pool()->trackUsage()); |
| 107 | |
| 108 | auto inputType = aggregationNode_->sources()[0]->outputType(); |
| 109 | |
| 110 | auto hashers = |
| 111 | createVectorHashers(inputType, aggregationNode_->groupingKeys()); |
| 112 | auto numHashers = hashers.size(); |
| 113 | |
| 114 | std::vector<column_index_t> preGroupedChannels; |
| 115 | preGroupedChannels.reserve(aggregationNode_->preGroupedKeys().size()); |
| 116 | for (const auto& key : aggregationNode_->preGroupedKeys()) { |
| 117 | auto channel = exprToChannel(key.get(), inputType); |
| 118 | preGroupedChannels.push_back(channel); |
| 119 | } |
| 120 | |
| 121 | std::shared_ptr<core::ExpressionEvaluator> expressionEvaluator; |
| 122 | std::vector<AggregateInfo> aggregateInfos = toAggregateInfo( |
| 123 | *aggregationNode_, *operatorCtx_, numHashers, expressionEvaluator); |
| 124 | for (int i = 0; i < aggregateInfos.size(); i++) { |
| 125 | if (aggregationNode_->aggregates()[i].call->name().find("vid_split") != |
| 126 | std::string::npos) { |
| 127 | containsVidSplit_ = true; |
| 128 | adaptiveAdjustment_ = false; |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | bool canUseRowBasedSpill = true; |
| 134 | bool hasDistinctAgg = false; |
| 135 | size_t accumulatorSize = 0; |
| 136 | int alignment = 1; |
| 137 | // Check that aggregate result type match the output type. |
| 138 | for (auto i = 0; i < aggregateInfos.size(); i++) { |
| 139 | accumulatorSize += aggregateInfos[i].function->accumulatorFixedWidthSize(); |
| 140 | const auto& aggResultType = aggregateInfos[i].function->resultType(); |
| 141 | const auto& expectedType = outputType_->childAt(numHashers + i); |
| 142 | BOLT_CHECK( |
| 143 | aggResultType->kindEquals(expectedType), |
| 144 | "Unexpected result type for an aggregation: {}, expected {}, step {}", |
| 145 | aggResultType->toString(), |
| 146 | expectedType->toString(), |
| 147 | core::AggregationNode::stepName(aggregationNode_->step())); |
| 148 | // only can used row based spill for fix accumulate and no sorting keys |
| 149 | canUseRowBasedSpill &= |
| 150 | (aggregateInfos[i].function->isFixedSize() || |
| 151 | aggregateInfos[i].function->supportAccumulatorSerde()) && |
| 152 | aggregateInfos[i].sortingKeys.empty(); |
| 153 | alignment = RowContainer::combineAlignments( |
| 154 | aggregateInfos[i].function->accumulatorAlignmentSize(), alignment); |
| 155 | hasDistinctAgg |= aggregateInfos[i].distinct; |
| 156 | } |
| 157 | const auto& queryConf = operatorCtx_->driverCtx()->queryConfig(); |
| 158 | if (canUseRowBasedSpill && spillConfig_) { |
| 159 | auto rowbasedSpillMode = queryConf.rowBasedSpillMode(); |
| 160 | LOG(INFO) << "Operator " << name() |
nothing calls this directly
no test coverage detected