| 1 | #include "duckdb/planner/operator/logical_aggregate.hpp" |
| 2 | #include "duckdb/common/string_util.hpp" |
| 3 | |
| 4 | using namespace duckdb; |
| 5 | using namespace std; |
| 6 | |
| 7 | LogicalAggregate::LogicalAggregate(idx_t group_index, idx_t aggregate_index, vector<unique_ptr<Expression>> select_list) |
| 8 | : LogicalOperator(LogicalOperatorType::AGGREGATE_AND_GROUP_BY, move(select_list)), group_index(group_index), |
| 9 | aggregate_index(aggregate_index) { |
| 10 | } |
| 11 | |
| 12 | void LogicalAggregate::ResolveTypes() { |
| 13 | for (auto &expr : groups) { |
| 14 | types.push_back(expr->return_type); |
| 15 | } |
| 16 | // get the chunk types from the projection list |
| 17 | for (auto &expr : expressions) { |
| 18 | types.push_back(expr->return_type); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | vector<ColumnBinding> LogicalAggregate::GetColumnBindings() { |
| 23 | vector<ColumnBinding> result; |
| 24 | for (idx_t i = 0; i < groups.size(); i++) { |
| 25 | result.push_back(ColumnBinding(group_index, i)); |
| 26 | } |
| 27 | for (idx_t i = 0; i < expressions.size(); i++) { |
| 28 | result.push_back(ColumnBinding(aggregate_index, i)); |
| 29 | } |
| 30 | return result; |
| 31 | } |
| 32 | |
| 33 | string LogicalAggregate::ParamsToString() const { |
| 34 | string result = LogicalOperator::ParamsToString(); |
| 35 | if (groups.size() > 0) { |
| 36 | result += "[" ; |
| 37 | result += StringUtil::Join(groups, groups.size(), ", " , |
| 38 | [](const unique_ptr<Expression> &child) { return child->GetName(); }); |
| 39 | result += "]" ; |
| 40 | } |
| 41 | |
| 42 | return result; |
| 43 | } |
| 44 | |