MCPcopy Create free account
hub / github.com/duckdb/duckdb / BindSelectNode

Method BindSelectNode

src/planner/binder/query_node/bind_select_node.cpp:421–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420
421BoundStatement Binder::BindSelectNode(SelectNode &statement, BoundStatement from_table) {
422 D_ASSERT(from_table.plan);
423 D_ASSERT(!statement.from_table);
424 auto result_ptr = make_uniq<BoundSelectNode>();
425 auto &result = *result_ptr;
426 result.projection_index = GenerateTableIndex();
427 result.group_index = GenerateTableIndex();
428 result.aggregate_index = GenerateTableIndex();
429 result.groupings_index = GenerateTableIndex();
430 result.window_index = GenerateTableIndex();
431 result.prune_index = GenerateTableIndex();
432
433 result.from_table = std::move(from_table);
434 // bind the sample clause
435 if (statement.sample) {
436 result.sample_options = std::move(statement.sample);
437 }
438
439 // visit the select list and expand any "*" statements
440 vector<unique_ptr<ParsedExpression>> new_select_list;
441 ExpandStarExpressions(statement.select_list, new_select_list);
442
443 if (new_select_list.empty()) {
444 throw BinderException("SELECT list is empty after resolving * expressions!");
445 }
446 statement.select_list = std::move(new_select_list);
447
448 auto &bind_state = result.bind_state;
449 for (idx_t i = 0; i < statement.select_list.size(); i++) {
450 auto &expr = statement.select_list[i];
451 result.names.push_back(expr->GetName());
452 ExpressionBinder::QualifyColumnNames(*this, expr);
453 if (!expr->GetAlias().empty()) {
454 bind_state.alias_map[expr->GetAlias()] = i;
455 result.names[i] = expr->GetAlias();
456 }
457 bind_state.projection_map[*expr] = i;
458 bind_state.original_expressions.push_back(expr->Copy());
459 }
460 result.column_count = statement.select_list.size();
461
462 // first visit the WHERE clause
463 // the WHERE clause happens before the GROUP BY, PROJECTION or HAVING clauses
464 if (statement.where_clause) {
465 // bind any star expressions in the WHERE clause
466 BindWhereStarExpression(statement.where_clause);
467
468 ColumnAliasBinder alias_binder(bind_state);
469 WhereBinder where_binder(*this, context, &alias_binder);
470 unique_ptr<ParsedExpression> condition = std::move(statement.where_clause);
471 result.where_clause = where_binder.Bind(condition);
472 }
473
474 // now bind all the result modifiers; including DISTINCT and ORDER BY targets
475 OrderBinder order_binder({*this}, statement, bind_state);
476 PrepareModifiers(order_binder, statement, result);
477
478 vector<unique_ptr<ParsedExpression>> unbound_groups;

Callers 1

BindMethod · 0.80

Calls 15

BinderExceptionClass · 0.85
idMethod · 0.80
BindAggregateFunctionMethod · 0.80
HasBoundColumnsMethod · 0.80
BoundAggregatesMethod · 0.80
GetExpressionTypeMethod · 0.80
AddExpandedColumnMethod · 0.80
AddRegularColumnMethod · 0.80
ResetBindingsMethod · 0.80
GetFunctionFunction · 0.50

Tested by

no test coverage detected