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::TableBinding Struct Reference
Inheritance diagram for duckdb::TableBinding:
Collaboration diagram for duckdb::TableBinding:

Public Member Functions

 TableBinding (const string &alias, vector< LogicalType > types, vector< string > names, vector< ColumnIndex > &bound_column_ids, optional_ptr< StandardEntry > entry, idx_t index, virtual_column_map_t virtual_columns)
unique_ptr< ParsedExpression > ExpandGeneratedColumn (const string &column_name)
BindResult Bind (ColumnRefExpression &colref, idx_t depth) override
optional_ptr< StandardEntry > GetStandardEntry () override
ErrorData ColumnNotFoundError (const string &column_name) const override
const vector< ColumnIndex > & GetBoundColumnIds () const
Public Member Functions inherited from duckdb::Binding
 Binding (BindingType binding_type, BindingAlias alias, vector< LogicalType > types, vector< string > names, idx_t index)
bool TryGetBindingIndex (const string &column_name, column_t &column_index)
column_t GetBindingIndex (const string &column_name)
bool HasMatchingBinding (const string &column_name)
string GetAlias () const
BindingType GetBindingType ()
const BindingAlias & GetBindingAlias ()
idx_t GetIndex ()
const vector< LogicalType > & GetColumnTypes ()
const vector< string > & GetColumnNames ()
idx_t GetColumnCount ()
void SetColumnType (idx_t col_idx, LogicalType type)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

vector< ColumnIndex > & bound_column_ids
 A reference to the set of bound column ids.
optional_ptr< StandardEntry > entry
 The underlying catalog entry (if any).
virtual_column_map_t virtual_columns
 Virtual columns.

Static Public Attributes

static constexpr const BindingType TYPE = BindingType::TABLE

Protected Member Functions

ColumnBinding GetColumnBinding (column_t column_index)
Protected Member Functions inherited from duckdb::Binding
void Initialize ()

Additional Inherited Members

Static Public Member Functions inherited from duckdb::Binding
static BindingAlias GetAlias (const string &explicit_alias, const StandardEntry &entry)
static BindingAlias GetAlias (const string &explicit_alias, optional_ptr< StandardEntry > entry)
Protected Attributes inherited from duckdb::Binding
BindingType binding_type
 The type of Binding.
BindingAlias alias
 The alias of the binding.
idx_t index
 The table index of the binding.
vector< LogicalType > types
 The types of the bound columns.
vector< string > names
 Column names of the subquery.
case_insensitive_map_t< column_t > name_map
 Name -> index for the names.

Detailed Description

TableBinding is exactly like the Binding, except it keeps track of which columns were bound in the linked LogicalGet node for projection pushdown purposes.

Constructor & Destructor Documentation

◆ TableBinding()

duckdb::TableBinding::TableBinding ( const string & alias,
vector< LogicalType > types,
vector< string > names,
vector< ColumnIndex > & bound_column_ids,
optional_ptr< StandardEntry > entry,
idx_t index,
virtual_column_map_t virtual_columns )
385675 : Binding(BindingType::TABLE, GetAlias(alias, entry), std::move(types_p), std::move(names_p), index),
385676 bound_column_ids(bound_column_ids), entry(entry), virtual_columns(std::move(virtual_columns_p)) {
385677 for (auto &ventry : virtual_columns) {
385678 auto idx = ventry.first;
385679 auto &name = ventry.second.name;
385680 if (idx < VIRTUAL_COLUMN_START) {
385681 throw BinderException(
385682 "Virtual column index must be larger than VIRTUAL_COLUMN_START - found %d for column \"%s\"", idx,
385683 name);
385684 }
385685 if (idx == COLUMN_IDENTIFIER_EMPTY) {
385686 // the empty column cannot be queried by the user
385687 continue;
385688 }
385689 if (name_map.find(name) == name_map.end()) {
385690 name_map[name] = idx;
385691 }
385692 }
385693}
const column_t COLUMN_IDENTIFIER_EMPTY
Special value used to signify an empty column (used for e.g. COUNT(*)).
Definition duckdb.cpp:50304
idx_t index
The table index of the binding.
Definition duckdb.cpp:1343
case_insensitive_map_t< column_t > name_map
Name -> index for the names.
Definition duckdb.cpp:1349
BindingAlias alias
The alias of the binding.
Definition duckdb.cpp:1341
optional_ptr< StandardEntry > entry
The underlying catalog entry (if any).
Definition duckdb.cpp:1379
vector< ColumnIndex > & bound_column_ids
A reference to the set of bound column ids.
Definition duckdb.cpp:1377
virtual_column_map_t virtual_columns
Virtual columns.
Definition duckdb.cpp:1381

Member Function Documentation

◆ ExpandGeneratedColumn()

unique_ptr< ParsedExpression > duckdb::TableBinding::ExpandGeneratedColumn ( const string & column_name)
385721 {
385722 auto catalog_entry = GetStandardEntry();
385723 D_ASSERT(catalog_entry); // Should only be called on a TableBinding
385724
385725 D_ASSERT(catalog_entry->type == CatalogType::TABLE_ENTRY);
385726 auto &table_entry = catalog_entry->Cast<TableCatalogEntry>();
385727
385728 // Get the index of the generated column
385729 auto column_index = GetBindingIndex(column_name);
385730 D_ASSERT(table_entry.GetColumn(LogicalIndex(column_index)).Generated());
385731 // Get a copy of the generated column
385732 auto expression = table_entry.GetColumn(LogicalIndex(column_index)).GeneratedExpression().Copy();
385733 unordered_map<idx_t, string> alias_map;
385734 for (auto &entry : name_map) {
385735 alias_map[entry.second] = entry.first;
385736 }
385737 ReplaceAliases(*expression, table_entry.GetColumns(), alias_map);
385738 BakeTableName(*expression, alias);
385739 return (expression);
385740}

◆ Bind()

BindResult duckdb::TableBinding::Bind ( ColumnRefExpression & colref,
idx_t depth )
overridevirtual

Reimplemented from duckdb::Binding.

385782 {
385783 auto &column_name = colref.GetColumnName();
385784 column_t column_index;
385785 bool success = false;
385786 success = TryGetBindingIndex(column_name, column_index);
385787 if (!success) {
385788 return BindResult(ColumnNotFoundError(column_name));
385789 }
385790 auto entry = GetStandardEntry();
385791 if (entry && !IsVirtualColumn(column_index)) {
385792 D_ASSERT(entry->type == CatalogType::TABLE_ENTRY);
385793 // Either there is no table, or the columns category has to be standard
385794 auto &table_entry = entry->Cast<TableCatalogEntry>();
385795 auto &column_entry = table_entry.GetColumn(LogicalIndex(column_index));
385796 (void)table_entry;
385797 (void)column_entry;
385798 D_ASSERT(column_entry.Category() == TableColumnType::STANDARD);
385799 }
385800 // fetch the type of the column
385801 LogicalType col_type;
385802 auto ventry = virtual_columns.find(column_index);
385803 if (ventry != virtual_columns.end()) {
385804 // virtual column - fetch type from there
385805 col_type = ventry->second.type;
385806 } else {
385807 // normal column: fetch type from base column
385808 col_type = types[column_index];
385809 if (colref.GetAlias().empty()) {
385810 colref.SetAlias(names[column_index]);
385811 }
385812 }
385813 ColumnBinding binding = GetColumnBinding(column_index);
385814 return BindResult(make_uniq<BoundColumnRefExpression>(colref.GetName(), col_type, binding, depth));
385815}
idx_t column_t
Type used for column identifiers.
Definition duckdb.hpp:259
vector< LogicalType > types
The types of the bound columns.
Definition duckdb.cpp:1345
vector< string > names
Column names of the subquery.
Definition duckdb.cpp:1347

◆ GetStandardEntry()

optional_ptr< StandardEntry > duckdb::TableBinding::GetStandardEntry ( )
overridevirtual

Reimplemented from duckdb::Binding.

385817 {
385818 return entry;
385819}

◆ ColumnNotFoundError()

ErrorData duckdb::TableBinding::ColumnNotFoundError ( const string & column_name) const
overridevirtual

Reimplemented from duckdb::Binding.

385821 {
385822 auto candidate_message = StringUtil::CandidatesErrorMessage(names, column_name, "Candidate bindings: ");
385823 return ErrorData(ExceptionType::BINDER, StringUtil::Format("Table \"%s\" does not have a column named \"%s\"\n%s",
385824 alias.GetAlias(), column_name, candidate_message));
385825}
static DUCKDB_API string CandidatesErrorMessage(const vector< string > &strings, const string &target, const string &message_prefix, idx_t n=5)
Definition duckdb.cpp:109926
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002

◆ GetBoundColumnIds()

const vector< ColumnIndex > & duckdb::TableBinding::GetBoundColumnIds ( ) const
385742 {
385743#ifdef DEBUG
385744 unordered_set<idx_t> column_ids;
385745 for (auto &col_id : bound_column_ids) {
385746 idx_t id = col_id.IsRowIdColumn() ? DConstants::INVALID_INDEX : col_id.GetPrimaryIndex();
385747 auto result = column_ids.insert(id);
385748 // assert that all entries in the bound_column_ids are unique
385749 D_ASSERT(result.second);
385750 auto it = std::find_if(name_map.begin(), name_map.end(),
385751 [&](const std::pair<const string, idx_t> &it) { return it.second == id; });
385752 // assert that every id appears in the name_map
385753 D_ASSERT(it != name_map.end());
385754 // the order that they appear in is not guaranteed to be sequential
385755 }
385756#endif
385757 return bound_column_ids;
385758}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ GetColumnBinding()

ColumnBinding duckdb::TableBinding::GetColumnBinding ( column_t column_index)
protected
385760 {
385761 auto &column_ids = bound_column_ids;
385762 ColumnBinding binding;
385763
385764 // Locate the column_id that matches the 'column_index'
385765 binding.column_index = column_ids.size();
385766 for (idx_t i = 0; i < column_ids.size(); ++i) {
385767 auto &col_id = column_ids[i];
385768 if (col_id.GetPrimaryIndex() == column_index) {
385769 binding.column_index = i;
385770 break;
385771 }
385772 }
385773 // If it wasn't found, add it
385774 if (binding.column_index == column_ids.size()) {
385775 column_ids.emplace_back(column_index);
385776 }
385777
385778 binding.table_index = index;
385779 return binding;
385780}

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