| 1 | #include "duckdb/planner/expression/bound_lambdaref_expression.hpp" |
| 2 | |
| 3 | #include "duckdb/common/types/hash.hpp" |
| 4 | #include "duckdb/common/to_string.hpp" |
| 5 | #include "duckdb/common/field_writer.hpp" |
| 6 | |
| 7 | namespace duckdb { |
| 8 | |
| 9 | BoundLambdaRefExpression::BoundLambdaRefExpression(string alias_p, LogicalType type, ColumnBinding binding, |
| 10 | idx_t lambda_index, idx_t depth) |
| 11 | : Expression(ExpressionType::BOUND_LAMBDA_REF, ExpressionClass::BOUND_LAMBDA_REF, std::move(type)), |
| 12 | binding(binding), lambda_index(lambda_index), depth(depth) { |
| 13 | this->alias = std::move(alias_p); |
| 14 | } |
| 15 | |
| 16 | BoundLambdaRefExpression::BoundLambdaRefExpression(LogicalType type, ColumnBinding binding, idx_t lambda_index, |
| 17 | idx_t depth) |
| 18 | : BoundLambdaRefExpression(string(), std::move(type), binding, lambda_index, depth) { |
| 19 | } |
| 20 | |
| 21 | unique_ptr<Expression> BoundLambdaRefExpression::Copy() { |
| 22 | return make_uniq<BoundLambdaRefExpression>(args&: alias, args&: return_type, args&: binding, args&: lambda_index, args&: depth); |
| 23 | } |
| 24 | |
| 25 | hash_t BoundLambdaRefExpression::Hash() const { |
| 26 | auto result = Expression::Hash(); |
| 27 | result = CombineHash(left: result, right: duckdb::Hash<uint64_t>(val: lambda_index)); |
| 28 | result = CombineHash(left: result, right: duckdb::Hash<uint64_t>(val: binding.column_index)); |
| 29 | result = CombineHash(left: result, right: duckdb::Hash<uint64_t>(val: binding.table_index)); |
| 30 | return CombineHash(left: result, right: duckdb::Hash<uint64_t>(val: depth)); |
| 31 | } |
| 32 | |
| 33 | bool BoundLambdaRefExpression::Equals(const BaseExpression &other_p) const { |
| 34 | if (!Expression::Equals(other: other_p)) { |
| 35 | return false; |
| 36 | } |
| 37 | auto &other = other_p.Cast<BoundLambdaRefExpression>(); |
| 38 | return other.binding == binding && other.lambda_index == lambda_index && other.depth == depth; |
| 39 | } |
| 40 | |
| 41 | string BoundLambdaRefExpression::ToString() const { |
| 42 | if (!alias.empty()) { |
| 43 | return alias; |
| 44 | } |
| 45 | return "#[" + to_string(val: binding.table_index) + "." + to_string(val: binding.column_index) + "." + |
| 46 | to_string(val: lambda_index) + "]" ; |
| 47 | } |
| 48 | |
| 49 | void BoundLambdaRefExpression::Serialize(FieldWriter &writer) const { |
| 50 | writer.WriteString(val: alias); |
| 51 | writer.WriteSerializable(element: return_type); |
| 52 | writer.WriteField(element: lambda_index); |
| 53 | writer.WriteField(element: binding.table_index); |
| 54 | writer.WriteField(element: binding.column_index); |
| 55 | writer.WriteField(element: depth); |
| 56 | } |
| 57 | |
| 58 | unique_ptr<Expression> BoundLambdaRefExpression::Deserialize(ExpressionDeserializationState &state, |
| 59 | FieldReader &reader) { |
| 60 | auto alias = reader.ReadRequired<string>(); |
| 61 | auto return_type = reader.ReadRequiredSerializable<LogicalType, LogicalType>(); |
| 62 | auto lambda_index = reader.ReadRequired<idx_t>(); |
| 63 | auto table_index = reader.ReadRequired<idx_t>(); |
| 64 | auto column_index = reader.ReadRequired<idx_t>(); |
| 65 | auto depth = reader.ReadRequired<idx_t>(); |
| 66 | |
| 67 | return make_uniq<BoundLambdaRefExpression>(args&: alias, args&: return_type, args: ColumnBinding(table_index, column_index), |
| 68 | args&: lambda_index, args&: depth); |
| 69 | } |
| 70 | |
| 71 | } // namespace duckdb |
| 72 | |