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

Dependency Manager local to a table, responsible for keeping track of generated column dependencies. More...

Collaboration diagram for duckdb::ColumnDependencyManager:

Public Member Functions

 ColumnDependencyManager (ColumnDependencyManager &&other)=default
 
 ColumnDependencyManager (const ColumnDependencyManager &other)=delete
 
stack< LogicalIndexGetBindOrder (const ColumnList &columns)
 Get the bind order that ensures dependencies are resolved before dependents are.
 
void AddGeneratedColumn (LogicalIndex index, const vector< LogicalIndex > &indices, bool root=true)
 Adds a connection between the dependent and its dependencies.
 
void AddGeneratedColumn (const ColumnDefinition &column, const ColumnList &list)
 Add a generated column from a column definition.
 
vector< LogicalIndexRemoveColumn (LogicalIndex index, idx_t column_amount)
 Removes the column(s) and outputs the new column indices.
 
bool IsDependencyOf (LogicalIndex dependent, LogicalIndex dependency) const
 
bool HasDependencies (LogicalIndex index) const
 
const logical_index_set_t & GetDependencies (LogicalIndex index) const
 
bool HasDependents (LogicalIndex index) const
 
const logical_index_set_t & GetDependents (LogicalIndex index) const
 

Private Member Functions

void RemoveStandardColumn (LogicalIndex index)
 
void RemoveGeneratedColumn (LogicalIndex index)
 
void AdjustSingle (LogicalIndex idx, idx_t offset)
 
vector< LogicalIndexCleanupInternals (idx_t column_amount)
 

Private Attributes

logical_index_map_t< logical_index_set_t > dependencies_map
 A map of column dependency to generated column(s)
 
logical_index_map_t< logical_index_set_t > dependents_map
 A map of generated column name to (potentially generated)column dependencies.
 
logical_index_map_t< logical_index_set_t > direct_dependencies
 For resolve-order purposes, keep track of the 'direct' (not inherited) dependencies of a generated column.
 
logical_index_set_t deleted_columns
 

Detailed Description

Dependency Manager local to a table, responsible for keeping track of generated column dependencies.

Constructor & Destructor Documentation

◆ ColumnDependencyManager()

duckdb::ColumnDependencyManager::ColumnDependencyManager ( )
8426 {
8427}

◆ ~ColumnDependencyManager()

duckdb::ColumnDependencyManager::~ColumnDependencyManager ( )
8429 {
8430}

Member Function Documentation

◆ GetBindOrder()

stack< LogicalIndex > duckdb::ColumnDependencyManager::GetBindOrder ( const ColumnList columns)

Get the bind order that ensures dependencies are resolved before dependents are.

Skip the dependents that are also dependencies

If this column does not have dependencies, the queue stops getting filled

8638 {
8639 stack<LogicalIndex> bind_order;
8640 queue<LogicalIndex> to_visit;
8641 logical_index_set_t visited;
8642
8643 for (auto &entry : direct_dependencies) {
8644 auto dependent = entry.first;
8646 if (dependencies_map.find(dependent) != dependencies_map.end()) {
8647 continue;
8648 }
8649 bind_order.push(dependent);
8650 visited.insert(dependent);
8651 for (auto &dependency : direct_dependencies[dependent]) {
8652 to_visit.push(dependency);
8653 }
8654 }
8655
8656 while (!to_visit.empty()) {
8657 auto column = to_visit.front();
8658 to_visit.pop();
8659
8661 if (direct_dependencies.find(column) == direct_dependencies.end()) {
8662 continue;
8663 }
8664 bind_order.push(column);
8665 visited.insert(column);
8666
8667 for (auto &dependency : direct_dependencies[column]) {
8668 to_visit.push(dependency);
8669 }
8670 }
8671
8672 // Add generated columns that have no dependencies, but still might need to have their type resolved
8673 for (auto &col : columns.Logical()) {
8674 // Not a generated column
8675 if (!col.Generated()) {
8676 continue;
8677 }
8678 // Already added to the bind_order stack
8679 if (visited.count(col.Logical())) {
8680 continue;
8681 }
8682 bind_order.push(col.Logical());
8683 }
8684
8685 return bind_order;
8686}
logical_index_map_t< logical_index_set_t > direct_dependencies
For resolve-order purposes, keep track of the 'direct' (not inherited) dependencies of a generated co...
Definition duckdb.cpp:2693
logical_index_map_t< logical_index_set_t > dependencies_map
A map of column dependency to generated column(s)
Definition duckdb.cpp:2689

◆ AddGeneratedColumn() [1/2]

void duckdb::ColumnDependencyManager::AddGeneratedColumn ( LogicalIndex  index,
const vector< LogicalIndex > &  indices,
bool  root = true 
)

Adds a connection between the dependent and its dependencies.

8447 {
8448 if (indices.empty()) {
8449 return;
8450 }
8451 auto &list = dependents_map[index];
8452 // Create a link between the dependencies
8453 for (auto &dep : indices) {
8454 // Add this column as a dependency of the new column
8455 list.insert(dep);
8456 // Add the new column as a dependent of the column
8457 dependencies_map[dep].insert(index);
8458 // Inherit the dependencies
8459 if (HasDependencies(dep)) {
8460 auto &inherited_deps = dependents_map[dep];
8461 D_ASSERT(!inherited_deps.empty());
8462 for (auto &inherited_dep : inherited_deps) {
8463 list.insert(inherited_dep);
8464 dependencies_map[inherited_dep].insert(index);
8465 }
8466 }
8467 if (!root) {
8468 continue;
8469 }
8470 direct_dependencies[index].insert(dep);
8471 }
8472 if (!HasDependents(index)) {
8473 return;
8474 }
8475 auto &dependents = dependencies_map[index];
8476 if (dependents.count(index)) {
8477 throw InvalidInputException("Circular dependency encountered when resolving generated column expressions");
8478 }
8479 // Also let the dependents of this generated column inherit the dependencies
8480 for (auto &dependent : dependents) {
8481 AddGeneratedColumn(dependent, indices, false);
8482 }
8483}
logical_index_map_t< logical_index_set_t > dependents_map
A map of generated column name to (potentially generated)column dependencies.
Definition duckdb.cpp:2691
void AddGeneratedColumn(LogicalIndex index, const vector< LogicalIndex > &indices, bool root=true)
Adds a connection between the dependent and its dependencies.
Definition duckdb.cpp:8447
index
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddGeneratedColumn() [2/2]

void duckdb::ColumnDependencyManager::AddGeneratedColumn ( const ColumnDefinition column,
const ColumnList list 
)

Add a generated column from a column definition.

8432 {
8433 D_ASSERT(column.Generated());
8434 vector<string> referenced_columns;
8435 column.GetListOfDependencies(referenced_columns);
8436 vector<LogicalIndex> indices;
8437 for (auto &col : referenced_columns) {
8438 if (!list.ColumnExists(col)) {
8439 throw BinderException("Column \"%s\" referenced by generated column does not exist", col);
8440 }
8441 auto &entry = list.GetColumn(col);
8442 indices.push_back(entry.Logical());
8443 }
8444 return AddGeneratedColumn(column.Logical(), indices);
8445}
Here is the call graph for this function:

◆ RemoveColumn()

vector< LogicalIndex > duckdb::ColumnDependencyManager::RemoveColumn ( LogicalIndex  index,
idx_t  column_amount 
)

Removes the column(s) and outputs the new column indices.

8485 {
8486 // Always add the initial column
8487 deleted_columns.insert(index);
8488
8489 RemoveGeneratedColumn(index);
8490 RemoveStandardColumn(index);
8491
8492 // Clean up the internal list
8493 vector<LogicalIndex> new_indices = CleanupInternals(column_amount);
8494 D_ASSERT(deleted_columns.empty());
8495 return new_indices;
8496}

◆ IsDependencyOf()

bool duckdb::ColumnDependencyManager::IsDependencyOf ( LogicalIndex  dependent,
LogicalIndex  dependency 
) const
8498 {
8499 auto entry = dependents_map.find(gcol);
8500 if (entry == dependents_map.end()) {
8501 return false;
8502 }
8503 auto &list = entry->second;
8504 return list.count(col);
8505}

◆ HasDependencies()

bool duckdb::ColumnDependencyManager::HasDependencies ( LogicalIndex  index) const
8507 {
8508 auto entry = dependents_map.find(index);
8509 if (entry == dependents_map.end()) {
8510 return false;
8511 }
8512 return true;
8513}

◆ GetDependencies()

const logical_index_set_t & duckdb::ColumnDependencyManager::GetDependencies ( LogicalIndex  index) const
8515 {
8516 auto entry = dependents_map.find(index);
8517 D_ASSERT(entry != dependents_map.end());
8518 return entry->second;
8519}

◆ HasDependents()

bool duckdb::ColumnDependencyManager::HasDependents ( LogicalIndex  index) const
8521 {
8522 auto entry = dependencies_map.find(index);
8523 if (entry == dependencies_map.end()) {
8524 return false;
8525 }
8526 return true;
8527}

◆ GetDependents()

const logical_index_set_t & duckdb::ColumnDependencyManager::GetDependents ( LogicalIndex  index) const
8529 {
8530 auto entry = dependencies_map.find(index);
8531 D_ASSERT(entry != dependencies_map.end());
8532 return entry->second;
8533}

◆ RemoveStandardColumn()

void duckdb::ColumnDependencyManager::RemoveStandardColumn ( LogicalIndex  index)
private
8535 {
8536 if (!HasDependents(index)) {
8537 return;
8538 }
8539 auto dependents = dependencies_map[index];
8540 for (auto &gcol : dependents) {
8541 // If index is a direct dependency of gcol, remove it from the list
8542 if (direct_dependencies.find(gcol) != direct_dependencies.end()) {
8543 direct_dependencies[gcol].erase(index);
8544 }
8545 RemoveGeneratedColumn(gcol);
8546 }
8547 // Remove this column from the dependencies map
8548 dependencies_map.erase(index);
8549}

◆ RemoveGeneratedColumn()

void duckdb::ColumnDependencyManager::RemoveGeneratedColumn ( LogicalIndex  index)
private
8551 {
8552 deleted_columns.insert(index);
8553 if (!HasDependencies(index)) {
8554 return;
8555 }
8556 auto &dependencies = dependents_map[index];
8557 for (auto &col : dependencies) {
8558 // Remove this generated column from the list of this column
8559 auto &col_dependents = dependencies_map[col];
8560 D_ASSERT(col_dependents.count(index));
8561 col_dependents.erase(index);
8562 // If the resulting list is empty, remove the column from the dependencies map altogether
8563 if (col_dependents.empty()) {
8564 dependencies_map.erase(col);
8565 }
8566 }
8567 // Remove this column from the dependents_map map
8568 dependents_map.erase(index);
8569}

◆ AdjustSingle()

void duckdb::ColumnDependencyManager::AdjustSingle ( LogicalIndex  idx,
idx_t  offset 
)
private
8571 {
8572 D_ASSERT(idx.index >= offset);
8573 LogicalIndex new_idx = LogicalIndex(idx.index - offset);
8574 // Adjust this index in the dependents of this column
8575 bool has_dependents = HasDependents(idx);
8576 bool has_dependencies = HasDependencies(idx);
8577
8578 if (has_dependents) {
8579 auto &dependents = GetDependents(idx);
8580 for (auto &dep : dependents) {
8581 auto &dep_dependencies = dependents_map[dep];
8582 dep_dependencies.erase(idx);
8583 D_ASSERT(!dep_dependencies.count(new_idx));
8584 dep_dependencies.insert(new_idx);
8585 }
8586 }
8587 if (has_dependencies) {
8588 auto &dependencies = GetDependencies(idx);
8589 for (auto &dep : dependencies) {
8590 auto &dep_dependents = dependencies_map[dep];
8591 dep_dependents.erase(idx);
8592 D_ASSERT(!dep_dependents.count(new_idx));
8593 dep_dependents.insert(new_idx);
8594 }
8595 }
8596 if (has_dependents) {
8597 D_ASSERT(!dependencies_map.count(new_idx));
8598 dependencies_map[new_idx] = std::move(dependencies_map[idx]);
8599 dependencies_map.erase(idx);
8600 }
8601 if (has_dependencies) {
8602 D_ASSERT(!dependents_map.count(new_idx));
8603 dependents_map[new_idx] = std::move(dependents_map[idx]);
8604 dependents_map.erase(idx);
8605 }
8606}

◆ CleanupInternals()

vector< LogicalIndex > duckdb::ColumnDependencyManager::CleanupInternals ( idx_t  column_amount)
private
8608 {
8609 vector<LogicalIndex> to_adjust;
8610 D_ASSERT(!deleted_columns.empty());
8611 // Get the lowest index that was deleted
8612 vector<LogicalIndex> new_indices(column_amount, LogicalIndex(DConstants::INVALID_INDEX));
8613 idx_t threshold = deleted_columns.begin()->index;
8614
8615 idx_t offset = 0;
8616 for (idx_t i = 0; i < column_amount; i++) {
8617 auto current_index = LogicalIndex(i);
8618 auto new_index = LogicalIndex(i - offset);
8619 new_indices[i] = new_index;
8620 if (deleted_columns.count(current_index)) {
8621 offset++;
8622 continue;
8623 }
8624 if (i > threshold && (HasDependencies(current_index) || HasDependents(current_index))) {
8625 to_adjust.push_back(current_index);
8626 }
8627 }
8628
8629 // Adjust all indices inside the dependency managers internal mappings
8630 for (auto &col : to_adjust) {
8631 auto offset = col.index - new_indices[col.index].index;
8632 AdjustSingle(col, offset);
8633 }
8634 deleted_columns.clear();
8635 return new_indices;
8636}
GMat threshold(const GMat &src, const GScalar &thresh, const GScalar &maxval, int type)
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: