1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/parser/expression/lambda_expression.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/parser/parsed_expression.hpp" |
12 | #include "duckdb/common/vector.hpp" |
13 | |
14 | namespace duckdb { |
15 | |
16 | //! LambdaExpression represents either: |
17 | //! 1. A lambda operator that can be used for e.g. mapping an expression to a list |
18 | //! 2. An OperatorExpression with the "->" operator |
19 | //! Lambda expressions are written in the form of "params -> expr", e.g. "x -> x + 1" |
20 | class LambdaExpression : public ParsedExpression { |
21 | public: |
22 | static constexpr const ExpressionClass TYPE = ExpressionClass::LAMBDA; |
23 | |
24 | public: |
25 | LambdaExpression(unique_ptr<ParsedExpression> lhs, unique_ptr<ParsedExpression> expr); |
26 | |
27 | // we need the context to determine if this is a list of column references or an expression (for JSON) |
28 | unique_ptr<ParsedExpression> lhs; |
29 | |
30 | vector<unique_ptr<ParsedExpression>> params; |
31 | unique_ptr<ParsedExpression> expr; |
32 | |
33 | public: |
34 | string ToString() const override; |
35 | |
36 | static bool Equal(const LambdaExpression &a, const LambdaExpression &b); |
37 | hash_t Hash() const override; |
38 | |
39 | unique_ptr<ParsedExpression> Copy() const override; |
40 | |
41 | void Serialize(FieldWriter &writer) const override; |
42 | static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source); |
43 | void FormatSerialize(FormatSerializer &serializer) const override; |
44 | static unique_ptr<ParsedExpression> FormatDeserialize(ExpressionType type, FormatDeserializer &deserializer); |
45 | }; |
46 | |
47 | } // namespace duckdb |
48 |