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::ExpressionBinder Class Reference
Inheritance diagram for duckdb::ExpressionBinder:
Collaboration diagram for duckdb::ExpressionBinder:

Public Member Functions

 ExpressionBinder (Binder &binder, ClientContext &context, bool replace_binder=false)
virtual bool TryResolveAliasReference (ColumnRefExpression &colref, idx_t depth, bool root_expression, BindResult &result, unique_ptr< ParsedExpression > &expr_ptr)
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)
virtual BindResult BindExpression (unique_ptr< ParsedExpression > &expr_ptr, idx_t depth, bool root_expression=false)
void ReplaceMacroParameters (unique_ptr< ParsedExpression > &expr, vector< unordered_set< string > > &lambda_params)
void ReplaceMacroParametersInLambda (FunctionExpression &function, vector< unordered_set< string > > &lambda_params)

Static Public Member Functions

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.

Public Attributes

LogicalType target_type
optional_ptr< DummyBinding > macro_binding
optional_ptr< vector< DummyBinding > > lambda_bindings

Protected Member Functions

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 UnsupportedAggregateMessage ()
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

Binder & binder
ClientContext & context
optional_ptr< ExpressionBinder > stored_binder
vector< BoundColumnReferenceInfo > bound_columns

Private Member Functions

void InitializeStackCheck ()
StackChecker< ExpressionBinder > StackCheck (const ParsedExpression &expr, idx_t extra_stack=1)

Private Attributes

idx_t stack_depth = DConstants::INVALID_INDEX
 Current stack depth.

Friends

class StackChecker< ExpressionBinder >

Constructor & Destructor Documentation

◆ ExpressionBinder()

duckdb::ExpressionBinder::ExpressionBinder ( Binder & binder,
ClientContext & context,
bool replace_binder = false )
378802 : binder(binder), context(context) {
378803 InitializeStackCheck();
378804 if (replace_binder) {
378805 stored_binder = &binder.GetActiveBinder();
378806 binder.SetActiveBinder(*this);
378807 } else {
378808 binder.PushExpressionBinder(*this);
378809 }
378810}

◆ ~ExpressionBinder()

duckdb::ExpressionBinder::~ExpressionBinder ( )
virtual
378812 {
378813 if (binder.HasActiveBinder()) {
378814 if (stored_binder) {
378815 binder.SetActiveBinder(*stored_binder);
378816 } else {
378817 binder.PopExpressionBinder();
378818 }
378819 }
378820}

Member Function Documentation

◆ TryResolveAliasReference()

virtual bool duckdb::ExpressionBinder::TryResolveAliasReference ( ColumnRefExpression & colref,
idx_t depth,
bool root_expression,
BindResult & result,
unique_ptr< ParsedExpression > & expr_ptr )
inlinevirtual
1092 {
1093 return false;
1094 }

◆ DoesColumnAliasExist()

virtual bool duckdb::ExpressionBinder::DoesColumnAliasExist ( const ColumnRefExpression & colref)
inlinevirtual
1096 {
1097 return false;
1098 }

◆ IsPotentialAlias()

bool duckdb::ExpressionBinder::IsPotentialAlias ( const ColumnRefExpression & colref)
static
379196 {
379197 // traditional alias (unqualified), or qualified with table name "alias"
379198 if (!colref.IsQualified()) {
379199 return true;
379200 }
379201 if (colref.column_names.size() == 2) {
379202 return StringUtil::CIEquals(colref.GetTableName(), "alias");
379203 }
379204 return false;
379205}
static DUCKDB_API bool CIEquals(const string &l1, const string &l2)
Case insensitive equals.
Definition duckdb.cpp:109696

◆ Bind() [1/2]

unique_ptr< Expression > duckdb::ExpressionBinder::Bind ( unique_ptr< ParsedExpression > & expr,
optional_ptr< LogicalType > result_type = nullptr,
bool root_expression = true )
379104 {
379105 // bind the main expression
379106 auto error_msg = Bind(expr, 0, root_expression);
379107 if (error_msg.HasError()) {
379108 // Try binding the correlated column. If binding the correlated column
379109 // has error messages, those should be propagated up. So for the test case
379110 // having subquery failed to bind:14 the real error message should be something like
379111 // aggregate with constant input must be bound to a root node.
379112 auto result = BindCorrelatedColumns(expr, error_msg);
379113 if (result.HasError()) {
379114 CombineErrors(error_msg, std::move(result.error));
379115 error_msg.Throw();
379116 }
379117 auto &bound_expr = expr->Cast<BoundExpression>();
379118 ExtractCorrelatedExpressions(binder, *bound_expr.expr);
379119 }
379120 auto &bound_expr = expr->Cast<BoundExpression>();
379121 unique_ptr<Expression> result = std::move(bound_expr.expr);
379122 if (target_type.id() != LogicalTypeId::INVALID) {
379123 // the binder has a specific target type: add a cast to that type
379124 result = BoundCastExpression::AddCastToType(context, std::move(result), target_type);
379125 } else {
379126 if (!binder.can_contain_nulls) {
379127 // SQL NULL type is only used internally in the binder
379128 // cast to INTEGER if we encounter it outside of the binder
379129 if (ContainsNullType(result->return_type)) {
379130 auto exchanged_type = ExchangeNullType(result->return_type);
379131 result = BoundCastExpression::AddCastToType(context, std::move(result), exchanged_type);
379132 }
379133 }
379134 if (result->return_type.id() == LogicalTypeId::UNKNOWN) {
379135 throw ParameterNotResolvedException();
379136 }
379137 }
379138 if (result_type) {
379139 *result_type = result->return_type;
379140 }
379141 return result;
379142}
static DUCKDB_API unique_ptr< Expression > AddCastToType(ClientContext &context, unique_ptr< Expression > expr, const LogicalType &target_type, bool try_cast=false)
Cast an expression to the specified SQL type if required.
Definition duckdb.cpp:375869
LogicalType target_type
Definition duckdb.cpp:1105

◆ HasBoundColumns()

bool duckdb::ExpressionBinder::HasBoundColumns ( )
inline

Returns whether or not any columns have been bound by the expression binder.

1115 {
1116 return !bound_columns.empty();
1117 }

◆ GetBoundColumns()

const vector< BoundColumnReferenceInfo > & duckdb::ExpressionBinder::GetBoundColumns ( )
inline
1118 {
1119 return bound_columns;
1120 }

◆ SetCatalogLookupCallback()

void duckdb::ExpressionBinder::SetCatalogLookupCallback ( catalog_entry_callback_t callback)
378797 {
378798 binder.SetCatalogLookupCallback(std::move(callback));
378799}

◆ Bind() [2/2]

ErrorData duckdb::ExpressionBinder::Bind ( unique_ptr< ParsedExpression > & expr,
idx_t depth,
bool root_expression = false )
379144 {
379145 // bind the node, but only if it has not been bound yet
379146 auto query_location = expr->GetQueryLocation();
379147 auto &expression = *expr;
379148 auto alias = expression.GetAlias();
379149 if (expression.GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION) {
379150 // already bound, don't bind it again
379151 return ErrorData();
379152 }
379153 if (expression.GetExpressionClass() == ExpressionClass::WINDOW) {
379154 auto &w = expression.Cast<WindowExpression>();
379155 if (w.HasBoundedParts()) {
379156 BindResult result =
379157 BindResult(BinderException::Unsupported(*expr, "window expression is not supported here"));
379158 if (result.HasError()) {
379159 return std::move(result.error);
379160 }
379161 }
379162 }
379163 // bind the expression
379164 BindResult result = BindExpression(expr, depth, root_expression);
379165 if (result.HasError()) {
379166 return std::move(result.error);
379167 }
379168 // successfully bound: replace the node with a BoundExpression
379169 result.expression->SetQueryLocation(query_location);
379170 expr = make_uniq<BoundExpression>(std::move(result.expression));
379171 auto &be = expr->Cast<BoundExpression>();
379172 be.SetAlias(alias);
379173 if (!alias.empty()) {
379174 be.expr->SetAlias(alias);
379175 }
379176 return ErrorData();
379177}
virtual BindResult BindExpression(unique_ptr< ParsedExpression > &expr_ptr, idx_t depth, bool root_expression=false)
Definition duckdb.cpp:378842

◆ CreateStructExtract()

unique_ptr< ParsedExpression > duckdb::ExpressionBinder::CreateStructExtract ( unique_ptr< ParsedExpression > base,
const string & field_name )

Returns the STRUCT_EXTRACT operator expression.

360233 {
360234 vector<unique_ptr<ParsedExpression>> children;
360235 children.push_back(std::move(base));
360236 children.push_back(make_uniq_base<ParsedExpression, ConstantExpression>(Value(field_name)));
360237 auto extract_fun = make_uniq<OperatorExpression>(ExpressionType::STRUCT_EXTRACT, std::move(children));
360238 return std::move(extract_fun);
360239}
Here is the caller graph for this function:

◆ CreateStructPack()

unique_ptr< ParsedExpression > duckdb::ExpressionBinder::CreateStructPack ( ColumnRefExpression & col_ref)

Returns a STRUCT_PACK function expression.

360241 {
360242 if (col_ref.column_names.size() > 3) {
360243 return nullptr;
360244 }
360245 D_ASSERT(!col_ref.column_names.empty());
360246
360247 // get a matching binding
360248 ErrorData error;
360249 optional_ptr<Binding> binding;
360250 switch (col_ref.column_names.size()) {
360251 case 1: {
360252 // single entry - this must be the table name
360253 BindingAlias alias(col_ref.column_names[0]);
360254 binding = binder.bind_context.GetBinding(alias, error);
360255 break;
360256 }
360257 case 2: {
360258 // two entries - this can either be "catalog.table" or "schema.table" - try both
360259 BindingAlias alias(col_ref.column_names[0], col_ref.column_names[1]);
360260 binding = binder.bind_context.GetBinding(alias, error);
360261 if (!binding) {
360262 alias = BindingAlias(col_ref.column_names[0], INVALID_SCHEMA, col_ref.column_names[1]);
360263 binding = binder.bind_context.GetBinding(alias, error);
360264 }
360265 break;
360266 }
360267 case 3: {
360268 // three entries - this must be "catalog.schema.table"
360269 BindingAlias alias(col_ref.column_names[0], col_ref.column_names[1], col_ref.column_names[2]);
360270 binding = binder.bind_context.GetBinding(alias, error);
360271 break;
360272 }
360273 default:
360274 throw InternalException("Expected 1, 2 or 3 column names for CreateStructPack");
360275 }
360276 if (!binding) {
360277 return nullptr;
360278 }
360279
360280 // We found the table, now create the struct_pack expression
360281 auto &column_names = binding->GetColumnNames();
360282 vector<unique_ptr<ParsedExpression>> child_expressions;
360283 child_expressions.reserve(column_names.size());
360284 for (const auto &column_name : column_names) {
360285 child_expressions.push_back(binder.bind_context.CreateColumnReference(
360286 binding->GetBindingAlias(), column_name, ColumnBindType::DO_NOT_EXPAND_GENERATED_COLUMNS));
360287 }
360288 return make_uniq<FunctionExpression>("struct_pack", std::move(child_expressions));
360289}
Here is the caller graph for this function:

◆ BindQualifiedColumnName()

BindResult duckdb::ExpressionBinder::BindQualifiedColumnName ( ColumnRefExpression & colref,
const string & table_name )
377481 {
377482 idx_t struct_start = 0;
377483 if (colref.column_names[0] == table_name) {
377484 struct_start++;
377485 }
377486 auto result = make_uniq_base<ParsedExpression, ColumnRefExpression>(colref.column_names.back());
377487 for (idx_t i = struct_start; i + 1 < colref.column_names.size(); i++) {
377488 result = CreateStructExtract(std::move(result), colref.column_names[i]);
377489 }
377490 return BindExpression(result, 0);
377491}
unique_ptr< ParsedExpression > CreateStructExtract(unique_ptr< ParsedExpression > base, const string &field_name)
Returns the STRUCT_EXTRACT operator expression.
Definition duckdb.cpp:360232
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ QualifyColumnName() [1/2]

unique_ptr< ParsedExpression > duckdb::ExpressionBinder::QualifyColumnName ( const ParsedExpression & expr,
const string & column_name,
ErrorData & error )

Returns a qualified column reference from a column name.

360062 {
360063 auto using_binding = binder.bind_context.GetUsingBinding(column_name);
360064 if (using_binding) {
360065 // we are referencing a USING column
360066 // check if we can refer to one of the base columns directly
360067 unique_ptr<Expression> expression;
360068 if (using_binding->primary_binding.IsSet()) {
360069 // we can! just assign the table name and re-bind
360070 return binder.bind_context.CreateColumnReference(using_binding->primary_binding, column_name);
360071 } else {
360072 // we cannot! we need to bind this as COALESCE between all the relevant columns
360073 auto coalesce = make_uniq<OperatorExpression>(ExpressionType::OPERATOR_COALESCE);
360074 coalesce->children.reserve(using_binding->bindings.size());
360075 for (auto &entry : using_binding->bindings) {
360076 coalesce->children.push_back(make_uniq<ColumnRefExpression>(column_name, entry));
360077 }
360078 return std::move(coalesce);
360079 }
360080 }
360081
360082 // try binding as a lambda parameter
360083 auto lambda_ref = LambdaRefExpression::FindMatchingBinding(lambda_bindings, column_name);
360084 if (lambda_ref) {
360085 return lambda_ref;
360086 }
360087
360088 // find a table binding that contains this column name
360089 auto table_binding = binder.bind_context.GetMatchingBinding(column_name, expr);
360090
360091 // throw an error if a macro parameter name conflicts with a column name
360092 auto is_macro_column = false;
360093 if (binder.macro_binding && binder.macro_binding->HasMatchingBinding(column_name)) {
360094 is_macro_column = true;
360095 if (table_binding) {
360096 throw BinderException(expr, "Conflicting column names for column " + column_name + "!");
360097 }
360098 }
360099
360100 // bind as a macro column
360101 if (is_macro_column) {
360102 return binder.bind_context.CreateColumnReference(binder.macro_binding->GetBindingAlias(), column_name);
360103 }
360104
360105 // bind as a regular column
360106 if (table_binding) {
360107 return binder.bind_context.CreateColumnReference(table_binding->GetBindingAlias(), column_name);
360108 }
360109
360110 // it's not, find candidates and error
360111 auto similar_bindings = binder.bind_context.GetSimilarBindings(column_name);
360112 error = ErrorData(BinderException::ColumnNotFound(column_name, similar_bindings));
360113 return nullptr;
360114}
static unique_ptr< ParsedExpression > FindMatchingBinding(optional_ptr< vector< DummyBinding > > &lambda_bindings, const string &parameter_name)
Traverses the lambda_bindings to find a matching binding for the column_name.
Definition duckdb.cpp:337039
Here is the call graph for this function:
Here is the caller graph for this function:

◆ QualifyColumnNameWithManyDots()

unique_ptr< ParsedExpression > duckdb::ExpressionBinder::QualifyColumnNameWithManyDots ( ColumnRefExpression & col_ref,
ErrorData & error )

Returns a qualified column reference from a column reference with column_names.size() > 2.

360438 {
360439 idx_t struct_extract_start = col_ref.column_names.size();
360440 auto result_expr = QualifyColumnNameWithManyDotsInternal(col_ref, error, struct_extract_start);
360441 if (!result_expr) {
360442 return nullptr;
360443 }
360444
360445 // create a struct extract with all remaining column names
360446 for (idx_t i = struct_extract_start; i < col_ref.column_names.size(); i++) {
360447 result_expr = CreateStructExtract(std::move(result_expr), col_ref.column_names[i]);
360448 }
360449
360450 return result_expr;
360451}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ QualifyColumnName() [2/2]

unique_ptr< ParsedExpression > duckdb::ExpressionBinder::QualifyColumnName ( ColumnRefExpression & col_ref,
ErrorData & error )
virtual

Returns a qualified column reference from a column reference.

Reimplemented in duckdb::HavingBinder.

360453 {
360454 if (!col_ref.IsQualified()) {
360455 // Try binding as a lambda parameter.
360456 auto lambda_ref = LambdaRefExpression::FindMatchingBinding(lambda_bindings, col_ref.GetColumnName());
360457 if (lambda_ref) {
360458 return lambda_ref;
360459 }
360460 }
360461
360462 idx_t column_parts = col_ref.column_names.size();
360463
360464 // column names can have an arbitrary amount of dots
360465 // here is how the resolution works:
360466 if (column_parts == 1) {
360467 // no dots (i.e. "part1")
360468 // -> part1 refers to a column
360469 // check if we can qualify the column name with the table name
360470 auto qualified_col_ref = QualifyColumnName(col_ref, col_ref.GetColumnName(), error);
360471 if (qualified_col_ref) {
360472 // we could: return it
360473 return qualified_col_ref;
360474 }
360475 // we could not! Try creating an implicit struct_pack
360476 return CreateStructPack(col_ref);
360477 }
360478
360479 if (column_parts == 2) {
360480 // one dot (i.e. "part1.part2")
360481 // EITHER:
360482 // -> part1 is a table, part2 is a column
360483 // -> part1 is a column, part2 is a property of that column (i.e. struct_extract)
360484
360485 // first check if part1 is a table, and part2 is a standard column name
360486 auto binding = binder.GetMatchingBinding(col_ref.column_names[0], col_ref.column_names[1], error);
360487 if (binding) {
360488 // it is! return the column reference directly
360489 return binder.bind_context.CreateColumnReference(binding->GetBindingAlias(), col_ref.GetColumnName());
360490 }
360491
360492 // otherwise check if we can turn this into a struct extract
360493 ErrorData other_error;
360494 auto qualified_col_ref = QualifyColumnName(col_ref, col_ref.column_names[0], other_error);
360495 if (qualified_col_ref) {
360496 // we could: create a struct extract
360497 return CreateStructExtract(std::move(qualified_col_ref), col_ref.column_names[1]);
360498 }
360499 // we could not! Try creating an implicit struct_pack
360500 return CreateStructPack(col_ref);
360501 }
360502
360503 // three or more dots
360504 return QualifyColumnNameWithManyDots(col_ref, error);
360505}
unique_ptr< ParsedExpression > CreateStructPack(ColumnRefExpression &col_ref)
Returns a STRUCT_PACK function expression.
Definition duckdb.cpp:360241
unique_ptr< ParsedExpression > QualifyColumnNameWithManyDots(ColumnRefExpression &col_ref, ErrorData &error)
Returns a qualified column reference from a column reference with column_names.size() > 2.
Definition duckdb.cpp:360437
unique_ptr< ParsedExpression > QualifyColumnName(const ParsedExpression &expr, const string &column_name, ErrorData &error)
Returns a qualified column reference from a column name.
Definition duckdb.cpp:360061
Here is the call graph for this function:

◆ QualifyColumnNamesInLambda()

void duckdb::ExpressionBinder::QualifyColumnNamesInLambda ( FunctionExpression & function,
vector< unordered_set< string > > & lambda_params )

Enables special-handling of lambda parameters by tracking them in the lambda_params vector.

360183 {
360184 for (auto &child : function.children) {
360185 if (child->GetExpressionClass() != ExpressionClass::LAMBDA) {
360186 // not a lambda expression
360187 QualifyColumnNames(child, lambda_params, true);
360188 continue;
360189 }
360190
360191 // special-handling for LHS lambda parameters
360192 // we do not qualify them, and we add them to the lambda_params vector
360193 auto &lambda_expr = child->Cast<LambdaExpression>();
360194 string error_message;
360195 auto column_ref_expressions = lambda_expr.ExtractColumnRefExpressions(error_message);
360196
360197 if (!error_message.empty()) {
360198 // possibly a JSON function, qualify both LHS and RHS
360199 QualifyColumnNames(lambda_expr.lhs, lambda_params, true);
360200 QualifyColumnNames(lambda_expr.expr, lambda_params, true);
360201 continue;
360202 }
360203
360204 // push this level
360205 lambda_params.emplace_back();
360206
360207 // push the lambda parameter names
360208 for (const auto &column_ref_expr : column_ref_expressions) {
360209 const auto &column_ref = column_ref_expr.get().Cast<ColumnRefExpression>();
360210 lambda_params.back().emplace(column_ref.GetName());
360211 }
360212
360213 // only qualify in RHS
360214 QualifyColumnNames(lambda_expr.expr, lambda_params, true);
360215
360216 // pop this level
360217 lambda_params.pop_back();
360218 }
360219}
void QualifyColumnNames(unique_ptr< ParsedExpression > &expr, vector< unordered_set< string > > &lambda_params, const bool within_function_expression=false)
Definition duckdb.cpp:360116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ QualifyColumnNames() [1/3]

void duckdb::ExpressionBinder::QualifyColumnNames ( unique_ptr< ParsedExpression > & expr,
vector< unordered_set< string > > & lambda_params,
const bool within_function_expression = false )

Recursively qualifies the column references in the (children) of the expression. Passes on the within_function_expression state from outer expressions, or sets it

360118 {
360119 bool next_within_function_expression = false;
360120 switch (expr->GetExpressionType()) {
360121 case ExpressionType::COLUMN_REF: {
360122 auto &col_ref = expr->Cast<ColumnRefExpression>();
360123
360124 // don't qualify lambda parameters
360125 if (LambdaExpression::IsLambdaParameter(lambda_params, col_ref.GetName())) {
360126 return;
360127 }
360128
360129 ErrorData error;
360130 auto new_expr = QualifyColumnName(col_ref, error);
360131
360132 if (new_expr) {
360133 if (!expr->GetAlias().empty()) {
360134 // Pre-existing aliases are added to the qualified column reference
360135 new_expr->SetAlias(expr->GetAlias());
360136 } else if (within_function_expression) {
360137 // Qualifying the column reference may add an alias, but this needs to be removed within function
360138 // expressions, because the alias here means a named parameter instead of a positional parameter
360139 new_expr->ClearAlias();
360140 }
360141
360142 // replace the expression with the qualified column reference
360143 new_expr->SetQueryLocation(col_ref.GetQueryLocation());
360144 expr = std::move(new_expr);
360145 }
360146 return;
360147 }
360148 case ExpressionType::POSITIONAL_REFERENCE: {
360149 auto &ref = expr->Cast<PositionalReferenceExpression>();
360150 if (ref.GetAlias().empty()) {
360151 string table_name, column_name;
360152 auto error = binder.bind_context.BindColumn(ref, table_name, column_name);
360153 if (error.empty()) {
360154 ref.SetAlias(column_name);
360155 }
360156 }
360157 break;
360158 }
360159 case ExpressionType::FUNCTION: {
360160 // Special-handling for lambdas, which are inside function expressions.
360161 auto &function = expr->Cast<FunctionExpression>();
360162 if (!IsUnnestFunction(function.function_name)) {
360163 BindAndQualifyFunction(function, false);
360164 }
360165 if (function.IsLambdaFunction()) {
360166 return QualifyColumnNamesInLambda(function, lambda_params);
360167 }
360168
360169 next_within_function_expression = true;
360170 break;
360171 }
360172 default: // fall through
360173 break;
360174 }
360175
360176 // recurse on the child expressions
360177 ParsedExpressionIterator::EnumerateChildren(*expr, [&](unique_ptr<ParsedExpression> &child) {
360178 QualifyColumnNames(child, lambda_params, next_within_function_expression);
360179 });
360180}
static bool IsUnnestFunction(const string &function_name)
Returns true if the function name is an alias for the UNNEST function.
Definition duckdb.cpp:379192
void QualifyColumnNamesInLambda(FunctionExpression &function, vector< unordered_set< string > > &lambda_params)
Enables special-handling of lambda parameters by tracking them in the lambda_params vector.
Definition duckdb.cpp:360182
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.
Definition duckdb.cpp:336951
Here is the call graph for this function:
Here is the caller graph for this function:

◆ QualifyColumnNames() [2/3]

void duckdb::ExpressionBinder::QualifyColumnNames ( Binder & binder,
unique_ptr< ParsedExpression > & expr )
static

Entry point for qualifying the column references of the expression.

360221 {
360222 WhereBinder where_binder(binder, binder.context);
360223 vector<unordered_set<string>> lambda_params;
360224 where_binder.QualifyColumnNames(expr, lambda_params);
360225}
Here is the call graph for this function:

◆ QualifyColumnNames() [3/3]

void duckdb::ExpressionBinder::QualifyColumnNames ( ExpressionBinder & binder,
unique_ptr< ParsedExpression > & expr )
static
360227 {
360228 vector<unordered_set<string>> lambda_params;
360229 expression_binder.QualifyColumnNames(expr, lambda_params);
360230}

◆ PushCollation()

bool duckdb::ExpressionBinder::PushCollation ( ClientContext & context,
unique_ptr< Expression > & source,
const LogicalType & sql_type,
CollationType type = CollationType::ALL_COLLATIONS )
static
360599 {
360600 auto &collation_binding = CollationBinding::Get(context);
360601 return collation_binding.PushCollation(context, source, sql_type, type);
360602}

◆ TestCollation()

void duckdb::ExpressionBinder::TestCollation ( ClientContext & context,
const string & collation )
static
360604 {
360605 auto expr = make_uniq_base<Expression, BoundConstantExpression>(Value(""));
360606 PushCollation(context, expr, LogicalType::VARCHAR_COLLATION(collation));
360607}

◆ BindCorrelatedColumns()

BindResult duckdb::ExpressionBinder::BindCorrelatedColumns ( unique_ptr< ParsedExpression > & expr,
ErrorData error_message )
378985 {
378986 // try to bind in one of the outer queries, if the binding error occurred in a subquery
378987 auto &active_binders = binder.GetActiveBinders();
378988 // make a copy of the set of binders, so we can restore it later
378989 auto binders = active_binders;
378990 auto bind_error = std::move(error_message);
378991 // we already failed with the current binder
378992 active_binders.pop_back();
378993 idx_t depth = 1;
378994 while (!active_binders.empty()) {
378995 auto &next_binder = active_binders.back().get();
378996 ExpressionBinder::QualifyColumnNames(next_binder.binder, expr);
378997 auto next_error = next_binder.Bind(expr, depth);
378998 if (!next_error.HasError()) {
378999 bind_error = std::move(next_error);
379000 break;
379001 }
379002 CombineErrors(bind_error, std::move(next_error));
379003 depth++;
379004 active_binders.pop_back();
379005 }
379006 active_binders = binders;
379007 return BindResult(bind_error);
379008}
double depth(InputArray R, InputArray t, InputArray X)

◆ BindChild()

void duckdb::ExpressionBinder::BindChild ( unique_ptr< ParsedExpression > & expr,
idx_t depth,
ErrorData & error )
379010 {
379011 if (expr) {
379012 ErrorData bind_error = Bind(expr, depth);
379013 if (!error.HasError()) {
379014 error = std::move(bind_error);
379015 }
379016 }
379017}

◆ ExtractCorrelatedExpressions()

void duckdb::ExpressionBinder::ExtractCorrelatedExpressions ( Binder & binder,
Expression & expr )
static
379019 {
379020 if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) {
379021 auto &bound_colref = expr.Cast<BoundColumnRefExpression>();
379022 if (bound_colref.depth > 0) {
379023 binder.AddCorrelatedColumn(CorrelatedColumnInfo(bound_colref));
379024 }
379025 }
379026 ExpressionIterator::EnumerateChildren(expr,
379027 [&](Expression &child) { ExtractCorrelatedExpressions(binder, child); });
379028}

◆ ContainsNullType()

bool duckdb::ExpressionBinder::ContainsNullType ( const LogicalType & type)
static
379095 {
379096 return ContainsType(type, LogicalTypeId::SQLNULL);
379097}

◆ ExchangeNullType()

LogicalType duckdb::ExpressionBinder::ExchangeNullType ( const LogicalType & type)
static
379099 {
379100 return ExchangeType(type, LogicalTypeId::SQLNULL, LogicalType::INTEGER);
379101}

◆ ContainsType()

bool duckdb::ExpressionBinder::ContainsType ( const LogicalType & type,
LogicalTypeId target )
static
379030 {
379031 if (type.id() == target) {
379032 return true;
379033 }
379034 switch (type.id()) {
379035 case LogicalTypeId::STRUCT: {
379036 auto child_count = StructType::GetChildCount(type);
379037 for (idx_t i = 0; i < child_count; i++) {
379038 if (ContainsType(StructType::GetChildType(type, i), target)) {
379039 return true;
379040 }
379041 }
379042 return false;
379043 }
379044 case LogicalTypeId::UNION: {
379045 auto member_count = UnionType::GetMemberCount(type);
379046 for (idx_t i = 0; i < member_count; i++) {
379047 if (ContainsType(UnionType::GetMemberType(type, i), target)) {
379048 return true;
379049 }
379050 }
379051 return false;
379052 }
379053 case LogicalTypeId::LIST:
379054 case LogicalTypeId::MAP:
379055 return ContainsType(ListType::GetChildType(type), target);
379056 case LogicalTypeId::ARRAY:
379057 return ContainsType(ArrayType::GetChildType(type), target);
379058 default:
379059 return false;
379060 }
379061}

◆ ExchangeType()

LogicalType duckdb::ExpressionBinder::ExchangeType ( const LogicalType & type,
LogicalTypeId target,
LogicalType new_type )
static
379063 {
379064 if (type.id() == target) {
379065 return new_type;
379066 }
379067 switch (type.id()) {
379068 case LogicalTypeId::STRUCT: {
379069 // we make a copy of the child types of the struct here
379070 auto child_types = StructType::GetChildTypes(type);
379071 for (auto &child_type : child_types) {
379072 child_type.second = ExchangeType(child_type.second, target, new_type);
379073 }
379074 return LogicalType::STRUCT(child_types);
379075 }
379076 case LogicalTypeId::UNION: {
379077 auto member_types = UnionType::CopyMemberTypes(type);
379078 for (auto &member_type : member_types) {
379079 member_type.second = ExchangeType(member_type.second, target, new_type);
379080 }
379081 return LogicalType::UNION(std::move(member_types));
379082 }
379083 case LogicalTypeId::LIST:
379084 return LogicalType::LIST(ExchangeType(ListType::GetChildType(type), target, new_type));
379085 case LogicalTypeId::MAP:
379086 return LogicalType::MAP(ExchangeType(ListType::GetChildType(type), target, new_type));
379087 case LogicalTypeId::ARRAY:
379088 return LogicalType::ARRAY(ExchangeType(ArrayType::GetChildType(type), target, new_type),
379089 ArrayType::GetSize(type));
379090 default:
379091 return type;
379092 }
379093}

◆ BindExpression() [1/16]

BindResult duckdb::ExpressionBinder::BindExpression ( unique_ptr< ParsedExpression > & expr_ptr,
idx_t depth,
bool root_expression = false )
virtual

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 in duckdb::AggregateBinder, duckdb::AlterBinder, duckdb::BaseSelectBinder, duckdb::CheckBinder, duckdb::ConstantBinder, duckdb::GroupBinder, duckdb::IndexBinder, duckdb::InsertBinder, duckdb::LateralBinder, duckdb::ProjectionBinder, duckdb::RelationBinder, duckdb::ReturningBinder, duckdb::TableFunctionBinder, duckdb::UpdateBinder, and duckdb::WhereBinder.

378842 {
378843 auto stack_checker = StackCheck(*expr);
378844
378845 auto &expr_ref = *expr;
378846 switch (expr_ref.GetExpressionClass()) {
378847 case ExpressionClass::BETWEEN:
378848 return BindExpression(expr_ref.Cast<BetweenExpression>(), depth);
378849 case ExpressionClass::CASE:
378850 return BindExpression(expr_ref.Cast<CaseExpression>(), depth);
378851 case ExpressionClass::CAST:
378852 return BindExpression(expr_ref.Cast<CastExpression>(), depth);
378853 case ExpressionClass::COLLATE:
378854 return BindExpression(expr_ref.Cast<CollateExpression>(), depth);
378855 case ExpressionClass::COLUMN_REF:
378856 return BindExpression(expr_ref.Cast<ColumnRefExpression>(), depth, root_expression, expr);
378857 case ExpressionClass::LAMBDA_REF:
378858 return BindExpression(expr_ref.Cast<LambdaRefExpression>(), depth);
378859 case ExpressionClass::COMPARISON:
378860 return BindExpression(expr_ref.Cast<ComparisonExpression>(), depth);
378861 case ExpressionClass::CONJUNCTION:
378862 return BindExpression(expr_ref.Cast<ConjunctionExpression>(), depth);
378863 case ExpressionClass::CONSTANT:
378864 return BindExpression(expr_ref.Cast<ConstantExpression>(), depth);
378865 case ExpressionClass::TYPE:
378866 return BindExpression(expr_ref.Cast<TypeExpression>(), depth);
378867 case ExpressionClass::FUNCTION: {
378868 auto &function = expr_ref.Cast<FunctionExpression>();
378869 if (IsUnnestFunction(function.function_name)) {
378870 // special case, not in catalog
378871 return BindUnnest(function, depth, root_expression);
378872 }
378873 // binding a function expression requires an extra parameter for macros
378874 return BindExpression(function, depth, expr);
378875 }
378876 case ExpressionClass::LAMBDA: {
378877 const vector<LogicalType> function_child_types;
378878 return BindExpression(expr_ref.Cast<LambdaExpression>(), depth, function_child_types, nullptr);
378879 }
378880 case ExpressionClass::OPERATOR:
378881 return BindExpression(expr_ref.Cast<OperatorExpression>(), depth);
378882 case ExpressionClass::SUBQUERY:
378883 return BindExpression(expr_ref.Cast<SubqueryExpression>(), depth);
378884 case ExpressionClass::PARAMETER:
378885 return BindExpression(expr_ref.Cast<ParameterExpression>(), depth);
378886 case ExpressionClass::POSITIONAL_REFERENCE:
378887 return BindPositionalReference(expr, depth, root_expression);
378888 case ExpressionClass::STAR:
378889 return BindResult(BinderException::Unsupported(expr_ref, "STAR expression is not supported here"));
378890 default:
378891 return BindResult(
378892 NotImplementedException("Unimplemented expression class in ExpressionBinder::BindExpression: %s",
378893 EnumUtil::ToString(expr_ref.GetExpressionClass())));
378894 }
378895}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReplaceMacroParameters()

void duckdb::ExpressionBinder::ReplaceMacroParameters ( unique_ptr< ParsedExpression > & expr,
vector< unordered_set< string > > & lambda_params )

FIXME: Generalise this for extensibility. Recursively replaces macro parameters with the provided input parameters.

361481 {
361482 switch (expr->GetExpressionClass()) {
361483 case ExpressionClass::COLUMN_REF: {
361484 // If the expression is a column reference, we replace it with its argument.
361485 auto &col_ref = expr->Cast<ColumnRefExpression>();
361486 if (LambdaExpression::IsLambdaParameter(lambda_params, col_ref.GetName())) {
361487 return;
361488 }
361489
361490 bool bind_macro_parameter = false;
361491 if (col_ref.IsQualified()) {
361492 if (col_ref.GetTableName().find(DummyBinding::DUMMY_NAME) != string::npos) {
361493 bind_macro_parameter = true;
361494 }
361495 } else {
361496 bind_macro_parameter = macro_binding->HasMatchingBinding(col_ref.GetColumnName());
361497 }
361498
361499 if (bind_macro_parameter) {
361500 D_ASSERT(macro_binding->HasMatchingBinding(col_ref.GetColumnName()));
361501 expr = macro_binding->ParamToArg(col_ref);
361502 }
361503 return;
361504 }
361505 case ExpressionClass::FUNCTION: {
361506 // Special-handling for lambdas, which are inside function expressions.
361507 auto &function = expr->Cast<FunctionExpression>();
361508 if (function.IsLambdaFunction()) {
361509 return ReplaceMacroParametersInLambda(function, lambda_params);
361510 }
361511 break;
361512 }
361513 case ExpressionClass::SUBQUERY: {
361514 auto &sq = (expr->Cast<SubqueryExpression>()).subquery;
361515 ParsedExpressionIterator::EnumerateQueryNodeChildren(
361516 *sq->node, [&](unique_ptr<ParsedExpression> &child) { ReplaceMacroParameters(child, lambda_params); });
361517 break;
361518 }
361519 default:
361520 break;
361521 }
361522
361523 ParsedExpressionIterator::EnumerateChildren(
361524 *expr, [&](unique_ptr<ParsedExpression> &child) { ReplaceMacroParameters(child, lambda_params); });
361525}
void ReplaceMacroParameters(unique_ptr< ParsedExpression > &expr, vector< unordered_set< string > > &lambda_params)
Definition duckdb.cpp:361480
void ReplaceMacroParametersInLambda(FunctionExpression &function, vector< unordered_set< string > > &lambda_params)
Definition duckdb.cpp:361445
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReplaceMacroParametersInLambda()

void duckdb::ExpressionBinder::ReplaceMacroParametersInLambda ( FunctionExpression & function,
vector< unordered_set< string > > & lambda_params )

Enables special-handling of lambda parameters during macro replacement by tracking them in the lambda_params vector.

361446 {
361447 for (auto &child : function.children) {
361448 if (child->GetExpressionClass() != ExpressionClass::LAMBDA) {
361449 ReplaceMacroParameters(child, lambda_params);
361450 continue;
361451 }
361452
361453 // Special-handling for LHS lambda parameters.
361454 // We do not replace them, and we add them to the lambda_params vector.
361455 auto &lambda_expr = child->Cast<LambdaExpression>();
361456 string error_message;
361457 auto column_ref_expressions = lambda_expr.ExtractColumnRefExpressions(error_message);
361458
361459 if (!error_message.empty()) {
361460 // Possibly a JSON function, replace both LHS and RHS.
361461 ReplaceMacroParameters(lambda_expr.lhs, lambda_params);
361462 ReplaceMacroParameters(lambda_expr.expr, lambda_params);
361463 continue;
361464 }
361465
361466 // Push the lambda parameter names of this level.
361467 lambda_params.emplace_back();
361468 for (const auto &column_ref_expr : column_ref_expressions) {
361469 const auto &column_ref = column_ref_expr.get().Cast<ColumnRefExpression>();
361470 lambda_params.back().emplace(column_ref.GetName());
361471 }
361472
361473 // Only replace in the RHS of the expression.
361474 ReplaceMacroParameters(lambda_expr.expr, lambda_params);
361475
361476 lambda_params.pop_back();
361477 }
361478}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetExpressionReturnType()

LogicalType duckdb::ExpressionBinder::GetExpressionReturnType ( const Expression & expr)
static
360722 {
360723 if (expr.GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
360724 if (expr.return_type == LogicalTypeId::VARCHAR && StringType::GetCollation(expr.return_type).empty()) {
360725 return LogicalTypeId::STRING_LITERAL;
360726 }
360727 if (expr.return_type.IsIntegral()) {
360728 auto &constant = expr.Cast<BoundConstantExpression>();
360729 if (!constant.value.IsNull()) {
360730 return LogicalType::INTEGER_LITERAL(constant.value);
360731 }
360732 }
360733 }
360734 return expr.return_type;
360735}
static DUCKDB_API LogicalType INTEGER_LITERAL(const Value &constant)
Integer literal of the specified value.
Definition duckdb.cpp:140922

◆ IsUnnestFunction()

bool duckdb::ExpressionBinder::IsUnnestFunction ( const string & function_name)
static

Returns true if the function name is an alias for the UNNEST function.

379192 {
379193 return function_name == "unnest" || function_name == "unlist";
379194}
Here is the caller graph for this function:

◆ InitializeStackCheck()

void duckdb::ExpressionBinder::InitializeStackCheck ( )
private
378822 {
378823 static constexpr idx_t INITIAL_DEPTH = 5;
378824 if (binder.HasActiveBinder()) {
378825 stack_depth = binder.GetActiveBinder().stack_depth + INITIAL_DEPTH;
378826 } else {
378827 stack_depth = INITIAL_DEPTH;
378828 }
378829}
idx_t stack_depth
Current stack depth.
Definition duckdb.cpp:1182

◆ StackCheck()

StackChecker< ExpressionBinder > duckdb::ExpressionBinder::StackCheck ( const ParsedExpression & expr,
idx_t extra_stack = 1 )
private
378831 {
378833 auto max_expression_depth = Settings::Get<MaxExpressionDepthSetting>(context);
378834 if (stack_depth + extra_stack >= max_expression_depth) {
378835 throw BinderException("Max expression depth limit of %lld exceeded. Use \"SET max_expression_depth TO x\" to "
378836 "increase the maximum expression depth.",
378837 max_expression_depth);
378838 }
378839 return StackChecker<ExpressionBinder>(*this, extra_stack);
378840}
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ BindExpression() [2/16]

BindResult duckdb::ExpressionBinder::BindExpression ( BetweenExpression & expr,
idx_t depth )
protected
359796 {
359797 // first try to bind the children of the case expression
359798 ErrorData error;
359799 BindChild(expr.input, depth, error);
359800 BindChild(expr.lower, depth, error);
359801 BindChild(expr.upper, depth, error);
359802 if (error.HasError()) {
359803 return BindResult(std::move(error));
359804 }
359805 // the children have been successfully resolved
359806 auto &input = BoundExpression::GetExpression(*expr.input);
359807 auto &lower = BoundExpression::GetExpression(*expr.lower);
359808 auto &upper = BoundExpression::GetExpression(*expr.upper);
359809
359810 auto input_sql_type = ExpressionBinder::GetExpressionReturnType(*input);
359811 auto lower_sql_type = ExpressionBinder::GetExpressionReturnType(*lower);
359812 auto upper_sql_type = ExpressionBinder::GetExpressionReturnType(*upper);
359813
359814 // cast the input types to the same type
359815 // now obtain the result type of the input types
359816 LogicalType input_type;
359817 if (!BoundComparisonExpression::TryBindComparison(context, input_sql_type, lower_sql_type, input_type,
359818 expr.GetExpressionType())) {
359819 throw BinderException(expr,
359820 "Cannot mix values of type %s and %s in BETWEEN clause - an explicit cast is required",
359821 input_sql_type.ToString(), lower_sql_type.ToString());
359822 }
359823 if (!BoundComparisonExpression::TryBindComparison(context, input_type, upper_sql_type, input_type,
359824 expr.GetExpressionType())) {
359825 throw BinderException(expr,
359826 "Cannot mix values of type %s and %s in BETWEEN clause - an explicit cast is required",
359827 input_type.ToString(), upper_sql_type.ToString());
359828 }
359829 // add casts (if necessary)
359830 input = BoundCastExpression::AddCastToType(context, std::move(input), input_type);
359831 lower = BoundCastExpression::AddCastToType(context, std::move(lower), input_type);
359832 upper = BoundCastExpression::AddCastToType(context, std::move(upper), input_type);
359833 // handle collation
359834 PushCollation(context, input, input_type);
359835 PushCollation(context, lower, input_type);
359836 PushCollation(context, upper, input_type);
359837
359838 if (!input->IsVolatile() && !input->HasParameter() && !input->HasSubquery()) {
359839 // the expression does not have side effects and can be copied: create two comparisons
359840 // the reason we do this is that individual comparisons are easier to handle in optimizers
359841 // if both comparisons remain they will be folded together again into a single BETWEEN in the optimizer
359842 auto left_compare = make_uniq<BoundComparisonExpression>(ExpressionType::COMPARE_GREATERTHANOREQUALTO,
359843 input->Copy(), std::move(lower));
359844 auto right_compare = make_uniq<BoundComparisonExpression>(ExpressionType::COMPARE_LESSTHANOREQUALTO,
359845 std::move(input), std::move(upper));
359846 return BindResult(make_uniq<BoundConjunctionExpression>(ExpressionType::CONJUNCTION_AND,
359847 std::move(left_compare), std::move(right_compare)));
359848 } else {
359849 // expression has side effects: we cannot duplicate it
359850 // create a bound_between directly
359851 return BindResult(
359852 make_uniq<BoundBetweenExpression>(std::move(input), std::move(lower), std::move(upper), true, true));
359853 }
359854}

◆ BindExpression() [3/16]

BindResult duckdb::ExpressionBinder::BindExpression ( CaseExpression & expr,
idx_t depth )
protected
359865 {
359866 // first try to bind the children of the case expression
359867 ErrorData error;
359868 for (auto &check : expr.case_checks) {
359869 BindChild(check.when_expr, depth, error);
359870 BindChild(check.then_expr, depth, error);
359871 }
359872 BindChild(expr.else_expr, depth, error);
359873 if (error.HasError()) {
359874 return BindResult(std::move(error));
359875 }
359876 // the children have been successfully resolved
359877 // figure out the result type of the CASE expression
359878 auto &else_expr = BoundExpression::GetExpression(*expr.else_expr);
359879 auto return_type = ExpressionBinder::GetExpressionReturnType(*else_expr);
359880 for (auto &check : expr.case_checks) {
359881 auto &then_expr = BoundExpression::GetExpression(*check.then_expr);
359882 auto then_type = ExpressionBinder::GetExpressionReturnType(*then_expr);
359883 if (!LogicalType::TryGetMaxLogicalType(context, return_type, then_type, return_type)) {
359884 throw BinderException(
359885 expr, "Cannot mix values of type %s and %s in CASE expression - an explicit cast is required",
359886 return_type.ToString(), then_type.ToString());
359887 }
359888 }
359889
359890 // bind all the individual components of the CASE statement
359891 auto result = make_uniq<BoundCaseExpression>(return_type);
359892 for (auto &check : expr.case_checks) {
359893 auto &when_expr = BoundExpression::GetExpression(*check.when_expr);
359894 auto &then_expr = BoundExpression::GetExpression(*check.then_expr);
359895 BoundCaseCheck result_check;
359896 result_check.when_expr =
359897 BoundCastExpression::AddCastToType(context, std::move(when_expr), LogicalType::BOOLEAN);
359898 result_check.then_expr = BoundCastExpression::AddCastToType(context, std::move(then_expr), return_type);
359899 result->case_checks.push_back(std::move(result_check));
359900 }
359901 result->else_expr = BoundCastExpression::AddCastToType(context, std::move(else_expr), return_type);
359902 return BindResult(std::move(result));
359903}

◆ BindExpression() [4/16]

BindResult duckdb::ExpressionBinder::BindExpression ( CollateExpression & expr,
idx_t depth )
protected
359944 {
359945 // first try to bind the child of the cast expression
359946 auto error = Bind(expr.child, depth);
359947 if (error.HasError()) {
359948 return BindResult(std::move(error));
359949 }
359950 auto &child = BoundExpression::GetExpression(*expr.child);
359951 if (child->HasParameter()) {
359952 throw ParameterNotResolvedException();
359953 }
359954 if (child->return_type.id() != LogicalTypeId::VARCHAR) {
359955 throw BinderException(child->query_location, "collations are only supported for type varchar");
359956 }
359957 // Validate the collation, but don't use it
359958 auto collation_test = make_uniq_base<Expression, BoundConstantExpression>(Value(child->return_type));
359959 auto collation_type = LogicalType::VARCHAR_COLLATION(expr.collation);
359960 PushCollation(context, collation_test, collation_type);
359961 child->return_type = collation_type;
359962 return BindResult(std::move(child));
359963}

◆ BindExpression() [5/16]

BindResult duckdb::ExpressionBinder::BindExpression ( CastExpression & expr,
idx_t depth )
protected
359913 {
359914 // first try to bind the child of the cast expression
359915 auto error = Bind(expr.child, depth);
359916 if (error.HasError()) {
359917 return BindResult(std::move(error));
359918 }
359919 // FIXME: We can also implement 'hello'::schema.custom_type; and pass by the schema down here.
359920 // Right now just considering its DEFAULT_SCHEMA always
359921 binder.BindLogicalType(expr.cast_type);
359922 // the children have been successfully resolved
359923 auto &child = BoundExpression::GetExpression(*expr.child);
359924 if (expr.try_cast) {
359925 if (ExpressionBinder::GetExpressionReturnType(*child) == expr.cast_type) {
359926 // no cast required: type matches
359927 return BindResult(std::move(child));
359928 }
359929 child = BoundCastExpression::AddCastToType(context, std::move(child), expr.cast_type, true);
359930 } else {
359931 // otherwise add a cast to the target type
359932 child = BoundCastExpression::AddCastToType(context, std::move(child), expr.cast_type);
359933 }
359934 return BindResult(std::move(child));
359935}

◆ BindExpression() [6/16]

BindResult duckdb::ExpressionBinder::BindExpression ( ColumnRefExpression & expr,
idx_t depth,
bool root_expression,
unique_ptr< ParsedExpression > & expr_ptr )
protected
360513 {
360514 if (binder.GetBindingMode() == BindingMode::EXTRACT_NAMES ||
360515 binder.GetBindingMode() == BindingMode::EXTRACT_QUALIFIED_NAMES) {
360516 return BindResult(make_uniq<BoundConstantExpression>(Value(LogicalType::SQLNULL)));
360517 }
360518
360519 ErrorData error;
360520 auto expr = QualifyColumnName(col_ref_p, error);
360521 if (!expr) {
360522 // column wasn't found
360523 if (ExpressionBinder::IsPotentialAlias(col_ref_p)) {
360524 BindResult alias_result;
360525 auto found_alias = TryResolveAliasReference(col_ref_p, depth, root_expression, alias_result, expr_ptr);
360526 if (found_alias) {
360527 return alias_result;
360528 }
360529
360530 auto value_function = GetSQLValueFunction(col_ref_p.GetColumnName());
360531 if (value_function) {
360532 return BindExpression(value_function, depth);
360533 }
360534 }
360535 error.AddQueryLocation(col_ref_p);
360536 return BindResult(std::move(error));
360537 }
360538
360539 expr->SetQueryLocation(col_ref_p.GetQueryLocation());
360540
360541 // the above QualifyColumName returns a generated expression for a generated
360542 // column, and struct_extract for a struct, or a lambda reference expression,
360543 // all of them are not column reference expressions, so we return here
360544 if (expr->GetExpressionType() != ExpressionType::COLUMN_REF) {
360545 auto alias = expr->GetAlias();
360546 auto result = BindExpression(expr, depth);
360547 if (result.expression) {
360548 result.expression->SetAlias(std::move(alias));
360549 }
360550 return result;
360551 }
360552
360553 // the above QualifyColumnName returned an individual column reference
360554 // expression, which we resolve to either a base table or a subquery expression,
360555 // and if it was a macro parameter, then we let macro_binding bind it to the argument
360556 BindResult result;
360557 auto &col_ref = expr->Cast<ColumnRefExpression>();
360558 D_ASSERT(col_ref.IsQualified());
360559 auto &table_name = col_ref.GetTableName();
360560
360561 if (binder.macro_binding && table_name == binder.macro_binding->GetAlias()) {
360562 result = binder.macro_binding->Bind(col_ref, depth);
360563 } else {
360564 result = binder.bind_context.BindColumn(col_ref, depth);
360565 }
360566
360567 if (result.HasError()) {
360568 result.error.AddQueryLocation(col_ref_p);
360569 return result;
360570 }
360571
360572 // we bound the column reference
360573 BoundColumnReferenceInfo ref;
360574 ref.name = col_ref.column_names.back();
360575 ref.query_location = col_ref.GetQueryLocation();
360576 bound_columns.push_back(std::move(ref));
360577 return result;
360578}

◆ BindExpression() [7/16]

BindResult duckdb::ExpressionBinder::BindExpression ( LambdaRefExpression & expr,
idx_t depth )
protected
360507 {
360508 D_ASSERT(lambda_bindings && lambda_ref.lambda_idx < lambda_bindings->size());
360509 return (*lambda_bindings)[lambda_ref.lambda_idx].Bind(lambda_ref, depth);
360510}

◆ BindExpression() [8/16]

BindResult duckdb::ExpressionBinder::BindExpression ( ComparisonExpression & expr,
idx_t depth )
protected
360737 {
360738 // first try to bind the children of the case expression
360739 ErrorData error;
360740 BindChild(expr.left, depth, error);
360741 BindChild(expr.right, depth, error);
360742 if (error.HasError()) {
360743 return BindResult(std::move(error));
360744 }
360745
360746 // the children have been successfully resolved
360747 auto &left = BoundExpression::GetExpression(*expr.left);
360748 auto &right = BoundExpression::GetExpression(*expr.right);
360749 auto left_sql_type = ExpressionBinder::GetExpressionReturnType(*left);
360750 auto right_sql_type = ExpressionBinder::GetExpressionReturnType(*right);
360751 // cast the input types to the same type
360752 // now obtain the result type of the input types
360753 LogicalType input_type;
360754 if (!BoundComparisonExpression::TryBindComparison(context, left_sql_type, right_sql_type, input_type,
360755 expr.GetExpressionType())) {
360756 return BindResult(BinderException(expr,
360757 "Cannot compare values of type %s and type %s - an explicit cast is required",
360758 left_sql_type.ToString(), right_sql_type.ToString()));
360759 }
360760 // add casts (if necessary)
360761 left = BoundCastExpression::AddCastToType(context, std::move(left), input_type,
360762 input_type.id() == LogicalTypeId::ENUM);
360763 right = BoundCastExpression::AddCastToType(context, std::move(right), input_type,
360764 input_type.id() == LogicalTypeId::ENUM);
360765
360766 PushCollation(context, left, input_type);
360767 PushCollation(context, right, input_type);
360768
360769 // now create the bound comparison expression
360770 return BindResult(
360771 make_uniq<BoundComparisonExpression>(expr.GetExpressionType(), std::move(left), std::move(right)));
360772}

◆ BindExpression() [9/16]

BindResult duckdb::ExpressionBinder::BindExpression ( ConjunctionExpression & expr,
idx_t depth )
protected
360782 {
360783 // first try to bind the children of the case expression
360784 ErrorData error;
360785 for (idx_t i = 0; i < expr.children.size(); i++) {
360786 BindChild(expr.children[i], depth, error);
360787 }
360788 if (error.HasError()) {
360789 return BindResult(std::move(error));
360790 }
360791 // the children have been successfully resolved
360792 // cast the input types to boolean (if necessary)
360793 // and construct the bound conjunction expression
360794 auto result = make_uniq<BoundConjunctionExpression>(expr.GetExpressionType());
360795 for (auto &child_expr : expr.children) {
360796 auto &child = BoundExpression::GetExpression(*child_expr);
360797 result->children.push_back(BoundCastExpression::AddCastToType(context, std::move(child), LogicalType::BOOLEAN));
360798 }
360799 // now create the bound conjunction expression
360800 return BindResult(std::move(result));
360801}

◆ BindExpression() [10/16]

BindResult duckdb::ExpressionBinder::BindExpression ( ConstantExpression & expr,
idx_t depth )
protected
360810 {
360811 return BindResult(make_uniq<BoundConstantExpression>(expr.value));
360812}

◆ BindExpression() [11/16]

BindResult duckdb::ExpressionBinder::BindExpression ( FunctionExpression & expr,
idx_t depth,
unique_ptr< ParsedExpression > & expr_ptr )
protected
360959 {
360960 auto func = BindAndQualifyFunction(function, true);
360961
360962 if (func->type != CatalogType::AGGREGATE_FUNCTION_ENTRY &&
360963 (function.distinct || function.filter || !function.order_bys->orders.empty())) {
360964 throw InvalidInputException("Function \"%s\" is a %s. \"DISTINCT\", \"FILTER\", and \"ORDER BY\" are only "
360965 "applicable to aggregate functions.",
360966 function.function_name, CatalogTypeToString(func->type));
360967 }
360968
360969 switch (func->type) {
360970 case CatalogType::SCALAR_FUNCTION_ENTRY: {
360971 auto child = function.IsLambdaFunction();
360972 if (child) {
360973 auto syntax_type = child->Cast<LambdaExpression>().syntax_type;
360974 return TryBindLambdaOrJson(function, depth, *func, syntax_type);
360975 }
360976 return BindFunction(function, func->Cast<ScalarFunctionCatalogEntry>(), depth);
360977 }
360978 case CatalogType::MACRO_ENTRY:
360979 // macro function
360980 return BindMacro(function, func->Cast<ScalarMacroCatalogEntry>(), depth, expr_ptr);
360981 default:
360982 // aggregate function
360983 return BindAggregate(function, func->Cast<AggregateFunctionCatalogEntry>(), depth);
360984 }
360985}

◆ BindExpression() [12/16]

BindResult duckdb::ExpressionBinder::BindExpression ( TypeExpression & expr,
idx_t depth )
protected
362606 {
362607 auto &type_name = type_expr.GetTypeName();
362608 auto type_schema = type_expr.GetSchema();
362609 auto type_catalog = type_expr.GetCatalog();
362610
362611 QueryErrorContext error_context(type_expr);
362612 EntryLookupInfo type_lookup(CatalogType::TYPE_ENTRY, type_name, error_context);
362613
362614 optional_ptr<CatalogEntry> entry = nullptr;
362615
362616 binder.BindSchemaOrCatalog(context, type_catalog, type_schema);
362617
362618 // Required for WAL lookup to work
362619 if (type_catalog.empty() && !DatabaseManager::Get(context).HasDefaultDatabase()) {
362620 // Look in the system catalog if no catalog was specified
362621 entry = binder.entry_retriever.GetEntry(SYSTEM_CATALOG, type_schema, type_lookup);
362622 } else {
362623 // Try to search from most specific to least specific
362624 // The search path should already have been set to the correct catalog/schema,
362625 // in case we are looking for a type in the same schema as a table we are creating
362626
362627 entry = binder.entry_retriever.GetEntry(type_catalog, type_schema, type_lookup, OnEntryNotFound::RETURN_NULL);
362628
362629 if (!IsValidTypeLookup(entry)) {
362630 if (!type_catalog.empty() || !type_schema.empty()) {
362631 entry = binder.entry_retriever.GetEntry(type_catalog, type_schema, type_lookup,
362632 OnEntryNotFound::THROW_EXCEPTION);
362633 }
362634 entry = binder.entry_retriever.GetEntry(type_catalog, INVALID_SCHEMA, type_lookup,
362635 OnEntryNotFound::RETURN_NULL);
362636 }
362637 if (!IsValidTypeLookup(entry)) {
362638 entry = binder.entry_retriever.GetEntry(INVALID_CATALOG, INVALID_SCHEMA, type_lookup,
362639 OnEntryNotFound::RETURN_NULL);
362640 }
362641 if (!IsValidTypeLookup(entry)) {
362642 entry = binder.entry_retriever.GetEntry(SYSTEM_CATALOG, DEFAULT_SCHEMA, type_lookup,
362643 OnEntryNotFound::THROW_EXCEPTION);
362644 }
362645 }
362646
362647 // By this point we have to have found a type in the catalog
362648 D_ASSERT(entry != nullptr);
362649 auto &type_entry = entry->Cast<TypeCatalogEntry>();
362650
362651 // Now handle type parameters
362652 auto &unbound_parameters = type_expr.GetChildren();
362653
362654 if (!type_entry.bind_function) {
362655 if (!unbound_parameters.empty()) {
362656 // This type does not support type parameters
362657 throw BinderException(type_expr, "Type '%s' does not take any type parameters", type_name);
362658 }
362659
362660 // Otherwise, return the user type directly!
362661 auto result_expr = make_uniq<BoundConstantExpression>(Value::TYPE(type_entry.user_type));
362662 result_expr->query_location = type_expr.GetQueryLocation();
362663 return BindResult(std::move(result_expr));
362664 }
362665
362666 // Bind value parameters
362667 vector<TypeArgument> bound_parameters;
362668
362669 for (auto &param : unbound_parameters) {
362670 // Otherwise, try to fold it to a constant value
362671 ConstantBinder binder(this->binder, context, StringUtil::Format("Type parameter for type '%s'", type_name));
362672
362673 auto expr = param->Copy();
362674 auto bound_expr = binder.Bind(expr);
362675
362676 if (!bound_expr->IsFoldable()) {
362677 throw BinderException(type_expr, "Type parameter expression for type '%s' is not a constant", type_name);
362678 }
362679
362680 // Shortcut for constant expressions
362681 if (bound_expr->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
362682 auto &const_expr = bound_expr->Cast<BoundConstantExpression>();
362683 bound_parameters.emplace_back(param->GetAlias(), const_expr.value);
362684 continue;
362685 }
362686
362687 // Otherwise we need to evaluate the expression
362688 auto bound_param = ExpressionExecutor::EvaluateScalar(context, *bound_expr);
362689 bound_parameters.emplace_back(param->GetAlias(), bound_param);
362690 };
362691
362692 // Call the bind function
362693 BindLogicalTypeInput input {context, type_entry.user_type, bound_parameters};
362694 auto result_type = type_entry.bind_function(input);
362695
362696 // Return the resulting type!
362697 auto result_expr = make_uniq<BoundConstantExpression>(Value::TYPE(result_type));
362698 result_expr->query_location = type_expr.GetQueryLocation();
362699 return BindResult(std::move(result_expr));
362700}
static DUCKDB_API Value EvaluateScalar(ClientContext &context, const Expression &expr, bool allow_unfoldable=false)
Evaluate a scalar expression and fold it into a single value.
Definition duckdb.cpp:149993
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002

◆ BindExpression() [13/16]

BindResult duckdb::ExpressionBinder::BindExpression ( LambdaExpression & expr,
idx_t depth,
const vector< LogicalType > & function_child_types,
optional_ptr< bind_lambda_function_t > bind_lambda_function )
protected
361261 {
361262 if (expr.syntax_type == LambdaSyntaxType::LAMBDA_KEYWORD && !bind_lambda_function) {
361263 return BindResult("invalid lambda expression");
361264 }
361265
361266 if (!bind_lambda_function) {
361267 // The PEG parser produces A -> (B ->> C) where the standard parser left-associates to (A -> B) ->> C.
361268 // Restructure to match standard behavior before binding.
361269 if (IsDoubleArrowRHS(*expr.expr)) {
361270 unique_ptr<ParsedExpression> restructured = RestructureArrowChain(expr);
361271 return BindExpression(restructured, depth);
361272 }
361273
361274 // This is not a lambda expression, but the JSON arrow operator.
361275 // Remember the original expression in case of a binding error.
361276 if (!expr.copied_expr) {
361277 expr.copied_expr = expr.expr->Copy();
361278 }
361279 OperatorExpression arrow_expr(ExpressionType::ARROW, std::move(expr.lhs), std::move(expr.expr));
361280 auto bind_result = BindExpression(arrow_expr, depth);
361281
361282 // The arrow_expr now might contain bound nodes.
361283 // Restore the original expression.
361284 if (bind_result.HasError()) {
361285 D_ASSERT(arrow_expr.children.size() == 2);
361286 expr.lhs = std::move(arrow_expr.children[0]);
361287 expr.expr = std::move(arrow_expr.children[1]);
361288 }
361289 return bind_result;
361290 }
361291
361292 // extract and verify lambda parameters to create dummy columns
361293 vector<LogicalType> column_types;
361294 vector<string> column_names;
361295 vector<string> column_aliases;
361296 ExtractParameters(expr, column_names, column_aliases);
361297 for (idx_t i = 0; i < column_names.size(); i++) {
361298 column_types.push_back((*bind_lambda_function)(context, function_child_types, i));
361299 }
361300
361301 // base table alias
361302 auto table_alias = StringUtil::Join(column_aliases, ", ");
361303 if (column_aliases.size() > 1) {
361304 table_alias = "(" + table_alias + ")";
361305 }
361306
361307 // create a lambda binding and push it to the lambda bindings vector
361308 vector<DummyBinding> local_bindings;
361309 if (!lambda_bindings) {
361310 lambda_bindings = &local_bindings;
361311 }
361312 DummyBinding new_lambda_binding(column_types, column_names, table_alias);
361313 lambda_bindings->push_back(new_lambda_binding);
361314
361315 if (expr.copied_expr) {
361316 expr.expr = std::move(expr.copied_expr);
361317 }
361318 auto result = BindExpression(expr.expr, depth, false);
361319 lambda_bindings->pop_back();
361320
361321 // successfully bound a subtree of nested lambdas, set this to nullptr in case other parts of the
361322 // query also contain lambdas
361323 if (lambda_bindings->empty()) {
361324 lambda_bindings = nullptr;
361325 }
361326
361327 if (result.HasError()) {
361328 result.error.Throw();
361329 }
361330
361331 return BindResult(make_uniq<BoundLambdaExpression>(ExpressionType::LAMBDA, LogicalType::LAMBDA,
361332 std::move(result.expression), column_names.size()));
361333}
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

◆ BindExpression() [14/16]

BindResult duckdb::ExpressionBinder::BindExpression ( OperatorExpression & expr,
idx_t depth )
protected

This binder is used to throw when the child expression is of a type that is not allowed.

361708 {
361709 auto operator_type = op.GetExpressionType();
361710 if (operator_type == ExpressionType::GROUPING_FUNCTION) {
361711 return BindGroupingFunction(op, depth);
361712 }
361713
361714 // Bind the children of the operator expression. We already create bound expressions.
361715 // Only those children that trigger an error are not yet bound.
361716 ErrorData error;
361717 if (operator_type == ExpressionType::OPERATOR_TRY) {
361718 D_ASSERT(op.children.size() == 1);
361720 TryOperatorBinder try_operator_binder(binder, context);
361721 try_operator_binder.BindChild(op.children[0], depth, error);
361722 } else {
361723 for (idx_t i = 0; i < op.children.size(); i++) {
361724 BindChild(op.children[i], depth, error);
361725 }
361726 }
361727
361728 if (error.HasError()) {
361729 return BindResult(std::move(error));
361730 }
361731
361732 // all children bound successfully
361733 string function_name;
361734 switch (op.GetExpressionType()) {
361735 case ExpressionType::OPERATOR_UNPACK:
361736 return BindResult("UNPACK not allowed here, should have been resolved earlier");
361737 case ExpressionType::ARRAY_EXTRACT: {
361738 D_ASSERT(op.children[0]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361739 auto &b_exp = BoundExpression::GetExpression(*op.children[0]);
361740 const auto &b_exp_type = b_exp->return_type;
361741 if (b_exp_type.id() == LogicalTypeId::MAP) {
361742 function_name = "map_extract_value";
361743 } else if (b_exp_type.IsJSONType() && op.children.size() == 2) {
361744 function_name = "json_extract";
361745 // Make sure we only extract array elements, not fields, by adding the $[] syntax
361746 auto &i_exp = BoundExpression::GetExpression(*op.children[1]);
361747 if (i_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT &&
361748 !i_exp->Cast<BoundConstantExpression>().value.IsNull()) {
361749 auto &const_exp = i_exp->Cast<BoundConstantExpression>();
361750 if (const_exp.value.TryCastAs(context, LogicalType::UINTEGER)) {
361751 // Array extraction: if the cast fails it's definitely out-of-bounds for a JSON array
361752 auto index = UIntegerValue::Get(const_exp.value);
361753 const_exp.value = StringUtil::Format("$[%lld]", index);
361754 const_exp.return_type = LogicalType::VARCHAR;
361755 } else if (const_exp.return_type.id() == LogicalType::VARCHAR) {
361756 // Field extraction
361757 const_exp.value = StringUtil::Format("$.\"%s\"", const_exp.value.ToString());
361758 const_exp.return_type = LogicalType::VARCHAR;
361759 }
361760 }
361761 } else if (b_exp_type.id() == LogicalTypeId::VARIANT && op.children.size() == 2) {
361762 function_name = "variant_extract";
361763 auto &i_exp = BoundExpression::GetExpression(*op.children[1]);
361764 if (i_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
361765 auto &const_exp = i_exp->Cast<BoundConstantExpression>();
361766 if (!const_exp.value.IsNull() && const_exp.return_type.IsNumeric()) {
361767 const_exp.value = const_exp.value.DefaultCastAs(LogicalType::UINTEGER, true);
361768 const_exp.return_type = LogicalType::UINTEGER;
361769 }
361770 }
361771 } else {
361772 function_name = "array_extract";
361773 }
361774 break;
361775 }
361776 case ExpressionType::ARRAY_SLICE:
361777 function_name = "array_slice";
361778 break;
361779 case ExpressionType::STRUCT_EXTRACT: {
361780 D_ASSERT(op.children.size() == 2);
361781 D_ASSERT(op.children[0]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361782 D_ASSERT(op.children[1]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361783 auto &extract_exp = BoundExpression::GetExpression(*op.children[0]);
361784 if (extract_exp->HasParameter() || extract_exp->return_type.id() == LogicalTypeId::UNKNOWN) {
361785 throw ParameterNotResolvedException();
361786 }
361787 auto &name_exp = BoundExpression::GetExpression(*op.children[1]);
361788 const auto &extract_expr_type = extract_exp->return_type;
361789 if (extract_expr_type.id() != LogicalTypeId::STRUCT && extract_expr_type.id() != LogicalTypeId::UNION &&
361790 extract_expr_type.id() != LogicalTypeId::MAP && extract_expr_type.id() != LogicalTypeId::SQLNULL &&
361791 !extract_expr_type.IsJSONType() && extract_expr_type.id() != LogicalTypeId::VARIANT) {
361792 return BindResult(StringUtil::Format(
361793 "Cannot extract field %s from expression \"%s\" because it is not a struct, union, map, or json",
361794 name_exp->ToString(), extract_exp->ToString()));
361795 }
361796 if (extract_expr_type.id() == LogicalTypeId::UNION) {
361797 function_name = "union_extract";
361798 } else if (extract_expr_type.id() == LogicalTypeId::MAP) {
361799 function_name = "map_extract_value";
361800 } else if (extract_expr_type.id() == LogicalTypeId::VARIANT) {
361801 function_name = "variant_extract";
361802 auto &i_exp = BoundExpression::GetExpression(*op.children[1]);
361803 if (i_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
361804 auto &const_exp = i_exp->Cast<BoundConstantExpression>();
361805 if (!const_exp.value.IsNull()) {
361806 const_exp.value = StringUtil::Format("%s", const_exp.value.ToString());
361807 const_exp.return_type = LogicalType::VARCHAR;
361808 }
361809 }
361810 } else if (extract_expr_type.IsJSONType()) {
361811 function_name = "json_extract";
361812 // Make sure we only extract fields, not array elements, by adding $. syntax
361813 if (name_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
361814 auto &const_exp = name_exp->Cast<BoundConstantExpression>();
361815 if (!const_exp.value.IsNull()) {
361816 const_exp.value = StringUtil::Format("$.\"%s\"", const_exp.value.ToString());
361817 const_exp.return_type = LogicalType::VARCHAR;
361818 }
361819 }
361820 } else {
361821 function_name = "struct_extract";
361822 }
361823 break;
361824 }
361825 case ExpressionType::ARRAY_CONSTRUCTOR:
361826 function_name = "list_value";
361827 break;
361828 case ExpressionType::ARROW:
361829 function_name = "json_extract";
361830 break;
361831 case ExpressionType::OPERATOR_TRY: {
361832 auto &expr = BoundExpression::GetExpression(*op.children[0]);
361833 if (expr->HasSubquery()) {
361834 throw BinderException("TRY can not be used in combination with a scalar subquery");
361835 }
361836 if (expr->IsVolatile()) {
361837 throw BinderException("TRY can not be used in combination with a volatile function");
361838 }
361839 break;
361840 }
361841 default:
361842 break;
361843 }
361844 if (!function_name.empty()) {
361845 auto function = make_uniq_base<ParsedExpression, FunctionExpression>(function_name, std::move(op.children));
361846 return BindExpression(function, depth, false);
361847 }
361848
361849 vector<unique_ptr<Expression>> children;
361850 for (idx_t i = 0; i < op.children.size(); i++) {
361851 D_ASSERT(op.children[i]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361852 children.push_back(std::move(BoundExpression::GetExpression(*op.children[i])));
361853 }
361854 // now resolve the types
361855 LogicalType result_type = ResolveOperatorType(op, children);
361856 if (op.GetExpressionType() == ExpressionType::OPERATOR_COALESCE) {
361857 if (children.empty()) {
361858 throw BinderException("COALESCE needs at least one child");
361859 }
361860 if (children.size() == 1) {
361861 return BindResult(std::move(children[0]));
361862 }
361863 }
361864
361865 auto result = make_uniq<BoundOperatorExpression>(op.GetExpressionType(), result_type);
361866 for (auto &child : children) {
361867 result->children.push_back(std::move(child));
361868 }
361869 return BindResult(std::move(result));
361870}
index
Here is the call graph for this function:

◆ BindExpression() [15/16]

BindResult duckdb::ExpressionBinder::BindExpression ( ParameterExpression & expr,
idx_t depth )
protected
361882 {
361883 auto parameters = binder.GetParameters();
361884 if (!parameters) {
361885 throw BinderException("Unexpected prepared parameter. This type of statement can't be prepared!");
361886 }
361887 auto parameter_id = expr.identifier;
361888
361889 // Check if a parameter value has already been supplied
361890 auto &parameter_data = parameters->GetParameterData();
361891 auto param_data_it = parameter_data.find(parameter_id);
361892 if (param_data_it != parameter_data.end()) {
361893 // it has! emit a constant directly
361894 auto &data = param_data_it->second;
361895 auto return_type = parameters->GetReturnType(parameter_id);
361896 bool is_literal =
361897 return_type.id() == LogicalTypeId::INTEGER_LITERAL || return_type.id() == LogicalTypeId::STRING_LITERAL;
361898 auto constant = make_uniq<BoundConstantExpression>(data.GetValue());
361899 constant->SetAlias(expr.GetAlias());
361900 if (is_literal) {
361901 return BindResult(std::move(constant));
361902 }
361903 auto cast = BoundCastExpression::AddCastToType(context, std::move(constant), return_type);
361904 return BindResult(std::move(cast));
361905 }
361906
361907 auto bound_parameter = parameters->BindParameterExpression(expr);
361908 return BindResult(std::move(bound_parameter));
361909}
Widget2D cast() const

◆ BindExpression() [16/16]

BindResult duckdb::ExpressionBinder::BindExpression ( SubqueryExpression & expr,
idx_t depth )
protected
362478 {
362479 if (expr.subquery->node->type != QueryNodeType::BOUND_SUBQUERY_NODE) {
362480 // first bind the actual subquery in a new binder
362481 auto subquery_binder = Binder::CreateBinder(context, &binder);
362482 subquery_binder->can_contain_nulls = true;
362483 auto bound_node = subquery_binder->BindNode(*expr.subquery->node);
362484 // check the correlated columns of the subquery for correlated columns with depth > 1
362485 for (idx_t i = 0; i < subquery_binder->correlated_columns.size(); i++) {
362486 CorrelatedColumnInfo corr = subquery_binder->correlated_columns[i];
362487 if (corr.depth > 1) {
362488 // depth > 1, the column references the query ABOVE the current one
362489 // add to the set of correlated columns for THIS query
362490 corr.depth -= 1;
362491 binder.AddCorrelatedColumn(corr);
362492 }
362493 }
362494 auto prior_subquery = std::move(expr.subquery);
362495 expr.subquery = make_uniq<SelectStatement>();
362496 expr.subquery->node =
362497 make_uniq<BoundSubqueryNode>(std::move(subquery_binder), std::move(bound_node), std::move(prior_subquery));
362498 }
362499 // now bind the child node of the subquery
362500 if (expr.child) {
362501 // first bind the children of the subquery, if any
362502 auto error = Bind(expr.child, depth);
362503 if (error.HasError()) {
362504 return BindResult(std::move(error));
362505 }
362506 }
362507 auto &bound_subquery = expr.subquery->node->Cast<BoundSubqueryNode>();
362508 vector<unique_ptr<Expression>> child_expressions;
362509 if (expr.subquery_type != SubqueryType::EXISTS) {
362510 idx_t expected_columns = 1;
362511 bool has_unexpanded_struct = false;
362512 if (expr.child) {
362513 auto &child = BoundExpression::GetExpression(*expr.child);
362514 // Check if child is an unexpanded struct before extraction
362515 has_unexpanded_struct = TypeIsUnnamedStruct(child->return_type);
362516 ExtractSubqueryChildren(child, child_expressions, bound_subquery.bound_node.types, expr.comparison_type);
362517 if (child_expressions.empty()) {
362518 child_expressions.push_back(std::move(child));
362519 }
362520 expected_columns = child_expressions.size();
362521 }
362522 // If we have an unexpanded struct (kept intact for ordered comparison),
362523 // the subquery might return multiple columns that need to be combined into a struct
362524 if (has_unexpanded_struct && expected_columns == 1 && bound_subquery.bound_node.types.size() > 1 &&
362525 TypeIsUnnamedStruct(child_expressions[0]->return_type)) {
362526 // The child is a struct with N elements, and the subquery returns N columns
362527 // This is allowed - the subquery columns will be matched against the struct during execution
362528 expected_columns = bound_subquery.bound_node.types.size();
362529 }
362530 if (bound_subquery.bound_node.types.size() != expected_columns) {
362531 throw BinderException(expr, "Subquery returns %zu columns - expected %d",
362532 bound_subquery.bound_node.types.size(), expected_columns);
362533 }
362534 }
362535 // both binding the child and binding the subquery was successful
362536 D_ASSERT(expr.subquery->node->type == QueryNodeType::BOUND_SUBQUERY_NODE);
362537 auto subquery_binder = std::move(bound_subquery.subquery_binder);
362538 auto bound_node = std::move(bound_subquery.bound_node);
362539 LogicalType return_type =
362540 expr.subquery_type == SubqueryType::SCALAR ? bound_node.types[0] : LogicalType(LogicalTypeId::BOOLEAN);
362541 if (return_type.id() == LogicalTypeId::UNKNOWN) {
362542 return_type = LogicalType::SQLNULL;
362543 }
362544
362545 auto result = make_uniq<BoundSubqueryExpression>(return_type);
362546 if (expr.subquery_type == SubqueryType::ANY) {
362547 // ANY comparison
362548 // cast child and subquery child to equivalent types
362549 // Special case: if we have a single struct child and multiple subquery types,
362550 // this means we kept the struct intact for ordered comparison (e.g., (a,b) < ANY(...))
362551 if (child_expressions.size() == 1 && bound_node.types.size() > 1 &&
362552 TypeIsUnnamedStruct(child_expressions[0]->return_type)) {
362553 // Keep the struct as-is for proper lexicographic row comparison
362554 result->children.push_back(std::move(child_expressions[0]));
362555 // Store all the subquery types - they will be used to construct the RHS struct during planning
362556 for (auto &subquery_type : bound_node.types) {
362557 result->child_types.push_back(subquery_type);
362558 result->child_targets.push_back(subquery_type);
362559 }
362560 } else {
362561 // Standard case: either no struct or struct was extracted into separate expressions
362562 for (idx_t child_idx = 0; child_idx < child_expressions.size(); child_idx++) {
362563 auto &child = child_expressions[child_idx];
362564 auto child_type = ExpressionBinder::GetExpressionReturnType(*child);
362565 auto &subquery_type = bound_node.types[child_idx];
362566 LogicalType compare_type;
362567 if (!LogicalType::TryGetMaxLogicalType(context, child_type, subquery_type, compare_type)) {
362568 throw BinderException(
362569 expr,
362570 "Cannot compare values of type %s and %s in IN/ANY/ALL clause - an explicit cast is required",
362571 child_type.ToString(), subquery_type);
362572 }
362573 child = BoundCastExpression::AddCastToType(context, std::move(child), compare_type);
362574 result->child_types.push_back(subquery_type);
362575 result->child_targets.push_back(compare_type);
362576 result->children.push_back(std::move(child));
362577 }
362578 }
362579 }
362580 result->binder = std::move(subquery_binder);
362581 result->subquery = std::move(bound_node);
362582 result->subquery_type = expr.subquery_type;
362583 result->comparison_type = expr.comparison_type;
362584
362585 return BindResult(std::move(result));
362586}
float corr

◆ BindPositionalReference()

BindResult duckdb::ExpressionBinder::BindPositionalReference ( unique_ptr< ParsedExpression > & expr,
idx_t depth,
bool root_expression )
protected
361919 {
361920 auto &ref = expr->Cast<PositionalReferenceExpression>();
361921 if (depth != 0) {
361922 throw InternalException("Positional reference expression could not be bound");
361923 }
361924 // replace the positional reference with a column
361925 auto column = binder.bind_context.PositionToColumn(ref);
361926 expr = std::move(column);
361927 return BindExpression(expr, depth, root_expression);
361928}

◆ TransformCapturedLambdaColumn()

void duckdb::ExpressionBinder::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 )
protected
361339 {
361340 // check if the original expression is a lambda parameter
361341 if (original->GetExpressionClass() == ExpressionClass::BOUND_LAMBDA_REF) {
361342 auto &bound_lambda_ref = original->Cast<BoundLambdaRefExpression>();
361343 auto alias = bound_lambda_ref.GetAlias();
361344
361345 // refers to a lambda parameter outside the current lambda function
361346 // so the lambda parameter will be inside the lambda_bindings
361347 if (lambda_bindings && bound_lambda_ref.lambda_idx != lambda_bindings->size()) {
361348 auto &binding = (*lambda_bindings)[bound_lambda_ref.lambda_idx];
361349 auto &column_names = binding.GetColumnNames();
361350 auto &column_types = binding.GetColumnTypes();
361351 D_ASSERT(column_names.size() == column_types.size());
361352
361353 // find the matching dummy column in the lambda binding
361354 for (idx_t column_idx = 0; column_idx < binding.GetColumnCount(); column_idx++) {
361355 if (column_idx == bound_lambda_ref.binding.column_index) {
361356 // now create the replacement
361357 auto index = GetLambdaParamIndex(*lambda_bindings, bound_lambda_expr, bound_lambda_ref);
361358 replacement =
361359 make_uniq<BoundReferenceExpression>(column_names[column_idx], column_types[column_idx], index);
361360 return;
361361 }
361362 }
361363
361364 // error resolving the lambda index
361365 throw InternalException("Failed to bind lambda parameter internally");
361366 }
361367 // refers to a lambda parameter inside the current lambda function
361368 auto logical_type =
361369 (*bind_lambda_function)(context, function_child_types, bound_lambda_ref.binding.column_index);
361370 auto index = bound_lambda_expr.parameter_count - bound_lambda_ref.binding.column_index - 1;
361371 replacement = make_uniq<BoundReferenceExpression>(alias, logical_type, index);
361372 return;
361373 }
361374
361375 // this is not a lambda parameter, get the capture offset
361376 idx_t offset = 0;
361377 if (lambda_bindings) {
361378 offset += GetLambdaParamCount(*lambda_bindings);
361379 }
361380 offset += bound_lambda_expr.parameter_count;
361381 offset += bound_lambda_expr.captures.size();
361382
361383 replacement = make_uniq<BoundReferenceExpression>(original->GetAlias(), original->return_type, offset);
361384 bound_lambda_expr.captures.push_back(std::move(original));
361385}

◆ CaptureLambdaColumns()

void duckdb::ExpressionBinder::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 )
protected
361389 {
361390 if (expr->GetExpressionClass() == ExpressionClass::BOUND_SUBQUERY) {
361391 throw BinderException("subqueries in lambda expressions are not supported");
361392 }
361393
361394 // these are bound depth-first
361395 D_ASSERT(expr->GetExpressionClass() != ExpressionClass::BOUND_LAMBDA);
361396
361397 // we do not need to replace anything, as these will be constant in the lambda expression
361398 // when executed by the expression executor
361399 if (expr->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
361400 return;
361401 }
361402
361403 // these expression classes do not have children, transform them
361404 if (expr->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF ||
361405 expr->GetExpressionClass() == ExpressionClass::BOUND_PARAMETER ||
361406 expr->GetExpressionClass() == ExpressionClass::BOUND_LAMBDA_REF) {
361407 if (expr->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) {
361408 // Search for UNNEST.
361409 auto &column_binding = expr->Cast<BoundColumnRefExpression>().binding;
361410 ThrowIfUnnestInLambda(column_binding);
361411 }
361412
361413 // move the expr because we are going to replace it
361414 auto original = std::move(expr);
361415 unique_ptr<Expression> replacement;
361416
361417 TransformCapturedLambdaColumn(original, replacement, bound_lambda_expr, bind_lambda_function,
361418 function_child_types);
361419
361420 // replace the expression
361421 expr = std::move(replacement);
361422
361423 } else {
361424 // recursively enumerate the children of the expression
361425 ExpressionIterator::EnumerateChildren(*expr, [&](unique_ptr<Expression> &child) {
361426 CaptureLambdaColumns(bound_lambda_expr, child, bind_lambda_function, function_child_types);
361427 });
361428 }
361429
361430 expr->Verify();
361431}

◆ GetSQLValueFunction()

unique_ptr< ParsedExpression > duckdb::ExpressionBinder::GetSQLValueFunction ( const string & column_name)
protectedvirtual
360051 {
360052 auto value_function = GetSQLValueFunctionName(column_name);
360053 if (value_function.empty()) {
360054 return nullptr;
360055 }
360056
360057 vector<unique_ptr<ParsedExpression>> children;
360058 return make_uniq<FunctionExpression>(value_function, std::move(children));
360059}

◆ ResolveOperatorType()

LogicalType duckdb::ExpressionBinder::ResolveOperatorType ( OperatorExpression & op,
vector< unique_ptr< Expression > > & children )
protected
361677 {
361678 switch (op.GetExpressionType()) {
361679 case ExpressionType::OPERATOR_IS_NULL:
361680 case ExpressionType::OPERATOR_IS_NOT_NULL:
361681 // IS (NOT) NULL always returns a boolean, and does not cast its children
361682 if (!children[0]->return_type.IsValid()) {
361683 throw ParameterNotResolvedException();
361684 }
361685 return LogicalType::BOOLEAN;
361686 case ExpressionType::COMPARE_IN:
361687 case ExpressionType::COMPARE_NOT_IN:
361688 ResolveCoalesceType(op, children);
361689 // (NOT) IN always returns a boolean
361690 return LogicalType::BOOLEAN;
361691 case ExpressionType::OPERATOR_COALESCE: {
361692 return ResolveCoalesceType(op, children);
361693 }
361694 case ExpressionType::OPERATOR_TRY: {
361695 return children[0]->return_type;
361696 }
361697 case ExpressionType::OPERATOR_NOT:
361698 return ResolveNotType(op, children);
361699 default:
361700 throw InternalException("Unrecognized expression type for ResolveOperatorType");
361701 }
361702}

◆ ResolveCoalesceType()

LogicalType duckdb::ExpressionBinder::ResolveCoalesceType ( OperatorExpression & op,
vector< unique_ptr< Expression > > & children )
protected
361637 {
361638 if (children.empty()) {
361639 throw InternalException("IN requires at least a single child node");
361640 }
361641 // get the maximum type from the children
361642 LogicalType max_type = ExpressionBinder::GetExpressionReturnType(*children[0]);
361643 bool is_in_operator = (op.GetExpressionType() == ExpressionType::COMPARE_IN ||
361644 op.GetExpressionType() == ExpressionType::COMPARE_NOT_IN);
361645 for (idx_t i = 1; i < children.size(); i++) {
361646 auto child_return = ExpressionBinder::GetExpressionReturnType(*children[i]);
361647 if (is_in_operator) {
361648 // If it's IN/NOT_IN operator, adjust DECIMAL and VARCHAR returned type.
361649 if (!BoundComparisonExpression::TryBindComparison(context, max_type, child_return, max_type,
361650 op.GetExpressionType())) {
361651 throw BinderException(op,
361652 "Cannot mix values of type %s and %s in %s clause - an explicit cast is required",
361653 max_type.ToString(), child_return.ToString(),
361654 op.GetExpressionType() == ExpressionType::COMPARE_IN ? "IN" : "NOT IN");
361655 }
361656 } else {
361657 // If it's COALESCE operator, don't do extra adjustment.
361658 if (!LogicalType::TryGetMaxLogicalType(context, max_type, child_return, max_type)) {
361659 throw BinderException(
361660 op, "Cannot mix values of type %s and %s in COALESCE operator - an explicit cast is required",
361661 max_type.ToString(), child_return.ToString());
361662 }
361663 }
361664 }
361665
361666 // cast all children to the same type
361667 for (auto &child : children) {
361668 child = BoundCastExpression::AddCastToType(context, std::move(child), max_type);
361669 if (is_in_operator) {
361670 // If it's IN/NOT_IN operator, push collation functions.
361671 ExpressionBinder::PushCollation(context, child, max_type);
361672 }
361673 }
361674 return max_type;
361675}

◆ ResolveNotType()

LogicalType duckdb::ExpressionBinder::ResolveNotType ( OperatorExpression & op,
vector< unique_ptr< Expression > > & children )
protected
361630 {
361631 // NOT expression, cast child to BOOLEAN
361632 D_ASSERT(children.size() == 1);
361633 children[0] = BoundCastExpression::AddCastToType(context, std::move(children[0]), LogicalType::BOOLEAN);
361634 return LogicalType(LogicalTypeId::BOOLEAN);
361635}

◆ BindUnsupportedExpression()

BindResult duckdb::ExpressionBinder::BindUnsupportedExpression ( ParsedExpression & expr,
idx_t depth,
const string & message )
protected
379179 {
379180 // we always prefer to throw an error if it occurs in a child expression
379181 // since that error might be more descriptive
379182 // bind all children
379183 ErrorData result;
379184 ParsedExpressionIterator::EnumerateChildren(
379185 expr, [&](unique_ptr<ParsedExpression> &child) { BindChild(child, depth, result); });
379186 if (result.HasError()) {
379187 return BindResult(std::move(result));
379188 }
379189 return BindResult(BinderException::Unsupported(expr, message));
379190}

◆ BindAndQualifyFunction()

optional_ptr< CatalogEntry > duckdb::ExpressionBinder::BindAndQualifyFunction ( FunctionExpression & function,
bool allow_throw )
protected
360893 {
360894 D_ASSERT(!IsUnnestFunction(function.function_name));
360895 // lookup the function in the catalog
360896 QueryErrorContext error_context(function.GetQueryLocation());
360897 binder.BindSchemaOrCatalog(function.catalog, function.schema);
360898
360899 EntryLookupInfo function_lookup(CatalogType::SCALAR_FUNCTION_ENTRY, function.function_name, error_context);
360900 auto func = GetCatalogEntry(function.catalog, function.schema, function_lookup, OnEntryNotFound::RETURN_NULL);
360901 if (!func) {
360902 // function was not found - check if we this is a table function
360903 EntryLookupInfo table_function_lookup(CatalogType::TABLE_FUNCTION_ENTRY, function.function_name, error_context);
360904 auto table_func =
360905 GetCatalogEntry(function.catalog, function.schema, table_function_lookup, OnEntryNotFound::RETURN_NULL);
360906 if (table_func) {
360907 if (!allow_throw) {
360908 return func;
360909 }
360910 throw BinderException(function,
360911 "Function \"%s\" is a table function but it was used as a scalar function. This "
360912 "function has to be called in a FROM clause (similar to a table).",
360913 function.function_name);
360914 }
360915 // not a table function - check if the schema is set
360916 if (!function.schema.empty()) {
360917 // the schema is set - check if we can turn this the schema into a column ref
360918 // does this function exist in the system catalog?
360919 func = GetCatalogEntry(INVALID_CATALOG, INVALID_SCHEMA, function_lookup, OnEntryNotFound::RETURN_NULL);
360920 if (func) {
360921 // the function exists in the system catalog - turn this into a dot call
360922 ErrorData error;
360923 unique_ptr<ColumnRefExpression> colref;
360924 if (function.catalog.empty()) {
360925 colref = make_uniq<ColumnRefExpression>(function.schema);
360926 } else {
360927 colref = make_uniq<ColumnRefExpression>(function.schema, function.catalog);
360928 }
360929 auto new_colref = QualifyColumnName(*colref, error);
360930 if (error.HasError()) {
360931 // could not find the column - try to qualify the alias
360932 if (!DoesColumnAliasExist(*colref)) {
360933 if (!allow_throw) {
360934 return func;
360935 }
360936 // no alias found either - throw
360937 error.Throw();
360938 }
360939 }
360940 // we can! transform this into a function call on the column
360941 // i.e. "x.lower()" becomes "lower(x)"
360942 function.children.insert(function.children.begin(), std::move(colref));
360943 function.catalog = INVALID_CATALOG;
360944 function.schema = INVALID_SCHEMA;
360945 }
360946 }
360947 // rebind the function
360948 if (!func) {
360949 const auto on_entry_not_found =
360950 allow_throw ? OnEntryNotFound::THROW_EXCEPTION : OnEntryNotFound::RETURN_NULL;
360951 func = GetCatalogEntry(function.catalog, function.schema, function_lookup, on_entry_not_found);
360952 }
360953 }
360954
360955 return func;
360956}

◆ BindGroupingFunction()

BindResult duckdb::ExpressionBinder::BindGroupingFunction ( OperatorExpression & op,
idx_t depth )
protectedvirtual
361704 {
361705 return BindResult("GROUPING function is not supported here");
361706}

◆ BindFunction()

BindResult duckdb::ExpressionBinder::BindFunction ( FunctionExpression & expr,
ScalarFunctionCatalogEntry & function,
idx_t depth )
protectedvirtual
360987 {
360988 // bind the children of the function expression
360989 ErrorData error;
360990
360991 // bind of each child
360992 for (idx_t i = 0; i < function.children.size(); i++) {
360993 BindChild(function.children[i], depth, error);
360994 }
360995
360996 if (error.HasError()) {
360997 return BindResult(std::move(error));
360998 }
360999 if (binder.GetBindingMode() == BindingMode::EXTRACT_NAMES ||
361000 binder.GetBindingMode() == BindingMode::EXTRACT_QUALIFIED_NAMES) {
361001 return BindResult(make_uniq<BoundConstantExpression>(Value(LogicalType::SQLNULL)));
361002 }
361003
361004 // all children bound successfully
361005 // extract the children and types
361006 vector<unique_ptr<Expression>> children;
361007 for (idx_t i = 0; i < function.children.size(); i++) {
361008 auto &child = BoundExpression::GetExpression(*function.children[i]);
361009 children.push_back(std::move(child));
361010 }
361011
361012 FunctionBinder function_binder(binder);
361013 auto result = function_binder.BindScalarFunction(func, std::move(children), error, function.is_operator, &binder);
361014 if (!result) {
361015 error.AddQueryLocation(function);
361016 error.Throw();
361017 }
361018 if (result->GetExpressionType() == ExpressionType::BOUND_FUNCTION) {
361019 auto &bound_function = result->Cast<BoundFunctionExpression>();
361020 if (bound_function.function.GetStability() == FunctionStability::CONSISTENT_WITHIN_QUERY) {
361021 binder.SetAlwaysRequireRebind();
361022 }
361023 }
361024 return BindResult(std::move(result));
361025}

◆ BindLambdaFunction()

BindResult duckdb::ExpressionBinder::BindLambdaFunction ( FunctionExpression & expr,
ScalarFunctionCatalogEntry & function,
idx_t depth )
protectedvirtual
361028 {
361029 // get the callback function for the lambda parameter types
361030 auto &scalar_function = func.functions.functions.front();
361031 auto bind_lambda_function = scalar_function.GetBindLambdaCallback();
361032 if (!bind_lambda_function) {
361033 return BindResult("This scalar function does not support lambdas!");
361034 }
361035
361036 // the first child is the list, the second child is the lambda expression
361037 // constexpr idx_t list_ix = 0;
361038 constexpr idx_t list_idx = 0;
361039 constexpr idx_t lambda_expr_idx = 1;
361040 D_ASSERT(function.children[lambda_expr_idx]->GetExpressionClass() == ExpressionClass::LAMBDA);
361041
361042 vector<LogicalType> function_child_types;
361043 // bind the list
361044 ErrorData error;
361045 for (idx_t i = 0; i < function.children.size(); i++) {
361046 if (i == lambda_expr_idx) {
361047 function_child_types.push_back(LogicalType::LAMBDA);
361048 continue;
361049 }
361050
361051 if (function.children[i]->GetExpressionClass() == ExpressionClass::LAMBDA) {
361052 return BindResult("No function matches the given name and argument types: '" + function.ToString() +
361053 "'. You might need to add explicit type casts.");
361054 }
361055
361056 BindChild(function.children[i], depth, error);
361057 if (error.HasError()) {
361058 return BindResult(std::move(error));
361059 }
361060
361061 const auto &child = BoundExpression::GetExpression(*function.children[i]);
361062 function_child_types.push_back(child->return_type);
361063 }
361064
361065 // get the logical type of the children of the list
361066 auto &list_child = BoundExpression::GetExpression(*function.children[list_idx]);
361067 if (list_child->return_type.id() != LogicalTypeId::LIST && list_child->return_type.id() != LogicalTypeId::ARRAY &&
361068 list_child->return_type.id() != LogicalTypeId::SQLNULL &&
361069 list_child->return_type.id() != LogicalTypeId::UNKNOWN) {
361070 return BindResult("Invalid LIST argument during lambda function binding!");
361071 }
361072
361073 // bind the lambda parameter
361074 auto &lambda_expr = function.children[lambda_expr_idx]->Cast<LambdaExpression>();
361075 BindResult bind_lambda_result = BindExpression(lambda_expr, depth, function_child_types, &bind_lambda_function);
361076
361077 if (bind_lambda_result.HasError()) {
361078 return BindResult(bind_lambda_result.error);
361079 }
361080
361081 // successfully bound: replace the node with a BoundExpression
361082 auto alias = function.children[lambda_expr_idx]->GetAlias();
361083 bind_lambda_result.expression->SetAlias(alias);
361084 if (!alias.empty()) {
361085 bind_lambda_result.expression->SetAlias(alias);
361086 }
361087 function.children[lambda_expr_idx] = make_uniq<BoundExpression>(std::move(bind_lambda_result.expression));
361088
361089 if (binder.GetBindingMode() == BindingMode::EXTRACT_NAMES) {
361090 return BindResult(make_uniq<BoundConstantExpression>(Value(LogicalType::SQLNULL)));
361091 }
361092
361093 // all children bound successfully
361094 // extract the children and types
361095 vector<unique_ptr<Expression>> children;
361096 for (idx_t i = 0; i < function.children.size(); i++) {
361097 auto &child = BoundExpression::GetExpression(*function.children[i]);
361098 children.push_back(std::move(child));
361099 }
361100
361101 // capture the (lambda) columns
361102 auto &bound_lambda_expr = children[lambda_expr_idx]->Cast<BoundLambdaExpression>();
361103 CaptureLambdaColumns(bound_lambda_expr, bound_lambda_expr.lambda_expr, &bind_lambda_function, function_child_types);
361104
361105 FunctionBinder function_binder(binder);
361106 unique_ptr<Expression> result =
361107 function_binder.BindScalarFunction(func, std::move(children), error, function.is_operator, &binder);
361108 if (!result) {
361109 error.AddQueryLocation(function);
361110 error.Throw();
361111 }
361112
361113 auto &bound_function_expr = result->Cast<BoundFunctionExpression>();
361114
361115 // remove the lambda expression from the children
361116 auto lambda = std::move(bound_function_expr.children[lambda_expr_idx]);
361117 bound_function_expr.children.erase_at(lambda_expr_idx);
361118 auto &bound_lambda = lambda->Cast<BoundLambdaExpression>();
361119
361120 // push back (in reverse order) any nested lambda parameters so that we can later use them in the lambda
361121 // expression (rhs). This happens after we bound the lambda expression of this depth. So it is relevant for
361122 // correctly binding lambdas one level 'out'. Therefore, the current parameter count does not matter here.
361123 if (lambda_bindings) {
361124 idx_t offset = 0;
361125
361126 for (idx_t i = lambda_bindings->size(); i > 0; i--) {
361127 auto &binding = (*lambda_bindings)[i - 1];
361128 auto &column_names = binding.GetColumnNames();
361129 auto &column_types = binding.GetColumnTypes();
361130 D_ASSERT(column_names.size() == column_types.size());
361131
361132 for (idx_t column_idx = column_names.size(); column_idx > 0; column_idx--) {
361133 auto bound_lambda_param = make_uniq<BoundReferenceExpression>(column_names[column_idx - 1],
361134 column_types[column_idx - 1], offset);
361135 offset++;
361136 bound_function_expr.children.push_back(std::move(bound_lambda_param));
361137 }
361138 }
361139 }
361140
361141 // push back the captures into the children vector
361142 for (auto &capture : bound_lambda.captures) {
361143 bound_function_expr.children.push_back(std::move(capture));
361144 }
361145
361146 return BindResult(std::move(result));
361147}

◆ BindAggregate()

BindResult duckdb::ExpressionBinder::BindAggregate ( FunctionExpression & expr,
AggregateFunctionCatalogEntry & function,
idx_t depth )
protectedvirtual
361150 {
361151 return BindUnsupportedExpression(expr, depth, UnsupportedAggregateMessage());
361152}

◆ BindUnnest()

BindResult duckdb::ExpressionBinder::BindUnnest ( FunctionExpression & expr,
idx_t depth,
bool root_expression )
protectedvirtual
361154 {
361155 return BindUnsupportedExpression(expr, depth, UnsupportedUnnestMessage());
361156}

◆ BindMacro()

BindResult duckdb::ExpressionBinder::BindMacro ( FunctionExpression & expr,
ScalarMacroCatalogEntry & macro,
idx_t depth,
unique_ptr< ParsedExpression > & expr_ptr )
protectedvirtual
361577 {
361578 auto stack_checker = StackCheck(*expr, 3);
361579
361580 // unfold the macro expression
361581 UnfoldMacroExpression(function, macro_func, expr, depth);
361582
361583 // bind the unfolded macro
361584 return BindExpression(expr, depth);
361585}

◆ UnfoldMacroExpression()

void duckdb::ExpressionBinder::UnfoldMacroExpression ( FunctionExpression & function,
ScalarMacroCatalogEntry & macro_func,
unique_ptr< ParsedExpression > & expr,
idx_t depth )
protected
361528 {
361529 // validate the arguments and separate positional and default arguments
361530 vector<unique_ptr<ParsedExpression>> positional_arguments;
361531 InsertionOrderPreservingMap<unique_ptr<ParsedExpression>> named_arguments;
361532 binder.lambda_bindings = lambda_bindings;
361533 auto bind_result = MacroFunction::BindMacroFunction(binder, macro_func.macros, macro_func.name, function,
361534 positional_arguments, named_arguments, depth);
361535 if (!bind_result.error.empty()) {
361536 throw BinderException(*expr, bind_result.error);
361537 }
361538 auto &macro_def = macro_func.macros[bind_result.function_idx.GetIndex()]->Cast<ScalarMacroFunction>();
361539
361540 auto new_macro_binding =
361541 MacroFunction::CreateDummyBinding(macro_def, macro_func.name, positional_arguments, named_arguments);
361542 macro_binding = new_macro_binding.get();
361543
361544 // replace current expression with stored macro expression
361545 // special case: If this is a window function, then we need to return a window expression
361546 if (expr->GetExpressionClass() == ExpressionClass::WINDOW) {
361547 // Only allowed if the expression is a function
361548 if (macro_def.expression->GetExpressionType() != ExpressionType::FUNCTION) {
361549 throw BinderException("Window function macros must be functions");
361550 }
361551 auto macro_copy = macro_def.expression->Copy();
361552 auto &macro_expr = macro_copy->Cast<FunctionExpression>();
361553 // Transfer the macro function attributes
361554 auto &window_expr = expr->Cast<WindowExpression>();
361555 window_expr.catalog = macro_expr.catalog;
361556 window_expr.schema = macro_expr.schema;
361557 window_expr.function_name = macro_expr.function_name;
361558 window_expr.children = std::move(macro_expr.children);
361559 window_expr.distinct = macro_expr.distinct;
361560 window_expr.filter_expr = std::move(macro_expr.filter);
361561 // TODO: transfer order_bys when window functions support them
361562 } else {
361563 expr = macro_def.expression->Copy();
361564 }
361565
361566 // qualify only the macro parameters with a new empty binder that only knows the macro binding
361567 auto dummy_binder = Binder::CreateBinder(context);
361568 dummy_binder->macro_binding = new_macro_binding.get();
361569 ExpressionBinder::QualifyColumnNames(*dummy_binder, expr);
361570
361571 // now replace the parameters
361572 vector<unordered_set<string>> lambda_params;
361573 ReplaceMacroParameters(expr, lambda_params);
361574}

◆ UnsupportedAggregateMessage()

string duckdb::ExpressionBinder::UnsupportedAggregateMessage ( )
protectedvirtual
361161 {
361162 return "Aggregate functions are not supported here";
361163}

◆ UnsupportedUnnestMessage()

string duckdb::ExpressionBinder::UnsupportedUnnestMessage ( )
protectedvirtual
361165 {
361166 return "UNNEST not supported here";
361167}

◆ GetCatalogEntry()

optional_ptr< CatalogEntry > duckdb::ExpressionBinder::GetCatalogEntry ( const string & catalog,
const string & schema,
const EntryLookupInfo & lookup_info,
OnEntryNotFound on_entry_not_found )
protected
361171 {
361172 return binder.GetCatalogEntry(catalog, schema, lookup_info, on_entry_not_found);
361173}

◆ TryBindLambdaOrJson()

BindResult duckdb::ExpressionBinder::TryBindLambdaOrJson ( FunctionExpression & function,
idx_t depth,
CatalogEntry & func,
const LambdaSyntaxType syntax_type )
protected
360835 {
360836 if (syntax_type == LambdaSyntaxType::LAMBDA_KEYWORD) {
360837 // lambda x: x + 1 syntax.
360838 return BindLambdaFunction(function, func.Cast<ScalarFunctionCatalogEntry>(), depth);
360839 }
360840
360841 auto setting = Settings::Get<LambdaSyntaxSetting>(context);
360842 bool invalid_syntax =
360843 setting == LambdaSyntax::DISABLE_SINGLE_ARROW && syntax_type == LambdaSyntaxType::SINGLE_ARROW;
360844 bool warn_deprecated_syntax = setting == LambdaSyntax::DEFAULT && syntax_type == LambdaSyntaxType::SINGLE_ARROW;
360845 const string msg = "Deprecated lambda arrow (->) detected. Please transition to the new lambda syntax, "
360846 "i.e.., lambda x, i: x + i, before DuckDB's next release.\n"
360847 "Use SET lambda_syntax='ENABLE_SINGLE_ARROW' to revert to the deprecated behavior.\n"
360848 "For more information, see https://duckdb.org/docs/stable/sql/functions/lambda.html.";
360849
360850 BindResult lambda_bind_result;
360851 ErrorData error;
360852 try {
360853 lambda_bind_result = BindLambdaFunction(function, func.Cast<ScalarFunctionCatalogEntry>(), depth);
360854 } catch (const std::exception &ex) {
360855 error = ErrorData(ex);
360856 }
360857
360858 if (error.HasError() && error.Type() == ExceptionType::PARAMETER_NOT_RESOLVED && invalid_syntax) {
360859 ErrorData deprecation_error(ExceptionType::BINDER, msg);
360860 deprecation_error.Throw();
360861 } else if (error.HasError()) {
360862 error.Throw();
360863 }
360864
360865 if (!lambda_bind_result.HasError()) {
360866 if (!invalid_syntax) {
360867 if (warn_deprecated_syntax) {
360868 DUCKDB_LOG_WARNING(context, msg);
360869 }
360870 return lambda_bind_result;
360871 }
360872 return BindResult(msg);
360873 }
360874 if (StringUtil::Contains(lambda_bind_result.error.RawMessage(), "Deprecated lambda arrow (->) detected.")) {
360875 if (warn_deprecated_syntax) {
360876 DUCKDB_LOG_WARNING(context, msg);
360877 }
360878
360879 return lambda_bind_result;
360880 }
360881
360882 auto json_bind_result = BindFunction(function, func.Cast<ScalarFunctionCatalogEntry>(), depth);
360883 if (!json_bind_result.HasError()) {
360884 return json_bind_result;
360885 }
360886
360887 return BindResult("failed to bind function, either: " + lambda_bind_result.error.RawMessage() +
360888 "\n"
360889 " or: " +
360890 json_bind_result.error.RawMessage());
360891}
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

◆ QualifyColumnNameWithManyDotsInternal()

unique_ptr< ParsedExpression > duckdb::ExpressionBinder::QualifyColumnNameWithManyDotsInternal ( ColumnRefExpression & col_ref,
ErrorData & error,
idx_t & struct_extract_start )
protected
360293 {
360294 // two or more dots (i.e. "part1.part2.part3.part4...")
360295 // -> part1 is a catalog, part2 is a schema, part3 is a table, part4 is a column name, part 5 and beyond are
360296 // struct fields
360297 // -> part1 is a catalog, part2 is a table, part3 is a column name, part4 and beyond are struct fields
360298 // -> part1 is a schema, part2 is a table, part3 is a column name, part4 and beyond are struct fields
360299 // -> part1 is a table, part2 is a column name, part3 and beyond are struct fields
360300 // -> part1 is a column, part2 and beyond are struct fields
360301
360302 // we always prefer the most top-level view
360303 // i.e. in case of multiple resolution options, we resolve in order:
360304 // -> 1. resolve "part1" as a catalog
360305 // -> 2. resolve "part1" as a schema
360306 // -> 3. resolve "part1" as a table
360307 // -> 4. resolve "part1" as a column
360308
360309 // first check if part1 is a catalog
360310 ErrorData fully_qualified_error;
360311 optional_ptr<Binding> binding;
360312 if (col_ref.column_names.size() > 3) {
360313 binding = binder.GetMatchingBinding(col_ref.column_names[0], col_ref.column_names[1], col_ref.column_names[2],
360314 col_ref.column_names[3], fully_qualified_error);
360315 if (binding) {
360316 // part1 is a catalog - the column reference is "catalog.schema.table.column"
360317 struct_extract_start = 4;
360318 return binder.bind_context.CreateColumnReference(binding->GetBindingAlias(), col_ref.column_names[3]);
360319 }
360320 }
360321 ErrorData catalog_table_error;
360322 binding = binder.GetMatchingBinding(col_ref.column_names[0], INVALID_SCHEMA, col_ref.column_names[1],
360323 col_ref.column_names[2], catalog_table_error);
360324 if (binding) {
360325 // part1 is a catalog - the column reference is "catalog.table.column"
360326 struct_extract_start = 3;
360327 return binder.bind_context.CreateColumnReference(binding->GetBindingAlias(), col_ref.column_names[2]);
360328 }
360329 ErrorData schema_table_error;
360330 binding = binder.GetMatchingBinding(col_ref.column_names[0], col_ref.column_names[1], col_ref.column_names[2],
360331 schema_table_error);
360332 if (binding) {
360333 // part1 is a schema - the column reference is "schema.table.column"
360334 // any additional fields are turned into struct_extract calls
360335 struct_extract_start = 3;
360336 return binder.bind_context.CreateColumnReference(binding->GetBindingAlias(), col_ref.column_names[2]);
360337 }
360338 ErrorData table_column_error;
360339 binding = binder.GetMatchingBinding(col_ref.column_names[0], col_ref.column_names[1], table_column_error);
360340 if (binding) {
360341 // part1 is a table
360342 // the column reference is "table.column"
360343 // any additional fields are turned into struct_extract calls
360344 struct_extract_start = 2;
360345 return binder.bind_context.CreateColumnReference(binding->GetBindingAlias(), col_ref.column_names[1]);
360346 }
360347 // part1 could be a column
360348 ErrorData unused_error;
360349 auto result_expr = QualifyColumnName(col_ref, col_ref.column_names[0], unused_error);
360350 if (result_expr) {
360351 // it is! add the struct extract calls
360352 struct_extract_start = 1;
360353 return result_expr;
360354 }
360355 auto struct_pack = CreateStructPack(col_ref);
360356 if (struct_pack) {
360357 return struct_pack;
360358 }
360359
360360 // we could not find the column - return an error
360361 // try to find out which error to return
360362 optional_idx catalog_pos;
360363 optional_idx schema_pos;
360364 optional_idx table_pos;
360365 for (const auto &binding_entry : binder.bind_context.GetBindingsList()) {
360366 auto &alias = binding_entry->GetBindingAlias();
360367 string catalog = alias.GetCatalog();
360368 string schema = alias.GetSchema();
360369 string table = alias.GetAlias();
360370 auto entry = binding_entry->GetStandardEntry();
360371 if (entry) {
360372 catalog = entry->ParentCatalog().GetName();
360373 schema = entry->ParentSchema().name;
360374 }
360375
360376 for (idx_t i = 0; i < 3; i++) {
360377 if (catalog == col_ref.column_names[i]) {
360378 catalog_pos = i;
360379 }
360380 if (schema == col_ref.column_names[i]) {
360381 schema_pos = i;
360382 }
360383 if (table == col_ref.column_names[i]) {
360384 table_pos = i;
360385 }
360386 }
360387 }
360388
360389 error = std::move(table_column_error);
360390 if (table_pos.IsValid()) {
360391 // we have a valid table
360392 if (table_pos.GetIndex() == 0) {
360393 // the first column is a valid table - return the error as if we were binding the column as the second
360394
360395 } else if (table_pos.GetIndex() == 1) {
360396 // the first column is a valid table
360397 // this means either the first column is a catalog OR the first column is a schema
360398 if (catalog_pos.IsValid()) {
360399 // catalog.table
360400 error = std::move(catalog_table_error);
360401 } else {
360402 // assume schema.table otherwise
360403 error = std::move(schema_table_error);
360404 }
360405 } else if (col_ref.column_names.size() > 3) {
360406 // the second column is a valid table
360407 // return the fully qualified error if we have enough components
360408 error = std::move(fully_qualified_error);
360409 }
360410 } else if (catalog_pos.IsValid()) {
360411 // the first column is a catalog
360412 if (schema_pos.IsValid()) {
360413 // AND a valid schema - this is likely "catalog.schema.table"
360414 if (col_ref.column_names.size() > 3) {
360415 error = std::move(fully_qualified_error);
360416 } else {
360417 error = std::move(catalog_table_error);
360418 }
360419 } else {
360420 // but no valid schema - this could be either "catalog.schema.table" or "catalog.table"
360421 // return "catalog.table" for now
360422 error = std::move(catalog_table_error);
360423 }
360424 } else if (schema_pos.IsValid()) {
360425 // we did not find a catalog or a table, but we did find a schema
360426 if (schema_pos.GetIndex() == 0) {
360427 // "schema.table"
360428 error = std::move(schema_table_error);
360429 } else if (schema_pos.GetIndex() == 1 && col_ref.column_names.size() > 3) {
360430 // catalog.schema.table
360431 error = std::move(fully_qualified_error);
360432 }
360433 }
360434 return nullptr;
360435}

◆ ThrowIfUnnestInLambda()

void duckdb::ExpressionBinder::ThrowIfUnnestInLambda ( const ColumnBinding & column_binding)
protectedvirtual
361158 {
361159}

Member Data Documentation

◆ target_type

LogicalType duckdb::ExpressionBinder::target_type

The target type that should result from the binder. If the result is not of this type, a cast to this type will be added. Defaults to INVALID.


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