1#include "duckdb/parser/expression/lambda_expression.hpp"
2#include "duckdb/common/field_writer.hpp"
3#include "duckdb/common/types/hash.hpp"
4#include "duckdb/common/string_util.hpp"
5
6#include "duckdb/common/serializer/format_serializer.hpp"
7#include "duckdb/common/serializer/format_deserializer.hpp"
8
9namespace duckdb {
10
11LambdaExpression::LambdaExpression(unique_ptr<ParsedExpression> lhs, unique_ptr<ParsedExpression> expr)
12 : ParsedExpression(ExpressionType::LAMBDA, ExpressionClass::LAMBDA), lhs(std::move(lhs)), expr(std::move(expr)) {
13}
14
15string LambdaExpression::ToString() const {
16 return lhs->ToString() + " -> " + expr->ToString();
17}
18
19bool LambdaExpression::Equal(const LambdaExpression &a, const LambdaExpression &b) {
20 return a.lhs->Equals(other: *b.lhs) && a.expr->Equals(other: *b.expr);
21}
22
23hash_t LambdaExpression::Hash() const {
24 hash_t result = lhs->Hash();
25 ParsedExpression::Hash();
26 result = CombineHash(left: result, right: expr->Hash());
27 return result;
28}
29
30unique_ptr<ParsedExpression> LambdaExpression::Copy() const {
31 auto copy = make_uniq<LambdaExpression>(args: lhs->Copy(), args: expr->Copy());
32 copy->CopyProperties(other: *this);
33 return std::move(copy);
34}
35
36void LambdaExpression::Serialize(FieldWriter &writer) const {
37 writer.WriteSerializable(element: *lhs);
38 writer.WriteSerializable(element: *expr);
39}
40
41unique_ptr<ParsedExpression> LambdaExpression::Deserialize(ExpressionType type, FieldReader &reader) {
42 auto lhs = reader.ReadRequiredSerializable<ParsedExpression>();
43 auto expr = reader.ReadRequiredSerializable<ParsedExpression>();
44 return make_uniq<LambdaExpression>(args: std::move(lhs), args: std::move(expr));
45}
46
47void LambdaExpression::FormatSerialize(FormatSerializer &serializer) const {
48 ParsedExpression::FormatSerialize(serializer);
49 serializer.WriteProperty(tag: "lhs", value&: *lhs);
50 serializer.WriteProperty(tag: "expr", value&: *expr);
51}
52
53unique_ptr<ParsedExpression> LambdaExpression::FormatDeserialize(ExpressionType type,
54 FormatDeserializer &deserializer) {
55 auto lhs = deserializer.ReadProperty<unique_ptr<ParsedExpression>>(tag: "lhs");
56 auto expr = deserializer.ReadProperty<unique_ptr<ParsedExpression>>(tag: "expr");
57 return make_uniq<LambdaExpression>(args: std::move(lhs), args: std::move(expr));
58}
59
60} // namespace duckdb
61