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::FunctionExpression Class Reference

Represents a function call. More...

Inheritance diagram for duckdb::FunctionExpression:
Collaboration diagram for duckdb::FunctionExpression:

Public Member Functions

DUCKDB_API FunctionExpression (string catalog_name, string schema_name, const string &function_name, vector< unique_ptr< ParsedExpression > > children, unique_ptr< ParsedExpression > filter=nullptr, unique_ptr< OrderModifier > order_bys=nullptr, bool distinct=false, bool is_operator=false, bool export_state=false)
DUCKDB_API FunctionExpression (const string &function_name, vector< unique_ptr< ParsedExpression > > children, unique_ptr< ParsedExpression > filter=nullptr, unique_ptr< OrderModifier > order_bys=nullptr, bool distinct=false, bool is_operator=false, bool export_state=false)
string ToString () const override
 Convert the Expression to a String.
unique_ptr< ParsedExpression > Copy () const override
 Create a copy of this expression.
hash_t Hash () const override
void Serialize (Serializer &serializer) const override
void Verify () const override
optional_ptr< ParsedExpression > IsLambdaFunction () const
 Returns a pointer to the lambda expression, if the function has a lambda expression as a child, else nullptr.
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
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static bool Equal (const FunctionExpression &a, const FunctionExpression &b)
static unique_ptr< ParsedExpression > Deserialize (Deserializer &deserializer)
template<class T, class BASE, class ORDER_MODIFIER = OrderModifier>
static string ToString (const T &entry, const string &catalog, const string &schema, const string &function_name, bool is_operator=false, bool distinct=false, BASE *filter=nullptr, ORDER_MODIFIER *order_bys=nullptr, bool export_state=false, bool add_alias=false)
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

string catalog
 Catalog of the function.
string schema
 Schema of the function.
string function_name
 Function name.
bool is_operator
 Whether or not the function is an operator, only used for rendering.
vector< unique_ptr< ParsedExpression > > children
 List of arguments to the function.
bool distinct
 Whether or not the aggregate function is distinct, only used for aggregates.
unique_ptr< ParsedExpression > filter
 Expression representing a filter, only used for aggregates.
unique_ptr< OrderModifier > order_bys
 Modifier representing an ORDER BY, only used for aggregates.
bool export_state
 whether this function should export its state or not
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::FUNCTION

Additional Inherited Members

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

Detailed Description

Represents a function call.

Constructor & Destructor Documentation

◆ FunctionExpression() [1/3]

duckdb::FunctionExpression::FunctionExpression ( string catalog_name,
string schema_name,
const string & function_name,
vector< unique_ptr< ParsedExpression > > children,
unique_ptr< ParsedExpression > filter = nullptr,
unique_ptr< OrderModifier > order_bys = nullptr,
bool distinct = false,
bool is_operator = false,
bool export_state = false )
336786 : ParsedExpression(ExpressionType::FUNCTION, ExpressionClass::FUNCTION), catalog(std::move(catalog)),
336788 children(std::move(children_p)), distinct(distinct), filter(std::move(filter)), order_bys(std::move(order_bys_p)),
336789 export_state(export_state_p) {
336790 D_ASSERT(!function_name.empty());
336791 if (!order_bys) {
336792 order_bys = make_uniq<OrderModifier>();
336793 }
336794}
bool distinct
Whether or not the aggregate function is distinct, only used for aggregates.
Definition duckdb.cpp:3155
bool is_operator
Whether or not the function is an operator, only used for rendering.
Definition duckdb.cpp:3151
unique_ptr< ParsedExpression > filter
Expression representing a filter, only used for aggregates.
Definition duckdb.cpp:3157
string catalog
Catalog of the function.
Definition duckdb.cpp:3145
string function_name
Function name.
Definition duckdb.cpp:3149
unique_ptr< OrderModifier > order_bys
Modifier representing an ORDER BY, only used for aggregates.
Definition duckdb.cpp:3159
vector< unique_ptr< ParsedExpression > > children
List of arguments to the function.
Definition duckdb.cpp:3153
bool export_state
whether this function should export its state or not
Definition duckdb.cpp:3161
string schema
Schema of the function.
Definition duckdb.cpp:3147
ParsedExpression(ExpressionType type, ExpressionClass expression_class)
Create an Expression.
Definition duckdb.hpp:13557
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630

◆ FunctionExpression() [2/3]

duckdb::FunctionExpression::FunctionExpression ( const string & function_name,
vector< unique_ptr< ParsedExpression > > children,
unique_ptr< ParsedExpression > filter = nullptr,
unique_ptr< OrderModifier > order_bys = nullptr,
bool distinct = false,
bool is_operator = false,
bool export_state = false )
336799 : FunctionExpression(INVALID_CATALOG, INVALID_SCHEMA, function_name, std::move(children_p), std::move(filter),
336800 std::move(order_bys), distinct, is_operator, export_state_p) {
336801}

◆ FunctionExpression() [3/3]

duckdb::FunctionExpression::FunctionExpression ( )
private
336779 : ParsedExpression(ExpressionType::FUNCTION, ExpressionClass::FUNCTION) {
336780}

Member Function Documentation

◆ ToString() [1/2]

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

Convert the Expression to a String.

Implements duckdb::BaseExpression.

336803 {
336805 filter.get(), order_bys.get(), export_state, true);
336806}
string ToString() const override
Convert the Expression to a String.
Definition duckdb.cpp:336803
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Copy()

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

Create a copy of this expression.

Implements duckdb::ParsedExpression.

336842 {
336843 vector<unique_ptr<ParsedExpression>> copy_children;
336844 unique_ptr<ParsedExpression> filter_copy;
336845 copy_children.reserve(children.size());
336846 for (auto &child : children) {
336847 copy_children.push_back(child->Copy());
336848 }
336849 if (filter) {
336850 filter_copy = filter->Copy();
336851 }
336852 auto order_copy = order_bys ? unique_ptr_cast<ResultModifier, OrderModifier>(order_bys->Copy()) : nullptr;
336853 auto copy =
336854 make_uniq<FunctionExpression>(catalog, schema, function_name, std::move(copy_children), std::move(filter_copy),
336855 std::move(order_copy), distinct, is_operator, export_state);
336856 copy->CopyProperties(*this);
336857 return std::move(copy);
336858}

◆ Equal()

bool duckdb::FunctionExpression::Equal ( const FunctionExpression & a,
const FunctionExpression & b )
static
336808 {
336809 if (a.catalog != b.catalog || a.schema != b.schema || a.function_name != b.function_name ||
336810 b.distinct != a.distinct) {
336811 return false;
336812 }
336813 if (b.children.size() != a.children.size()) {
336814 return false;
336815 }
336816 for (idx_t i = 0; i < a.children.size(); i++) {
336817 if (!a.children[i]->Equals(*b.children[i])) {
336818 return false;
336819 }
336820 }
336821 if (!ParsedExpression::Equals(a.filter, b.filter)) {
336822 return false;
336823 }
336824 if (!OrderModifier::Equals(a.order_bys, b.order_bys)) {
336825 return false;
336826 }
336827 if (a.export_state != b.export_state) {
336828 return false;
336829 }
336830 return true;
336831}
bool Equals(const ResultModifier &other) const override
Returns true if the two result modifiers are equivalent.
Definition duckdb.cpp:348694
bool Equals(const BaseExpression &other) const override
Returns true if this expression is equal to another expression.
Definition duckdb.cpp:340462
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Hash()

hash_t duckdb::FunctionExpression::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.

336833 {
336834 hash_t result = ParsedExpression::Hash();
336835 result = CombineHash(result, duckdb::Hash<const char *>(schema.c_str()));
336836 result = CombineHash(result, duckdb::Hash<const char *>(function_name.c_str()));
336837 result = CombineHash(result, duckdb::Hash<bool>(distinct));
336838 result = CombineHash(result, duckdb::Hash<bool>(export_state));
336839 return result;
336840}
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:

◆ Serialize()

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

Reimplemented from duckdb::ParsedExpression.

418836 {
418837 ParsedExpression::Serialize(serializer);
418838 serializer.WritePropertyWithDefault<string>(200, "function_name", function_name);
418839 serializer.WritePropertyWithDefault<string>(201, "schema", schema);
418840 serializer.WritePropertyWithDefault<vector<unique_ptr<ParsedExpression>>>(202, "children", children);
418841 serializer.WritePropertyWithDefault<unique_ptr<ParsedExpression>>(203, "filter", filter);
418842 serializer.WritePropertyWithDefault<unique_ptr<OrderModifier>>(204, "order_bys", order_bys);
418843 serializer.WritePropertyWithDefault<bool>(205, "distinct", distinct);
418844 serializer.WritePropertyWithDefault<bool>(206, "is_operator", is_operator);
418845 serializer.WritePropertyWithDefault<bool>(207, "export_state", export_state);
418846 serializer.WritePropertyWithDefault<string>(208, "catalog", catalog);
418847}

◆ Deserialize()

unique_ptr< ParsedExpression > duckdb::FunctionExpression::Deserialize ( Deserializer & deserializer)
static
418849 {
418850 auto result = duckdb::unique_ptr<FunctionExpression>(new FunctionExpression());
418851 deserializer.ReadPropertyWithDefault<string>(200, "function_name", result->function_name);
418852 deserializer.ReadPropertyWithDefault<string>(201, "schema", result->schema);
418853 deserializer.ReadPropertyWithDefault<vector<unique_ptr<ParsedExpression>>>(202, "children", result->children);
418854 deserializer.ReadPropertyWithDefault<unique_ptr<ParsedExpression>>(203, "filter", result->filter);
418855 auto order_bys = deserializer.ReadPropertyWithDefault<unique_ptr<ResultModifier>>(204, "order_bys");
418856 result->order_bys = unique_ptr_cast<ResultModifier, OrderModifier>(std::move(order_bys));
418857 deserializer.ReadPropertyWithDefault<bool>(205, "distinct", result->distinct);
418858 deserializer.ReadPropertyWithDefault<bool>(206, "is_operator", result->is_operator);
418859 deserializer.ReadPropertyWithDefault<bool>(207, "export_state", result->export_state);
418860 deserializer.ReadPropertyWithDefault<string>(208, "catalog", result->catalog);
418861 return std::move(result);
418862}

◆ Verify()

void duckdb::FunctionExpression::Verify ( ) const
overridevirtual

Reimplemented from duckdb::BaseExpression.

336860 {
336861 D_ASSERT(!function_name.empty());
336862}

◆ IsLambdaFunction()

optional_ptr< ParsedExpression > duckdb::FunctionExpression::IsLambdaFunction ( ) const

Returns a pointer to the lambda expression, if the function has a lambda expression as a child, else nullptr.

336864 {
336865 // Ignore the ->> operator (JSON extension).
336866 if (function_name == "->>") {
336867 return nullptr;
336868 }
336869 // Check the children for lambda expressions.
336870 for (auto &child : children) {
336871 if (child->GetExpressionClass() == ExpressionClass::LAMBDA) {
336872 return *child;
336873 }
336874 }
336875 return nullptr;
336876}

◆ ToString() [2/2]

template<class T, class BASE, class ORDER_MODIFIER = OrderModifier>
string duckdb::FunctionExpression::ToString ( const T & entry,
const string & catalog,
const string & schema,
const string & function_name,
bool is_operator = false,
bool distinct = false,
BASE * filter = nullptr,
ORDER_MODIFIER * order_bys = nullptr,
bool export_state = false,
bool add_alias = false )
inlinestatic
3183 {
3184 if (is_operator) {
3185 // built-in operator
3186 D_ASSERT(!distinct);
3187 if (entry.children.size() == 1) {
3188 if (StringUtil::Contains(function_name, "__postfix")) {
3189 return "((" + entry.children[0]->ToString() + ")" +
3190 StringUtil::Replace(function_name, "__postfix", "") + ")";
3191 } else {
3192 return function_name + "(" + entry.children[0]->ToString() + ")";
3193 }
3194 } else if (entry.children.size() == 2) {
3195 return StringUtil::Format("(%s %s %s)", entry.children[0]->ToString(), function_name,
3196 entry.children[1]->ToString());
3197 }
3198 }
3199 // standard function call
3200 string result;
3201 if (!catalog.empty()) {
3203 }
3204 if (!schema.empty()) {
3206 }
3208 result += "(";
3209 if (distinct) {
3210 result += "DISTINCT ";
3211 }
3212 result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
3213 return child->GetAlias().empty() || !add_alias
3214 ? child->ToString()
3215 : StringUtil::Format("%s := %s", SQLIdentifier(child->GetAlias()), child->ToString());
3216 });
3217 // ordered aggregate
3218 if (order_bys && !order_bys->orders.empty()) {
3219 if (entry.children.empty()) {
3220 result += ") WITHIN GROUP (";
3221 }
3222 result += " ORDER BY ";
3223 for (idx_t i = 0; i < order_bys->orders.size(); i++) {
3224 if (i > 0) {
3225 result += ", ";
3226 }
3227 result += order_bys->orders[i].ToString();
3228 }
3229 }
3230 result += ")";
3231
3232 // filtered aggregate
3233 if (filter) {
3234 result += " FILTER (WHERE " + filter->ToString() + ")";
3235 }
3236
3237 if (export_state) {
3238 result += " EXPORT_STATE";
3239 }
3240
3241 return result;
3242 }
static string WriteOptionallyQuoted(const string &text, char quote='"', bool allow_caps = true, KeywordCategory category = KeywordCategory::KEYWORD_NONE)
Writes a string that is optionally quoted + escaped so it can be used as an identifier.
Definition duckdb.cpp:338034
static DUCKDB_API bool Contains(const string &haystack, const string &needle)
Returns true if the needle string exists in the haystack.
Definition duckdb.cpp:109323
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
static DUCKDB_API string Join(const vector< string > &input, const string &separator)
Join multiple strings into one string. Components are concatenated by the given separator.
Definition duckdb.cpp:109497

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