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

The GROUP binder is responsible for binding expressions in the GROUP BY clause. More...

Inheritance diagram for duckdb::GroupBinder:
Collaboration diagram for duckdb::GroupBinder:

Public Member Functions

 GroupBinder (Binder &binder, ClientContext &context, SelectNode &node, idx_t group_index, SelectBindState &bind_state, case_insensitive_map_t< idx_t > &group_alias_map)
Public Member Functions inherited from duckdb::ExpressionBinder
 ExpressionBinder (Binder &binder, ClientContext &context, bool replace_binder=false)
virtual bool DoesColumnAliasExist (const ColumnRefExpression &colref)
unique_ptr< Expression > Bind (unique_ptr< ParsedExpression > &expr, optional_ptr< LogicalType > result_type=nullptr, bool root_expression=true)
bool HasBoundColumns ()
 Returns whether or not any columns have been bound by the expression binder.
const vector< BoundColumnReferenceInfo > & GetBoundColumns ()
void SetCatalogLookupCallback (catalog_entry_callback_t callback)
ErrorData Bind (unique_ptr< ParsedExpression > &expr, idx_t depth, bool root_expression=false)
unique_ptr< ParsedExpression > CreateStructExtract (unique_ptr< ParsedExpression > base, const string &field_name)
 Returns the STRUCT_EXTRACT operator expression.
unique_ptr< ParsedExpression > CreateStructPack (ColumnRefExpression &col_ref)
 Returns a STRUCT_PACK function expression.
BindResult BindQualifiedColumnName (ColumnRefExpression &colref, const string &table_name)
unique_ptr< ParsedExpression > QualifyColumnName (const ParsedExpression &expr, const string &column_name, ErrorData &error)
 Returns a qualified column reference from a column name.
unique_ptr< ParsedExpression > QualifyColumnNameWithManyDots (ColumnRefExpression &col_ref, ErrorData &error)
 Returns a qualified column reference from a column reference with column_names.size() > 2.
virtual unique_ptr< ParsedExpression > QualifyColumnName (ColumnRefExpression &col_ref, ErrorData &error)
 Returns a qualified column reference from a column reference.
void QualifyColumnNamesInLambda (FunctionExpression &function, vector< unordered_set< string > > &lambda_params)
 Enables special-handling of lambda parameters by tracking them in the lambda_params vector.
void QualifyColumnNames (unique_ptr< ParsedExpression > &expr, vector< unordered_set< string > > &lambda_params, const bool within_function_expression=false)
BindResult BindCorrelatedColumns (unique_ptr< ParsedExpression > &expr, ErrorData error_message)
void BindChild (unique_ptr< ParsedExpression > &expr, idx_t depth, ErrorData &error)
void ReplaceMacroParameters (unique_ptr< ParsedExpression > &expr, vector< unordered_set< string > > &lambda_params)
void ReplaceMacroParametersInLambda (FunctionExpression &function, vector< unordered_set< string > > &lambda_params)

Public Attributes

unique_ptr< ParsedExpression > unbound_expression
 The unbound root expression.
idx_t bind_index
 The group index currently being bound.
Public Attributes inherited from duckdb::ExpressionBinder
LogicalType target_type
optional_ptr< DummyBinding > macro_binding
optional_ptr< vector< DummyBinding > > lambda_bindings

Protected Member Functions

BindResult BindExpression (unique_ptr< ParsedExpression > &expr_ptr, idx_t depth, bool root_expression) override
string UnsupportedAggregateMessage () override
BindResult BindSelectRef (idx_t entry)
BindResult BindColumnRef (ColumnRefExpression &expr, unique_ptr< ParsedExpression > &expr_ptr)
BindResult BindConstant (ConstantExpression &expr)
bool TryResolveAliasReference (ColumnRefExpression &colref, idx_t depth, bool root_expression, BindResult &result, unique_ptr< ParsedExpression > &expr_ptr) override
Protected Member Functions inherited from duckdb::ExpressionBinder
BindResult BindExpression (BetweenExpression &expr, idx_t depth)
BindResult BindExpression (CaseExpression &expr, idx_t depth)
BindResult BindExpression (CollateExpression &expr, idx_t depth)
BindResult BindExpression (CastExpression &expr, idx_t depth)
BindResult BindExpression (ColumnRefExpression &expr, idx_t depth, bool root_expression, unique_ptr< ParsedExpression > &expr_ptr)
BindResult BindExpression (LambdaRefExpression &expr, idx_t depth)
BindResult BindExpression (ComparisonExpression &expr, idx_t depth)
BindResult BindExpression (ConjunctionExpression &expr, idx_t depth)
BindResult BindExpression (ConstantExpression &expr, idx_t depth)
BindResult BindExpression (FunctionExpression &expr, idx_t depth, unique_ptr< ParsedExpression > &expr_ptr)
BindResult BindExpression (TypeExpression &expr, idx_t depth)
BindResult BindExpression (LambdaExpression &expr, idx_t depth, const vector< LogicalType > &function_child_types, optional_ptr< bind_lambda_function_t > bind_lambda_function)
BindResult BindExpression (OperatorExpression &expr, idx_t depth)
BindResult BindExpression (ParameterExpression &expr, idx_t depth)
BindResult BindExpression (SubqueryExpression &expr, idx_t depth)
BindResult BindPositionalReference (unique_ptr< ParsedExpression > &expr, idx_t depth, bool root_expression)
void TransformCapturedLambdaColumn (unique_ptr< Expression > &original, unique_ptr< Expression > &replacement, BoundLambdaExpression &bound_lambda_expr, const optional_ptr< bind_lambda_function_t > bind_lambda_function, const vector< LogicalType > &function_child_types)
void CaptureLambdaColumns (BoundLambdaExpression &bound_lambda_expr, unique_ptr< Expression > &expr, const optional_ptr< bind_lambda_function_t > bind_lambda_function, const vector< LogicalType > &function_child_types)
virtual unique_ptr< ParsedExpression > GetSQLValueFunction (const string &column_name)
LogicalType ResolveOperatorType (OperatorExpression &op, vector< unique_ptr< Expression > > &children)
LogicalType ResolveCoalesceType (OperatorExpression &op, vector< unique_ptr< Expression > > &children)
LogicalType ResolveNotType (OperatorExpression &op, vector< unique_ptr< Expression > > &children)
BindResult BindUnsupportedExpression (ParsedExpression &expr, idx_t depth, const string &message)
optional_ptr< CatalogEntry > BindAndQualifyFunction (FunctionExpression &function, bool allow_throw)
virtual BindResult BindGroupingFunction (OperatorExpression &op, idx_t depth)
virtual BindResult BindFunction (FunctionExpression &expr, ScalarFunctionCatalogEntry &function, idx_t depth)
virtual BindResult BindLambdaFunction (FunctionExpression &expr, ScalarFunctionCatalogEntry &function, idx_t depth)
virtual BindResult BindAggregate (FunctionExpression &expr, AggregateFunctionCatalogEntry &function, idx_t depth)
virtual BindResult BindUnnest (FunctionExpression &expr, idx_t depth, bool root_expression)
virtual BindResult BindMacro (FunctionExpression &expr, ScalarMacroCatalogEntry &macro, idx_t depth, unique_ptr< ParsedExpression > &expr_ptr)
void UnfoldMacroExpression (FunctionExpression &function, ScalarMacroCatalogEntry &macro_func, unique_ptr< ParsedExpression > &expr, idx_t depth)
virtual string UnsupportedUnnestMessage ()
optional_ptr< CatalogEntry > GetCatalogEntry (const string &catalog, const string &schema, const EntryLookupInfo &lookup_info, OnEntryNotFound on_entry_not_found)
BindResult TryBindLambdaOrJson (FunctionExpression &function, idx_t depth, CatalogEntry &func, const LambdaSyntaxType syntax_type)
unique_ptr< ParsedExpression > QualifyColumnNameWithManyDotsInternal (ColumnRefExpression &col_ref, ErrorData &error, idx_t &struct_extract_start)
virtual void ThrowIfUnnestInLambda (const ColumnBinding &column_binding)

Protected Attributes

SelectNode & node
SelectBindState & bind_state
case_insensitive_map_t< idx_t > & group_alias_map
unordered_set< idx_t > used_aliases
idx_t group_index
Protected Attributes inherited from duckdb::ExpressionBinder
Binder & binder
ClientContext & context
optional_ptr< ExpressionBinder > stored_binder
vector< BoundColumnReferenceInfo > bound_columns

Additional Inherited Members

Static Public Member Functions inherited from duckdb::ExpressionBinder
static bool IsPotentialAlias (const ColumnRefExpression &colref)
static void QualifyColumnNames (Binder &binder, unique_ptr< ParsedExpression > &expr)
 Entry point for qualifying the column references of the expression.
static void QualifyColumnNames (ExpressionBinder &binder, unique_ptr< ParsedExpression > &expr)
static bool PushCollation (ClientContext &context, unique_ptr< Expression > &source, const LogicalType &sql_type, CollationType type=CollationType::ALL_COLLATIONS)
static void TestCollation (ClientContext &context, const string &collation)
static void ExtractCorrelatedExpressions (Binder &binder, Expression &expr)
static bool ContainsNullType (const LogicalType &type)
static LogicalType ExchangeNullType (const LogicalType &type)
static bool ContainsType (const LogicalType &type, LogicalTypeId target)
static LogicalType ExchangeType (const LogicalType &type, LogicalTypeId target, LogicalType new_type)
static LogicalType GetExpressionReturnType (const Expression &expr)
static bool IsUnnestFunction (const string &function_name)
 Returns true if the function name is an alias for the UNNEST function.

Detailed Description

The GROUP binder is responsible for binding expressions in the GROUP BY clause.

Constructor & Destructor Documentation

◆ GroupBinder()

duckdb::GroupBinder::GroupBinder ( Binder & binder,
ClientContext & context,
SelectNode & node,
idx_t group_index,
SelectBindState & bind_state,
case_insensitive_map_t< idx_t > & group_alias_map )
377629 : ExpressionBinder(binder, context), node(node), bind_state(bind_state), group_alias_map(group_alias_map),
377630 group_index(group_index) {
377631}

Member Function Documentation

◆ BindExpression()

BindResult duckdb::GroupBinder::BindExpression ( unique_ptr< ParsedExpression > & expr_ptr,
idx_t depth,
bool root_expression )
overrideprotectedvirtual

Bind the given expression. Unlike Bind(), this does not mute the given ParsedExpression. Exposed to be used from sub-binders that aren't subclasses of ExpressionBinder.

Reimplemented from duckdb::ExpressionBinder.

377633 {
377634 auto &expr = *expr_ptr;
377635 if (root_expression && depth == 0) {
377636 switch (expr.GetExpressionClass()) {
377637 case ExpressionClass::COLUMN_REF:
377638 return BindColumnRef(expr.Cast<ColumnRefExpression>(), expr_ptr);
377639 case ExpressionClass::CONSTANT:
377640 return BindConstant(expr.Cast<ConstantExpression>());
377641 case ExpressionClass::PARAMETER:
377642 throw ParameterNotAllowedException("Parameter not supported in GROUP BY clause");
377643 default:
377644 break;
377645 }
377646 }
377647 switch (expr.GetExpressionClass()) {
377648 case ExpressionClass::DEFAULT:
377649 return BindUnsupportedExpression(expr, depth, "GROUP BY clause cannot contain DEFAULT clause");
377650 case ExpressionClass::WINDOW:
377651 return BindUnsupportedExpression(expr, depth, "GROUP BY clause cannot contain window functions!");
377652 default:
377653 return ExpressionBinder::BindExpression(expr_ptr, depth);
377654 }
377655}
virtual BindResult BindExpression(unique_ptr< ParsedExpression > &expr_ptr, idx_t depth, bool root_expression=false)
Definition duckdb.cpp:378842
Here is the call graph for this function:

◆ UnsupportedAggregateMessage()

string duckdb::GroupBinder::UnsupportedAggregateMessage ( )
overrideprotectedvirtual

Reimplemented from duckdb::ExpressionBinder.

377657 {
377658 return "GROUP BY clause cannot contain aggregates!";
377659}

◆ BindSelectRef()

BindResult duckdb::GroupBinder::BindSelectRef ( idx_t entry)
protected
377661 {
377662 if (used_aliases.find(entry) != used_aliases.end()) {
377663 // the alias has already been bound to before!
377664 // this happens if we group on the same alias twice
377665 // e.g. GROUP BY k, k or GROUP BY 1, 1
377666 // in this case, we can just replace the grouping with a constant since the second grouping has no effect
377667 // (the constant grouping will be optimized out later)
377668 return BindResult(make_uniq<BoundConstantExpression>(Value::INTEGER(42)));
377669 }
377670 if (entry >= node.select_list.size()) {
377671 throw BinderException("GROUP BY term out of range - should be between 1 and %d", (int)node.select_list.size());
377672 }
377673 // we replace the root expression, also replace the unbound expression
377674 unbound_expression = node.select_list[entry]->Copy();
377675 // move the expression that this refers to here and bind it
377676 auto select_entry = std::move(node.select_list[entry]);
377677 auto binding = Bind(select_entry, nullptr, false);
377678 // now replace the original expression in the select list with a reference to this group
377679 group_alias_map[to_string(entry)] = bind_index;
377680 node.select_list[entry] = make_uniq<ColumnRefExpression>(to_string(entry));
377681 // insert into the set of used aliases
377682 used_aliases.insert(entry);
377683 return BindResult(std::move(binding));
377684}
idx_t bind_index
The group index currently being bound.
Definition duckdb.cpp:363992
unique_ptr< ParsedExpression > unbound_expression
The unbound root expression.
Definition duckdb.cpp:363990
static DUCKDB_API Value INTEGER(int32_t value)
Create an integer Value from a specified value.
Definition duckdb.cpp:132139
std::string to_string(const T &value)
Definition duckdb.cpp:19425

◆ BindColumnRef()

BindResult duckdb::GroupBinder::BindColumnRef ( ColumnRefExpression & expr,
unique_ptr< ParsedExpression > & expr_ptr )
protected
377723 {
377724 // columns in GROUP BY clauses:
377725 // FIRST refer to the original tables, and
377726 // THEN if no match is found refer to aliases in the SELECT list
377727 // THEN if no match is found, refer to outer queries
377728
377729 // first try to bind to the base columns (original tables)
377730 return ExpressionBinder::BindExpression(colref, 0, true, expr_ptr);
377731}

◆ BindConstant()

BindResult duckdb::GroupBinder::BindConstant ( ConstantExpression & expr)
protected
377686 {
377687 // constant as root expression
377688 if (!constant.value.type().IsIntegral()) {
377689 // non-integral expression, we just leave the constant here.
377690 return ExpressionBinder::BindExpression(constant, 0);
377691 }
377692 // INTEGER constant: we use the integer as an index into the select list (e.g. GROUP BY 1)
377693 auto index = (idx_t)constant.value.GetValue<int64_t>();
377694 return BindSelectRef(index - 1);
377695}
index
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ TryResolveAliasReference()

bool duckdb::GroupBinder::TryResolveAliasReference ( ColumnRefExpression & colref,
idx_t depth,
bool root_expression,
BindResult & result,
unique_ptr< ParsedExpression > & expr_ptr )
overrideprotectedvirtual

Reimplemented from duckdb::ExpressionBinder.

377698 {
377699 // try to resolve alias references in GROUP
377700 // failed to bind the column and the node is the root expression with depth = 0
377701 // check if refers to an alias in the select clause
377702
377703 auto &alias_name = colref.GetColumnName();
377704 auto entry = bind_state.alias_map.find(alias_name);
377705 if (entry == bind_state.alias_map.end()) {
377706 // no matching alias found
377707 return false;
377708 }
377709 if (!root_expression) {
377710 result = BindResult(BinderException(
377711 colref,
377712 "Alias with name \"%s\" exists, but aliases cannot be used as part of an expression in the GROUP BY",
377713 alias_name));
377714 return true;
377715 }
377716 result = BindResult(BindSelectRef(entry->second));
377717 if (!result.HasError()) {
377718 group_alias_map[alias_name] = bind_index;
377719 }
377720 return true;
377721}

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