1#include "duckdb/parser/expression/subquery_expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4#include "duckdb/common/serializer.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9SubqueryExpression::SubqueryExpression()
10 : ParsedExpression(ExpressionType::SUBQUERY, ExpressionClass::SUBQUERY), subquery_type(SubqueryType::INVALID),
11 comparison_type(ExpressionType::INVALID) {
12}
13
14string SubqueryExpression::ToString() const {
15 return "SUBQUERY";
16}
17
18bool SubqueryExpression::Equals(const SubqueryExpression *a, const SubqueryExpression *b) {
19 if (!a->subquery || !b->subquery) {
20 return false;
21 }
22 return a->subquery_type == b->subquery_type && a->subquery->Equals(b->subquery.get());
23}
24
25unique_ptr<ParsedExpression> SubqueryExpression::Copy() const {
26 auto copy = make_unique<SubqueryExpression>();
27 copy->CopyProperties(*this);
28 copy->subquery = subquery->Copy();
29 copy->subquery_type = subquery_type;
30 copy->child = child ? child->Copy() : nullptr;
31 copy->comparison_type = comparison_type;
32 return move(copy);
33}
34
35void SubqueryExpression::Serialize(Serializer &serializer) {
36 ParsedExpression::Serialize(serializer);
37 serializer.Write<SubqueryType>(subquery_type);
38 subquery->Serialize(serializer);
39 serializer.WriteOptional(child);
40 serializer.Write<ExpressionType>(comparison_type);
41}
42
43unique_ptr<ParsedExpression> SubqueryExpression::Deserialize(ExpressionType type, Deserializer &source) {
44 auto subquery_type = source.Read<SubqueryType>();
45 auto subquery = QueryNode::Deserialize(source);
46
47 auto expression = make_unique<SubqueryExpression>();
48 expression->subquery_type = subquery_type;
49 expression->subquery = move(subquery);
50 expression->child = source.ReadOptional<ParsedExpression>();
51 expression->comparison_type = source.Read<ExpressionType>();
52 return move(expression);
53}
54