Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::LambdaExpression Class Reference

DuckDB 1.3. introduced a new lambda syntax: lambda x, y: x + y. The new syntax resolves any ambiguity with the JSON arrow operator. Currently, we're still using a LambdaExpression for both cases. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::LambdaExpression:
Collaboration diagram for duckdb::LambdaExpression:

Public Member Functions

 LambdaExpression (vector< string > named_parameters_p, unique_ptr< ParsedExpression > expr)
 LambdaExpression (unique_ptr< ParsedExpression > lhs, unique_ptr< ParsedExpression > expr)
vector< reference< const ParsedExpression > > ExtractColumnRefExpressions (string &error_message) const
 Returns a vector to the column references in the LHS expression, and fills the error message, if the LHS is not a valid lambda parameter list.
string ToString () const override
 Convert the Expression to a String.
hash_t Hash () const override
unique_ptr< ParsedExpression > Copy () const override
 Create a copy of this expression.
void Serialize (Serializer &serializer) const override
Public Member Functions inherited from duckdb::ParsedExpression
 ParsedExpression (ExpressionType type, ExpressionClass expression_class)
 Create an Expression.
bool IsAggregate () const override
 Returns true if this expression is an aggregate or not.
bool IsWindow () const override
 Returns true if the expression has a window function or not.
bool HasSubquery () const override
 Returns true if the query contains a subquery.
bool IsScalar () const override
 Returns true if expression does not contain a group ref or col ref or parameter.
bool HasParameter () const override
 Returns true if the expression has a parameter.
bool Equals (const BaseExpression &other) const override
 Returns true if this expression is equal to another expression.
hash_t Hash () const override
Public Member Functions inherited from duckdb::BaseExpression
 BaseExpression (ExpressionType type, ExpressionClass expression_class)
 Create an Expression.
ExpressionClass GetExpressionClass () const
 Returns the class of the expression.
ExpressionType GetExpressionType () const
 Returns the type of the expression.
void SetExpressionTypeUnsafe (ExpressionType new_type)
optional_idx GetQueryLocation () const
 Returns the location in the query (if any).
void SetQueryLocation (optional_idx location)
 Sets the location in the query.
bool HasAlias () const
 Returns true if the expression has a non-empty alias.
const string & GetAlias () const
 Returns the alias of the expression.
void SetAlias (const string &alias_p)
 Sets the alias of the expression.
void SetAlias (string &&alias_p)
 Sets the alias of the expression.
void ClearAlias ()
 Clears the alias of the expression.
virtual string GetName () const
 Get the name of the expression.
void Print () const
 Print the expression to stdout.
bool operator== (const BaseExpression &rhs) const
virtual void Verify () const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static string InvalidParametersErrorMessage ()
 Returns the error message for an invalid lambda parameter list.
static bool IsLambdaParameter (const vector< unordered_set< string > > &lambda_params, const string &column_name)
 Returns true, if the column_name is a lambda parameter name.
static bool Equal (const LambdaExpression &a, const LambdaExpression &b)
static unique_ptr< ParsedExpression > Deserialize (Deserializer &deserializer)
Static Public Member Functions inherited from duckdb::ParsedExpression
static unique_ptr< ParsedExpression > Deserialize (Deserializer &deserializer)
static bool Equals (const unique_ptr< ParsedExpression > &left, const unique_ptr< ParsedExpression > &right)
static bool ListEquals (const vector< unique_ptr< ParsedExpression > > &left, const vector< unique_ptr< ParsedExpression > > &right)
Static Public Member Functions inherited from duckdb::BaseExpression
static bool Equals (const BaseExpression &left, const BaseExpression &right)

Public Attributes

LambdaSyntaxType syntax_type
 The syntax type.
unique_ptr< ParsedExpression > lhs
 The LHS of a lambda expression or the JSON "->"-operator. We need the context to determine if the LHS is a list of column references (lambda parameters) or an expression (JSON).
unique_ptr< ParsedExpression > expr
 The lambda or JSON expression (RHS).
unique_ptr< ParsedExpression > copied_expr
 Band-aid for conflicts between lambda binding and JSON binding.
Public Attributes inherited from duckdb::BaseExpression
ExpressionType type
 Type of the expression.
ExpressionClass expression_class
 The expression class of the node.
string alias
 The alias of the expression,.
optional_idx query_location
 The location in the query (if any).

Static Public Attributes

static constexpr const ExpressionClass TYPE = ExpressionClass::LAMBDA

Additional Inherited Members

Protected Member Functions inherited from duckdb::ParsedExpression
void CopyProperties (const ParsedExpression &other)

Detailed Description

DuckDB 1.3. introduced a new lambda syntax: lambda x, y: x + y. The new syntax resolves any ambiguity with the JSON arrow operator. Currently, we're still using a LambdaExpression for both cases.

Constructor & Destructor Documentation

◆ LambdaExpression() [1/3]

duckdb::LambdaExpression::LambdaExpression ( vector< string > named_parameters_p,
unique_ptr< ParsedExpression > expr )
336892 : ParsedExpression(ExpressionType::LAMBDA, ExpressionClass::LAMBDA), syntax_type(LambdaSyntaxType::LAMBDA_KEYWORD),
336893 expr(std::move(expr)) {
336894 if (named_parameters_p.size() == 1) {
336895 lhs = make_uniq<ColumnRefExpression>(named_parameters_p.back());
336896 return;
336897 }
336898 // Create a dummy row function and insert the children.
336899 vector<unique_ptr<ParsedExpression>> children;
336900 for (const auto &name : named_parameters_p) {
336901 auto child = make_uniq<ColumnRefExpression>(name);
336902 children.push_back(std::move(child));
336903 }
336904 lhs = make_uniq<FunctionExpression>("row", std::move(children));
336905}
unique_ptr< ParsedExpression > expr
The lambda or JSON expression (RHS).
Definition duckdb.hpp:36446
LambdaSyntaxType syntax_type
The syntax type.
Definition duckdb.hpp:36441
unique_ptr< ParsedExpression > lhs
The LHS of a lambda expression or the JSON "->"-operator. We need the context to determine if the LHS...
Definition duckdb.hpp:36444
ParsedExpression(ExpressionType type, ExpressionClass expression_class)
Create an Expression.
Definition duckdb.hpp:13557

◆ LambdaExpression() [2/3]

duckdb::LambdaExpression::LambdaExpression ( unique_ptr< ParsedExpression > lhs,
unique_ptr< ParsedExpression > expr )
336908 : ParsedExpression(ExpressionType::LAMBDA, ExpressionClass::LAMBDA), syntax_type(LambdaSyntaxType::SINGLE_ARROW),
336909 lhs(std::move(lhs)), expr(std::move(expr)) {
336910}

◆ LambdaExpression() [3/3]

duckdb::LambdaExpression::LambdaExpression ( )
private
336888 : ParsedExpression(ExpressionType::LAMBDA, ExpressionClass::LAMBDA) {
336889}

Member Function Documentation

◆ ExtractColumnRefExpressions()

vector< reference< const ParsedExpression > > duckdb::LambdaExpression::ExtractColumnRefExpressions ( string & error_message) const

Returns a vector to the column references in the LHS expression, and fills the error message, if the LHS is not a valid lambda parameter list.

336912 {
336913 // we return an error message because we can't throw a binder exception here,
336914 // since we can't distinguish between a lambda function and the JSON operator yet
336915 vector<reference<const ParsedExpression>> column_refs;
336916
336917 if (lhs->GetExpressionClass() == ExpressionClass::COLUMN_REF) {
336918 // single column reference
336919 column_refs.emplace_back(*lhs);
336920 return column_refs;
336921 }
336922
336923 if (lhs->GetExpressionClass() == ExpressionClass::FUNCTION) {
336924 // list of column references
336925 auto &func_expr = lhs->Cast<FunctionExpression>();
336926 if (func_expr.function_name != "row") {
336927 error_message = InvalidParametersErrorMessage();
336928 return column_refs;
336929 }
336930
336931 for (auto &child : func_expr.children) {
336932 if (child->GetExpressionClass() != ExpressionClass::COLUMN_REF) {
336933 error_message = InvalidParametersErrorMessage();
336934 return column_refs;
336935 }
336936 column_refs.emplace_back(*child);
336937 }
336938 }
336939
336940 if (column_refs.empty()) {
336941 error_message = InvalidParametersErrorMessage();
336942 }
336943 return column_refs;
336944}
static string InvalidParametersErrorMessage()
Returns the error message for an invalid lambda parameter list.
Definition duckdb.cpp:336946
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InvalidParametersErrorMessage()

string duckdb::LambdaExpression::InvalidParametersErrorMessage ( )
static

Returns the error message for an invalid lambda parameter list.

336946 {
336947 // FIXME: remove this once we only support the new lambda syntax.
336948 return "Invalid lambda parameters! Parameters must be unqualified comma-separated names like x or (x, y).";
336949}
Here is the caller graph for this function:

◆ IsLambdaParameter()

bool duckdb::LambdaExpression::IsLambdaParameter ( const vector< unordered_set< string > > & lambda_params,
const string & column_name )
static

Returns true, if the column_name is a lambda parameter name.

336952 {
336953 for (const auto &level : lambda_params) {
336954 if (level.find(parameter_name) != level.end()) {
336955 return true;
336956 }
336957 }
336958 return false;
336959}
Here is the caller graph for this function:

◆ ToString()

string duckdb::LambdaExpression::ToString ( ) const
overridevirtual

Convert the Expression to a String.

Implements duckdb::BaseExpression.

336961 {
336962 if (syntax_type != LambdaSyntaxType::LAMBDA_KEYWORD) {
336963 return "(" + lhs->ToString() + " -> " + expr->ToString() + ")";
336964 }
336965
336966 string str = "";
336967 auto column_refs = ExtractColumnRefExpressions(str);
336968
336969 str = "(lambda ";
336970 for (idx_t i = 0; i < column_refs.size(); i++) {
336971 auto &column_ref = column_refs[i].get();
336972 auto &cast_column_ref = column_ref.Cast<ColumnRefExpression>();
336973
336974 if (i == column_refs.size() - 1) {
336975 str += cast_column_ref.ToString();
336976 continue;
336977 }
336978 str += cast_column_ref.ToString() + ", ";
336979 }
336980 return str + ": " + expr->ToString() + ")";
336981}
vector< reference< const ParsedExpression > > ExtractColumnRefExpressions(string &error_message) const
Returns a vector to the column references in the LHS expression, and fills the error message,...
Definition duckdb.cpp:336912
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ Equal()

bool duckdb::LambdaExpression::Equal ( const LambdaExpression & a,
const LambdaExpression & b )
static
336983 {
336984 return a.lhs->Equals(*b.lhs) && a.expr->Equals(*b.expr);
336985}

◆ Hash()

hash_t duckdb::LambdaExpression::Hash ( ) const
overridevirtual

Creates a hash value of this expression. It is important that if two expressions are identical (i.e. Expression::Equals() returns true), that their hash value is identical as well.

Implements duckdb::BaseExpression.

336987 {
336988 hash_t result = lhs->Hash();
336990 result = CombineHash(result, expr->Hash());
336991 return result;
336992}
hash_t Hash() const override
Definition duckdb.cpp:340509
uint64_t hash_t
The type used for hashes.
Definition duckdb.hpp:243
hash_t CombineHash(hash_t left, hash_t right)
Combine two hashes by XORing them.
Definition duckdb.hpp:4635
Here is the call graph for this function:

◆ Copy()

unique_ptr< ParsedExpression > duckdb::LambdaExpression::Copy ( ) const
overridevirtual

Create a copy of this expression.

Implements duckdb::ParsedExpression.

336994 {
336995 auto copy = make_uniq<LambdaExpression>(lhs->Copy(), expr->Copy());
336996 copy->syntax_type = syntax_type;
336997 copy->CopyProperties(*this);
336998 return std::move(copy);
336999}

◆ Serialize()

void duckdb::LambdaExpression::Serialize ( Serializer & serializer) const
overridevirtual

Reimplemented from duckdb::ParsedExpression.

418864 {
418865 ParsedExpression::Serialize(serializer);
418866 serializer.WritePropertyWithDefault<unique_ptr<ParsedExpression>>(200, "lhs", lhs);
418867 serializer.WritePropertyWithDefault<unique_ptr<ParsedExpression>>(201, "expr", expr);
418868 if (serializer.ShouldSerialize(5)) {
418869 serializer.WritePropertyWithDefault<LambdaSyntaxType>(202, "syntax_type", syntax_type, LambdaSyntaxType::SINGLE_ARROW_STORAGE);
418870 }
418871}

◆ Deserialize()

unique_ptr< ParsedExpression > duckdb::LambdaExpression::Deserialize ( Deserializer & deserializer)
static
418873 {
418874 auto result = duckdb::unique_ptr<LambdaExpression>(new LambdaExpression());
418875 deserializer.ReadPropertyWithDefault<unique_ptr<ParsedExpression>>(200, "lhs", result->lhs);
418876 deserializer.ReadPropertyWithDefault<unique_ptr<ParsedExpression>>(201, "expr", result->expr);
418877 deserializer.ReadPropertyWithExplicitDefault<LambdaSyntaxType>(202, "syntax_type", result->syntax_type, LambdaSyntaxType::SINGLE_ARROW_STORAGE);
418878 return std::move(result);
418879}

The documentation for this class was generated from the following files: