1#include "duckdb/planner/expression/bound_operator_expression.hpp"
2#include "duckdb/common/string_util.hpp"
3
4using namespace duckdb;
5using namespace std;
6
7BoundOperatorExpression::BoundOperatorExpression(ExpressionType type, TypeId return_type)
8 : Expression(type, ExpressionClass::BOUND_OPERATOR, return_type) {
9}
10
11string BoundOperatorExpression::ToString() const {
12 auto op = ExpressionTypeToOperator(type);
13 if (!op.empty()) {
14 // use the operator string to represent the operator
15 if (children.size() == 1) {
16 return op + "(" + children[0]->GetName() + ")";
17 } else if (children.size() == 2) {
18 return children[0]->GetName() + " " + op + " " + children[1]->GetName();
19 }
20 }
21 // if there is no operator we render it as a function
22 auto result = ExpressionTypeToString(type) + "(";
23 result += StringUtil::Join(children, children.size(), ", ",
24 [](const unique_ptr<Expression> &child) { return child->GetName(); });
25 result += ")";
26 return result;
27}
28
29bool BoundOperatorExpression::Equals(const BaseExpression *other_) const {
30 if (!BaseExpression::Equals(other_)) {
31 return false;
32 }
33 auto other = (BoundOperatorExpression *)other_;
34 if (children.size() != other->children.size()) {
35 return false;
36 }
37 for (idx_t i = 0; i < children.size(); i++) {
38 if (!Expression::Equals(children[i].get(), other->children[i].get())) {
39 return false;
40 }
41 }
42 return true;
43}
44
45unique_ptr<Expression> BoundOperatorExpression::Copy() {
46 auto copy = make_unique<BoundOperatorExpression>(type, return_type);
47 copy->CopyProperties(*this);
48 for (auto &child : children) {
49 copy->children.push_back(child->Copy());
50 }
51 return move(copy);
52}
53