1 | #include "duckdb/planner/expression/bound_function_expression.hpp" |
2 | |
3 | #include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp" |
4 | #include "duckdb/common/types/hash.hpp" |
5 | #include "duckdb/common/string_util.hpp" |
6 | |
7 | using namespace duckdb; |
8 | using namespace std; |
9 | |
10 | BoundFunctionExpression::BoundFunctionExpression(TypeId return_type, ScalarFunction bound_function, bool is_operator) |
11 | : Expression(ExpressionType::BOUND_FUNCTION, ExpressionClass::BOUND_FUNCTION, return_type), |
12 | function(bound_function), is_operator(is_operator) { |
13 | } |
14 | |
15 | bool BoundFunctionExpression::IsFoldable() const { |
16 | // functions with side effects cannot be folded: they have to be executed once for every row |
17 | return function.has_side_effects ? false : Expression::IsFoldable(); |
18 | } |
19 | |
20 | string BoundFunctionExpression::ToString() const { |
21 | string result = function.name + "(" ; |
22 | result += StringUtil::Join(children, children.size(), ", " , |
23 | [](const unique_ptr<Expression> &child) { return child->GetName(); }); |
24 | result += ")" ; |
25 | return result; |
26 | } |
27 | |
28 | hash_t BoundFunctionExpression::Hash() const { |
29 | hash_t result = Expression::Hash(); |
30 | return CombineHash(result, duckdb::Hash(function.name.c_str())); |
31 | } |
32 | |
33 | bool BoundFunctionExpression::Equals(const BaseExpression *other_) const { |
34 | if (!BaseExpression::Equals(other_)) { |
35 | return false; |
36 | } |
37 | auto other = (BoundFunctionExpression *)other_; |
38 | if (other->function != function) { |
39 | return false; |
40 | } |
41 | if (children.size() != other->children.size()) { |
42 | return false; |
43 | } |
44 | for (idx_t i = 0; i < children.size(); i++) { |
45 | if (!Expression::Equals(children[i].get(), other->children[i].get())) { |
46 | return false; |
47 | } |
48 | } |
49 | return true; |
50 | } |
51 | |
52 | unique_ptr<Expression> BoundFunctionExpression::Copy() { |
53 | auto copy = make_unique<BoundFunctionExpression>(return_type, function, is_operator); |
54 | for (auto &child : children) { |
55 | copy->children.push_back(child->Copy()); |
56 | } |
57 | copy->bind_info = bind_info ? bind_info->Copy() : nullptr; |
58 | copy->CopyProperties(*this); |
59 | copy->arguments = arguments; |
60 | copy->sql_return_type = sql_return_type; |
61 | return move(copy); |
62 | } |
63 | |