1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/parser/parsed_expression.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/parser/base_expression.hpp" |
12 | #include "duckdb/common/vector.hpp" |
13 | #include "duckdb/common/string_util.hpp" |
14 | #include "duckdb/parser/qualified_name.hpp" |
15 | #include "duckdb/parser/expression_util.hpp" |
16 | |
17 | namespace duckdb { |
18 | class Serializer; |
19 | class Deserializer; |
20 | class FieldWriter; |
21 | class FieldReader; |
22 | class FormatDeserializer; |
23 | class FormatSerializer; |
24 | |
25 | //! The ParsedExpression class is a base class that can represent any expression |
26 | //! part of a SQL statement. |
27 | /*! |
28 | The ParsedExpression class is a base class that can represent any expression |
29 | part of a SQL statement. This is, for example, a column reference in a SELECT |
30 | clause, but also operators, aggregates or filters. The Expression is emitted by the parser and does not contain any |
31 | information about bindings to the catalog or to the types. ParsedExpressions are transformed into regular Expressions |
32 | in the Binder. |
33 | */ |
34 | class ParsedExpression : public BaseExpression { |
35 | public: |
36 | //! Create an Expression |
37 | ParsedExpression(ExpressionType type, ExpressionClass expression_class) : BaseExpression(type, expression_class) { |
38 | } |
39 | |
40 | //! The location in the query (if any) |
41 | idx_t query_location = DConstants::INVALID_INDEX; |
42 | |
43 | public: |
44 | bool IsAggregate() const override; |
45 | bool IsWindow() const override; |
46 | bool HasSubquery() const override; |
47 | bool IsScalar() const override; |
48 | bool HasParameter() const override; |
49 | |
50 | bool Equals(const BaseExpression &other) const override; |
51 | hash_t Hash() const override; |
52 | |
53 | //! Create a copy of this expression |
54 | virtual unique_ptr<ParsedExpression> Copy() const = 0; |
55 | |
56 | //! Serializes an Expression to a stand-alone binary blob |
57 | void Serialize(Serializer &serializer) const; |
58 | //! Serializes an Expression to a stand-alone binary blob |
59 | virtual void Serialize(FieldWriter &writer) const = 0; |
60 | |
61 | //! Deserializes a blob back into an Expression [CAN THROW: |
62 | //! SerializationException] |
63 | static unique_ptr<ParsedExpression> Deserialize(Deserializer &source); |
64 | |
65 | virtual void FormatSerialize(FormatSerializer &serializer) const; |
66 | static unique_ptr<ParsedExpression> FormatDeserialize(FormatDeserializer &deserializer); |
67 | |
68 | static bool Equals(const unique_ptr<ParsedExpression> &left, const unique_ptr<ParsedExpression> &right); |
69 | static bool ListEquals(const vector<unique_ptr<ParsedExpression>> &left, |
70 | const vector<unique_ptr<ParsedExpression>> &right); |
71 | |
72 | protected: |
73 | //! Copy base Expression properties from another expression to this one, |
74 | //! used in Copy method |
75 | void CopyProperties(const ParsedExpression &other) { |
76 | type = other.type; |
77 | expression_class = other.expression_class; |
78 | alias = other.alias; |
79 | } |
80 | }; |
81 | |
82 | } // namespace duckdb |
83 |