| 1 | #include "duckdb/planner/expression/bound_aggregate_expression.hpp" |
| 2 | #include "duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp" |
| 3 | #include "duckdb/common/types/hash.hpp" |
| 4 | #include "duckdb/common/string_util.hpp" |
| 5 | |
| 6 | using namespace duckdb; |
| 7 | using namespace std; |
| 8 | |
| 9 | BoundAggregateExpression::BoundAggregateExpression(TypeId return_type, AggregateFunction function, bool distinct) |
| 10 | : Expression(ExpressionType::BOUND_AGGREGATE, ExpressionClass::BOUND_AGGREGATE, return_type), function(function), |
| 11 | distinct(distinct) { |
| 12 | } |
| 13 | |
| 14 | string BoundAggregateExpression::ToString() const { |
| 15 | string result = function.name + "(" ; |
| 16 | if (distinct) { |
| 17 | result += "DISTINCT " ; |
| 18 | } |
| 19 | StringUtil::Join(children, children.size(), ", " , |
| 20 | [](const unique_ptr<Expression> &child) { return child->GetName(); }); |
| 21 | result += ")" ; |
| 22 | return result; |
| 23 | } |
| 24 | hash_t BoundAggregateExpression::Hash() const { |
| 25 | hash_t result = Expression::Hash(); |
| 26 | result = CombineHash(result, duckdb::Hash(function.name.c_str())); |
| 27 | result = CombineHash(result, duckdb::Hash(distinct)); |
| 28 | return result; |
| 29 | } |
| 30 | |
| 31 | bool BoundAggregateExpression::Equals(const BaseExpression *other_) const { |
| 32 | if (!BaseExpression::Equals(other_)) { |
| 33 | return false; |
| 34 | } |
| 35 | auto other = (BoundAggregateExpression *)other_; |
| 36 | if (other->distinct != distinct) { |
| 37 | return false; |
| 38 | } |
| 39 | if (other->function != function) { |
| 40 | return false; |
| 41 | } |
| 42 | if (children.size() != other->children.size()) { |
| 43 | return false; |
| 44 | } |
| 45 | for (idx_t i = 0; i < children.size(); i++) { |
| 46 | if (!Expression::Equals(children[i].get(), other->children[i].get())) { |
| 47 | return false; |
| 48 | } |
| 49 | } |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | unique_ptr<Expression> BoundAggregateExpression::Copy() { |
| 54 | auto copy = make_unique<BoundAggregateExpression>(return_type, function, distinct); |
| 55 | for (auto &child : children) { |
| 56 | copy->children.push_back(child->Copy()); |
| 57 | } |
| 58 | copy->CopyProperties(*this); |
| 59 | return move(copy); |
| 60 | } |
| 61 | |