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

Public Member Functions

 ColumnBindingResolver (bool verify_only=false)
void VisitOperator (LogicalOperator &op) override
Public Member Functions inherited from duckdb::LogicalOperatorVisitor
virtual void VisitExpression (unique_ptr< Expression > *expression)

Static Public Member Functions

static void Verify (LogicalOperator &op)
Static Public Member Functions inherited from duckdb::LogicalOperatorVisitor
static void EnumerateExpressions (LogicalOperator &op, const std::function< void(unique_ptr< Expression > *child)> &callback)

Protected Member Functions

unique_ptr< Expression > VisitReplace (BoundColumnRefExpression &expr, unique_ptr< Expression > *expr_ptr) override
Protected Member Functions inherited from duckdb::LogicalOperatorVisitor
void VisitOperatorChildren (LogicalOperator &op)
void VisitOperatorExpressions (LogicalOperator &op)
void VisitOperatorWithProjectionMapChildren (LogicalOperator &op)
 Alternatives for VisitOperatorChildren for operators that have a projection map.
void VisitChildOfOperatorWithProjectionMap (LogicalOperator &child, vector< idx_t > &projection_map)
virtual void VisitExpressionChildren (Expression &expression)
virtual unique_ptr< Expression > VisitReplace (BoundAggregateExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundBetweenExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCaseExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCastExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundComparisonExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConjunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConstantExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundDefaultExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundFunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundOperatorExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundReferenceExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundSubqueryExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundParameterExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundWindowExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundUnnestExpression &expr, unique_ptr< Expression > *expr_ptr)

Static Protected Member Functions

static unordered_set< idx_t > VerifyInternal (LogicalOperator &op)

Protected Attributes

vector< ColumnBinding > bindings
vector< LogicalType > types
bool verify_only

Detailed Description

The ColumnBindingResolver resolves ColumnBindings into base tables (table_index, column_index) into physical indices into the DataChunks that are used within the execution engine

Constructor & Destructor Documentation

◆ ColumnBindingResolver()

duckdb::ColumnBindingResolver::ColumnBindingResolver ( bool verify_only = false)
explicit
147691 : verify_only(verify_only) {
147692}

Member Function Documentation

◆ VisitOperator()

void duckdb::ColumnBindingResolver::VisitOperator ( LogicalOperator & op)
overridevirtual

We first need to update the current set of bindings and then visit operator expressions

We want to execute the normal path, but also add a dummy 'excluded' binding if there is a

Reimplemented from duckdb::LogicalOperatorVisitor.

147694 {
147695 switch (op.type) {
147696 case LogicalOperatorType::LOGICAL_ASOF_JOIN:
147697 case LogicalOperatorType::LOGICAL_COMPARISON_JOIN: {
147698 // special case: comparison join
147699 auto &comp_join = op.Cast<LogicalComparisonJoin>();
147700 // first get the bindings of the LHS and resolve the LHS expressions
147701 VisitOperator(*comp_join.children[0]);
147702 for (auto &cond : comp_join.conditions) {
147703 VisitExpression(&cond.left);
147704 }
147705 // visit the duplicate eliminated columns on the LHS, if any
147706 for (auto &expr : comp_join.duplicate_eliminated_columns) {
147707 VisitExpression(&expr);
147708 }
147709 // then get the bindings of the RHS and resolve the RHS expressions
147710 VisitOperator(*comp_join.children[1]);
147711 for (auto &cond : comp_join.conditions) {
147712 VisitExpression(&cond.right);
147713 }
147714 // finally update the bindings with the result bindings of the join
147715 bindings = op.GetColumnBindings();
147716 types = op.types;
147717 // resolve any mixed predicates
147718 // for now, only ASOF supports this.
147719 if (comp_join.predicate) {
147720 D_ASSERT(op.type == LogicalOperatorType::LOGICAL_ASOF_JOIN);
147721 // If this is a SEMI or ANTI join and we have an arbitrary predicate,
147722 // we need to include the bindings of the RHS
147723 if (comp_join.join_type == JoinType::SEMI || comp_join.join_type == JoinType::ANTI) {
147724 auto right_bindings = op.children[1]->GetColumnBindings();
147725 bindings.insert(bindings.end(), right_bindings.begin(), right_bindings.end());
147726 auto &right_types = op.children[1]->types;
147727 types.insert(types.end(), right_types.begin(), right_types.end());
147728 }
147729 VisitExpression(&comp_join.predicate);
147730 }
147731 return;
147732 }
147733 case LogicalOperatorType::LOGICAL_DELIM_JOIN: {
147734 auto &comp_join = op.Cast<LogicalComparisonJoin>();
147735 // get bindings from the duplicate-eliminated side
147736 auto &delim_side = comp_join.delim_flipped ? *comp_join.children[1] : *comp_join.children[0];
147737 VisitOperator(delim_side);
147738 for (auto &cond : comp_join.conditions) {
147739 auto &expr = comp_join.delim_flipped ? cond.right : cond.left;
147740 VisitExpression(&expr);
147741 }
147742 // visit the duplicate eliminated columns
147743 for (auto &expr : comp_join.duplicate_eliminated_columns) {
147744 VisitExpression(&expr);
147745 }
147746 // now the other side
147747 auto &other_side = comp_join.delim_flipped ? *comp_join.children[0] : *comp_join.children[1];
147748 VisitOperator(other_side);
147749 for (auto &cond : comp_join.conditions) {
147750 auto &expr = comp_join.delim_flipped ? cond.left : cond.right;
147751 VisitExpression(&expr);
147752 }
147753 // finally update the bindings with the result bindings of the join
147754 bindings = op.GetColumnBindings();
147755 types = op.types;
147756 return;
147757 }
147758 case LogicalOperatorType::LOGICAL_ANY_JOIN: {
147759 // ANY join, this join is different because we evaluate the expression on the bindings of BOTH join sides at
147760 // once i.e. we set the bindings first to the bindings of the entire join, and then resolve the expressions of
147761 // this operator
147763 bindings = op.GetColumnBindings();
147764 types = op.types;
147765 auto &any_join = op.Cast<LogicalAnyJoin>();
147766 if (any_join.join_type == JoinType::SEMI || any_join.join_type == JoinType::ANTI) {
147767 auto right_bindings = op.children[1]->GetColumnBindings();
147768 bindings.insert(bindings.end(), right_bindings.begin(), right_bindings.end());
147769 auto &right_types = op.children[1]->types;
147770 types.insert(types.end(), right_types.begin(), right_types.end());
147771 }
147772 if (any_join.join_type == JoinType::RIGHT_SEMI || any_join.join_type == JoinType::RIGHT_ANTI) {
147773 throw InternalException("RIGHT SEMI/ANTI any join not supported yet");
147774 }
147776 return;
147777 }
147778 case LogicalOperatorType::LOGICAL_CREATE_INDEX: {
147779 // CREATE INDEX statement, add the columns of the table with table index 0 to the binding set
147780 // afterwards bind the expressions of the CREATE INDEX statement
147781 auto &create_index = op.Cast<LogicalCreateIndex>();
147782 bindings = LogicalOperator::GenerateColumnBindings(0, create_index.table.GetColumns().LogicalColumnCount());
147783 // TODO: fill types in too (clearing skips type checks)
147784 types.clear();
147786 return;
147787 }
147788 case LogicalOperatorType::LOGICAL_GET: {
147790 bindings = op.GetColumnBindings();
147791 types = op.types;
147793 return;
147794 }
147795 case LogicalOperatorType::LOGICAL_INSERT: {
147797 // ON CONFLICT DO UPDATE clause
147798 auto &insert_op = op.Cast<LogicalInsert>();
147799 if (insert_op.on_conflict_info.action_type != OnConflictAction::THROW) {
147800 // Get the bindings from the children
147802 auto column_count = insert_op.table.GetColumns().PhysicalColumnCount();
147803 auto dummy_bindings =
147804 LogicalOperator::GenerateColumnBindings(insert_op.on_conflict_info.excluded_table_index, column_count);
147805 // Now insert our dummy bindings at the start of the bindings,
147806 // so the first 'column_count' indices of the chunk are reserved for our 'excluded' columns
147807 bindings.insert(bindings.begin(), dummy_bindings.begin(), dummy_bindings.end());
147808 // TODO: fill types in too (clearing skips type checks)
147809 types.clear();
147810 if (insert_op.on_conflict_info.on_conflict_condition) {
147811 VisitExpression(&insert_op.on_conflict_info.on_conflict_condition);
147812 }
147813 if (insert_op.on_conflict_info.do_update_condition) {
147814 VisitExpression(&insert_op.on_conflict_info.do_update_condition);
147815 }
147817 bindings = op.GetColumnBindings();
147818 types = op.types;
147819 return;
147820 }
147821 break;
147822 }
147823 case LogicalOperatorType::LOGICAL_EXTENSION_OPERATOR: {
147824 auto &ext_op = op.Cast<LogicalExtensionOperator>();
147825 // Just to be very sure, we clear before and after resolving extension operator column bindings
147826 // This skips checks, but makes sure we don't break any extension operators with type verification
147827 types.clear();
147828 ext_op.ResolveColumnBindings(*this, bindings);
147829 types.clear();
147830 return;
147831 }
147832 case LogicalOperatorType::LOGICAL_RECURSIVE_CTE: {
147833 auto &rec = op.Cast<LogicalRecursiveCTE>();
147835 bindings = op.GetColumnBindings();
147836 types = op.types;
147837 for (auto &expr : rec.key_targets) {
147838 VisitExpression(&expr);
147839 }
147840 return;
147841 }
147842 default:
147843 break;
147844 }
147845
147846 // general case
147847 // first visit the children of this operator
147849 // now visit the expressions of this operator to resolve any bound column references
147851 // finally update the current set of bindings to the current set of column bindings
147852 bindings = op.GetColumnBindings();
147853 types = op.types;
147854}
void VisitOperator(LogicalOperator &op) override
Definition duckdb.cpp:147694
void VisitOperatorExpressions(LogicalOperator &op)
Definition duckdb.cpp:381188
void VisitOperatorChildren(LogicalOperator &op)
Definition duckdb.cpp:380983
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Verify()

void duckdb::ColumnBindingResolver::Verify ( LogicalOperator & op)
static
147914 {
147915#ifdef DEBUG
147916 op.ResolveOperatorTypes();
147917 ColumnBindingResolver resolver(true);
147918 resolver.VisitOperator(op);
147919 VerifyInternal(op);
147920#endif
147921}

◆ VisitReplace()

unique_ptr< Expression > duckdb::ColumnBindingResolver::VisitReplace ( BoundColumnRefExpression & expr,
unique_ptr< Expression > * expr_ptr )
overrideprotectedvirtual

Reimplemented from duckdb::LogicalOperatorVisitor.

147857 {
147858 D_ASSERT(expr.depth == 0);
147859 // check the current set of column bindings to see which index corresponds to the column reference
147860 for (idx_t i = 0; i < bindings.size(); i++) {
147861 if (expr.binding == bindings[i]) {
147862 if (!types.empty()) {
147863 if (bindings.size() != types.size()) {
147864 throw InternalException(
147865 "Failed to bind column reference \"%s\" [%d.%d]: inequal num bindings/types (%llu != %llu)",
147866 expr.GetAlias(), expr.binding.table_index, expr.binding.column_index, bindings.size(),
147867 types.size());
147868 }
147869 if (expr.return_type != types[i]) {
147870 throw InternalException("Failed to bind column reference \"%s\" [%d.%d]: inequal types (%s != %s)",
147871 expr.GetAlias(), expr.binding.table_index, expr.binding.column_index,
147872 expr.return_type.ToString(), types[i].ToString());
147873 }
147874 }
147875 if (verify_only) {
147876 // in verification mode
147877 return nullptr;
147878 }
147879 return make_uniq<BoundReferenceExpression>(expr.GetAlias(), expr.return_type, i);
147880 }
147881 }
147882 // LCOV_EXCL_START
147883 // could not bind the column reference, this should never happen and indicates a bug in the code
147884 // generate an error message
147885 throw InternalException("Failed to bind column reference \"%s\" [%d.%d] (bindings: %s)", expr.GetAlias(),
147886 expr.binding.table_index, expr.binding.column_index,
147887 LogicalOperator::ColumnBindingsToString(bindings));
147888 // LCOV_EXCL_STOP
147889}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ VerifyInternal()

unordered_set< idx_t > duckdb::ColumnBindingResolver::VerifyInternal ( LogicalOperator & op)
staticprotected
147891 {
147892 unordered_set<idx_t> result;
147893 for (auto &child : op.children) {
147894 auto child_indexes = VerifyInternal(*child);
147895 for (auto index : child_indexes) {
147896 D_ASSERT(index != DConstants::INVALID_INDEX);
147897 if (result.find(index) != result.end()) {
147898 throw InternalException("Duplicate table index \"%lld\" found", index);
147899 }
147900 result.insert(index);
147901 }
147902 }
147903 auto indexes = op.GetTableIndex();
147904 for (auto index : indexes) {
147905 D_ASSERT(index != DConstants::INVALID_INDEX);
147906 if (result.find(index) != result.end()) {
147907 throw InternalException("Duplicate table index \"%lld\" found", index);
147908 }
147909 result.insert(index);
147910 }
147911 return result;
147912}
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

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