1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/planner/expression.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/parser/base_expression.hpp"
12#include "duckdb/common/types.hpp"
13#include "duckdb/planner/plan_serialization.hpp"
14
15namespace duckdb {
16class BaseStatistics;
17class FieldWriter;
18class FieldReader;
19class ClientContext;
20
21//! The Expression class represents a bound Expression with a return type
22class Expression : public BaseExpression {
23public:
24 Expression(ExpressionType type, ExpressionClass expression_class, LogicalType return_type);
25 ~Expression() override;
26
27 //! The return type of the expression
28 LogicalType return_type;
29 //! Expression statistics (if any) - ONLY USED FOR VERIFICATION
30 unique_ptr<BaseStatistics> verification_stats;
31
32public:
33 bool IsAggregate() const override;
34 bool IsWindow() const override;
35 bool HasSubquery() const override;
36 bool IsScalar() const override;
37 bool HasParameter() const override;
38 virtual bool HasSideEffects() const;
39 virtual bool PropagatesNullValues() const;
40 virtual bool IsFoldable() const;
41
42 hash_t Hash() const override;
43
44 bool Equals(const BaseExpression &other) const override {
45 if (!BaseExpression::Equals(other)) {
46 return false;
47 }
48 return return_type == ((Expression &)other).return_type;
49 }
50 static bool Equals(const Expression &left, const Expression &right) {
51 return left.Equals(other: right);
52 }
53 static bool Equals(const unique_ptr<Expression> &left, const unique_ptr<Expression> &right);
54 static bool ListEquals(const vector<unique_ptr<Expression>> &left, const vector<unique_ptr<Expression>> &right);
55 //! Create a copy of this expression
56 virtual unique_ptr<Expression> Copy() = 0;
57
58 //! Serializes an Expression to a stand-alone binary blob
59 void Serialize(Serializer &serializer) const;
60 //! Serializes an Expression to a stand-alone binary blob
61 virtual void Serialize(FieldWriter &writer) const = 0;
62
63 //! Deserializes a blob back into an Expression [CAN THROW:
64 //! SerializationException]
65 static unique_ptr<Expression> Deserialize(Deserializer &source, PlanDeserializationState &state);
66
67protected:
68 //! Copy base Expression properties from another expression to this one,
69 //! used in Copy method
70 void CopyProperties(Expression &other) {
71 type = other.type;
72 expression_class = other.expression_class;
73 alias = other.alias;
74 return_type = other.return_type;
75 }
76};
77
78} // namespace duckdb
79