1#include "duckdb/planner/expression/common_subexpression.hpp"
2
3#include "duckdb/common/exception.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8CommonSubExpression::CommonSubExpression(unique_ptr<Expression> child, string alias)
9 : Expression(ExpressionType::COMMON_SUBEXPRESSION, ExpressionClass::COMMON_SUBEXPRESSION, child->return_type) {
10 this->child = child.get();
11 this->owned_child = move(child);
12 this->alias = alias;
13 assert(this->child);
14}
15
16CommonSubExpression::CommonSubExpression(Expression *child, string alias)
17 : Expression(ExpressionType::COMMON_SUBEXPRESSION, ExpressionClass::COMMON_SUBEXPRESSION, child->return_type),
18 child(child) {
19 this->alias = alias;
20 assert(child);
21}
22
23string CommonSubExpression::ToString() const {
24 return child->ToString();
25}
26
27bool CommonSubExpression::Equals(const BaseExpression *other_) const {
28 if (!BaseExpression::Equals(other_)) {
29 return false;
30 }
31 auto other = (CommonSubExpression *)other_;
32 return other->child == child;
33}
34
35unique_ptr<Expression> CommonSubExpression::Copy() {
36 throw SerializationException("CSEs cannot be copied");
37}
38