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

Public Member Functions

 PlanSignatureTableIndexMap (ArenaAllocator &allocator_p)
const arena_unordered_map< idx_t, PlanSignatureColumnIndexMap > & GetMap () const
template<ConversionType TYPE>
bool Convert (LogicalOperator &op)

Private Member Functions

template<ConversionType TYPE>
void Initialize (LogicalOperator &op)
template<ConversionType TYPE>
void ConvertTableIndices (LogicalOperator &op)
template<ConversionType TYPE>
void ConvertProjectionMaps (LogicalOperator &op)
template<ConversionType TYPE>
void ConvertTableIndex (idx_t &table_index, const idx_t i)
template<ConversionType TYPE>
bool ConvertColumnIndices (LogicalOperator &op)
template<ConversionType TYPE>
void ConvertChildren (LogicalOperator &op)
template<ConversionType TYPE>
bool ConvertExpressions (LogicalOperator &op)

Private Attributes

ArenaAllocator & allocator
 For batching allocations.
arena_unordered_map< idx_t, PlanSignatureColumnIndexMap > table_index_map
 Map from original table index to column index map.
arena_unordered_map< idx_t, idx_t > to_canonical_table_index
 Temporary map from original table index to canonical table index (and reverse).
arena_unordered_map< idx_t, idx_t > restore_original_table_index
vector< idx_t > table_indices
 Temporary vector to store table indices.
vector< vector< idx_t > > projection_maps
 Temporary vector to store projection maps.
vector< ColumnIndex > column_ids
 Utility to temporarily store column ids, projection_ids, table indices, expression info and children.
vector< idx_t > projection_ids
vector< pair< string, optional_idx > > expression_info
vector< unique_ptr< LogicalOperator > > children

Static Private Attributes

static constexpr idx_t CANONICAL_TABLE_INDEX_OFFSET = 10000000000000
 Offset for table index conversion.

Constructor & Destructor Documentation

◆ PlanSignatureTableIndexMap()

duckdb::PlanSignatureTableIndexMap::PlanSignatureTableIndexMap ( ArenaAllocator & allocator_p)
inlineexplicit
304492 restore_original_table_index(allocator) {
304493 }
ArenaAllocator & allocator
For batching allocations.
Definition duckdb.cpp:304784
arena_unordered_map< idx_t, idx_t > to_canonical_table_index
Temporary map from original table index to canonical table index (and reverse).
Definition duckdb.cpp:304790
arena_unordered_map< idx_t, PlanSignatureColumnIndexMap > table_index_map
Map from original table index to column index map.
Definition duckdb.cpp:304787

Member Function Documentation

◆ GetMap()

const arena_unordered_map< idx_t, PlanSignatureColumnIndexMap > & duckdb::PlanSignatureTableIndexMap::GetMap ( ) const
inline
304496 {
304497 return table_index_map;
304498 }

◆ Convert()

template<ConversionType TYPE>
bool duckdb::PlanSignatureTableIndexMap::Convert ( LogicalOperator & op)
inline
304501 {
304502 Initialize<TYPE>(op);
304503 ConvertTableIndices<TYPE>(op);
304504 ConvertProjectionMaps<TYPE>(op);
304505 auto can_materialize = ConvertColumnIndices<TYPE>(op);
304506 ConvertChildren<TYPE>(op);
304507 return ConvertExpressions<TYPE>(op) && can_materialize;
304508 }

◆ Initialize()

template<ConversionType TYPE>
void duckdb::PlanSignatureTableIndexMap::Initialize ( LogicalOperator & op)
inlineprivate
304512 {
304513 if (TYPE == ConversionType::TO_CANONICAL) {
304514 // Clear temporary data structures
304515 to_canonical_table_index.clear();
304516 restore_original_table_index.clear();
304517 column_ids.clear();
304518 projection_ids.clear();
304519 table_indices.clear();
304520 projection_maps.clear();
304521 expression_info.clear();
304522
304523 // Store temporary mapping
304524 for (const auto &child_op : op.children) {
304525 for (const auto &child_cb : child_op->GetColumnBindings()) {
304526 const auto &original = child_cb.table_index;
304527 auto it = to_canonical_table_index.find(original);
304528 if (it != to_canonical_table_index.end()) {
304529 continue; // We've seen this table index before
304530 }
304532 D_ASSERT(to_canonical_table_index.find(original) == to_canonical_table_index.end());
304533 D_ASSERT(restore_original_table_index.find(canonical) == restore_original_table_index.end());
304534 to_canonical_table_index.emplace(make_pair(original, canonical));
304535 restore_original_table_index.emplace(make_pair(canonical, original));
304536 }
304537 }
304538 }
304539 }
static constexpr idx_t CANONICAL_TABLE_INDEX_OFFSET
Offset for table index conversion.
Definition duckdb.cpp:304781
vector< vector< idx_t > > projection_maps
Temporary vector to store projection maps.
Definition duckdb.cpp:304795
vector< ColumnIndex > column_ids
Utility to temporarily store column ids, projection_ids, table indices, expression info and children.
Definition duckdb.cpp:304798
vector< idx_t > table_indices
Temporary vector to store table indices.
Definition duckdb.cpp:304793
cv::String canonical(const cv::String &path)

◆ ConvertTableIndices()

template<ConversionType TYPE>
void duckdb::PlanSignatureTableIndexMap::ConvertTableIndices ( LogicalOperator & op)
inlineprivate
304542 {
304543#ifdef D_ASSERT_IS_ENABLED
304544 const auto table_indices_verification = op.GetTableIndex();
304545#endif
304546 switch (op.type) {
304547 case LogicalOperatorType::LOGICAL_GET:
304548 ConvertTableIndex<TYPE>(op.Cast<LogicalGet>().table_index, 0);
304549 break;
304550 case LogicalOperatorType::LOGICAL_CHUNK_GET:
304551 ConvertTableIndex<TYPE>(op.Cast<LogicalColumnDataGet>().table_index, 0);
304552 break;
304553 case LogicalOperatorType::LOGICAL_EXPRESSION_GET:
304554 ConvertTableIndex<TYPE>(op.Cast<LogicalExpressionGet>().table_index, 0);
304555 break;
304556 case LogicalOperatorType::LOGICAL_DUMMY_SCAN:
304557 ConvertTableIndex<TYPE>(op.Cast<LogicalDummyScan>().table_index, 0);
304558 break;
304559 case LogicalOperatorType::LOGICAL_CTE_REF:
304560 ConvertTableIndex<TYPE>(op.Cast<LogicalCTERef>().table_index, 0);
304561 break;
304562 case LogicalOperatorType::LOGICAL_PROJECTION:
304563 ConvertTableIndex<TYPE>(op.Cast<LogicalProjection>().table_index, 0);
304564 break;
304565 case LogicalOperatorType::LOGICAL_PIVOT:
304566 ConvertTableIndex<TYPE>(op.Cast<LogicalPivot>().pivot_index, 0);
304567 break;
304568 case LogicalOperatorType::LOGICAL_UNNEST:
304569 ConvertTableIndex<TYPE>(op.Cast<LogicalUnnest>().unnest_index, 0);
304570 break;
304571 case LogicalOperatorType::LOGICAL_WINDOW:
304572 ConvertTableIndex<TYPE>(op.Cast<LogicalWindow>().window_index, 0);
304573 break;
304574 case LogicalOperatorType::LOGICAL_AGGREGATE_AND_GROUP_BY: {
304575 auto &aggr = op.Cast<LogicalAggregate>();
304576 ConvertTableIndex<TYPE>(aggr.group_index, 0);
304577 ConvertTableIndex<TYPE>(aggr.aggregate_index, 1);
304578 if (aggr.groupings_index != DConstants::INVALID_INDEX) {
304579 ConvertTableIndex<TYPE>(aggr.groupings_index, 2);
304580 }
304581 break;
304582 }
304583 case LogicalOperatorType::LOGICAL_ANY_JOIN:
304584 case LogicalOperatorType::LOGICAL_COMPARISON_JOIN: {
304585 auto &join = op.Cast<LogicalJoin>();
304586 if (join.join_type == JoinType::MARK) {
304587 ConvertTableIndex<TYPE>(join.mark_index, 0);
304588 }
304589 break;
304590 }
304591 case LogicalOperatorType::LOGICAL_UNION:
304592 case LogicalOperatorType::LOGICAL_EXCEPT:
304593 case LogicalOperatorType::LOGICAL_INTERSECT:
304594 ConvertTableIndex<TYPE>(op.Cast<LogicalSetOperation>().table_index, 0);
304595 break;
304596 default:
304597 break;
304598 }
304599#ifdef D_ASSERT_IS_ENABLED
304600 if (TYPE == ConversionType::TO_CANONICAL) {
304601 D_ASSERT(table_indices == table_indices_verification);
304602 }
304603#endif
304604 }
cv::String join(const cv::String &base, const cv::String &path)
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ ConvertProjectionMaps()

template<ConversionType TYPE>
void duckdb::PlanSignatureTableIndexMap::ConvertProjectionMaps ( LogicalOperator & op)
inlineprivate
304607 {
304608 switch (op.type) {
304609 case LogicalOperatorType::LOGICAL_ANY_JOIN:
304610 case LogicalOperatorType::LOGICAL_COMPARISON_JOIN: {
304611 auto &join = op.Cast<LogicalJoin>();
304612 if (TYPE == ConversionType::TO_CANONICAL) {
304613 D_ASSERT(projection_maps.empty());
304614 projection_maps.push_back(std::move(join.left_projection_map));
304615 projection_maps.push_back(std::move(join.right_projection_map));
304616 } else {
304617 D_ASSERT(TYPE == ConversionType::RESTORE_ORIGINAL);
304618 D_ASSERT(!projection_maps.empty());
304619 join.left_projection_map = std::move(projection_maps[0]);
304620 join.right_projection_map = std::move(projection_maps[1]);
304621 }
304622 break;
304623 }
304624 case LogicalOperatorType::LOGICAL_FILTER: {
304625 auto &filter = op.Cast<LogicalFilter>();
304626 if (TYPE == ConversionType::TO_CANONICAL) {
304627 D_ASSERT(projection_maps.empty());
304628 projection_maps.push_back(std::move(filter.projection_map));
304629 } else {
304630 D_ASSERT(TYPE == ConversionType::RESTORE_ORIGINAL);
304631 D_ASSERT(!projection_maps.empty());
304632 filter.projection_map = std::move(projection_maps[0]);
304633 }
304634 break;
304635 }
304636 case LogicalOperatorType::LOGICAL_ORDER_BY: {
304637 auto &order = op.Cast<LogicalOrder>();
304638 if (TYPE == ConversionType::TO_CANONICAL) {
304639 D_ASSERT(projection_maps.empty());
304640 projection_maps.push_back(std::move(order.projection_map));
304641 } else {
304642 D_ASSERT(TYPE == ConversionType::RESTORE_ORIGINAL);
304643 D_ASSERT(!projection_maps.empty());
304644 order.projection_map = std::move(projection_maps[0]);
304645 }
304646 break;
304647 }
304648 default:
304649 break;
304650 }
304651 }
void filter(InputArray image, InputArray kernel, OutputArray output)

◆ ConvertTableIndex()

template<ConversionType TYPE>
void duckdb::PlanSignatureTableIndexMap::ConvertTableIndex ( idx_t & table_index,
const idx_t i )
inlineprivate
304654 {
304655 switch (TYPE) {
304656 case ConversionType::TO_CANONICAL:
304657 D_ASSERT(table_indices.size() == i);
304658 D_ASSERT(table_index_map.find(table_index) == table_index_map.end());
304659 table_index_map.emplace(table_index, PlanSignatureColumnIndexMap(allocator));
304660 table_indices.emplace_back(table_index);
304661 table_index = CANONICAL_TABLE_INDEX_OFFSET + to_canonical_table_index.size() + i;
304662 break;
304663 case ConversionType::RESTORE_ORIGINAL:
304664 table_index = table_indices[i];
304665 break;
304666 }
304667 }

◆ ConvertColumnIndices()

template<ConversionType TYPE>
bool duckdb::PlanSignatureTableIndexMap::ConvertColumnIndices ( LogicalOperator & op)
inlineprivate
304670 {
304671 if (op.type == LogicalOperatorType::LOGICAL_GET) {
304672 auto &get = op.Cast<LogicalGet>();
304673 switch (TYPE) {
304674 case ConversionType::TO_CANONICAL: {
304675 D_ASSERT(column_ids.empty());
304676 // Grab selected GET columns and populate with all possible columns
304677 column_ids = std::move(get.GetMutableColumnIds());
304678 for (idx_t col_idx = 0; col_idx < get.names.size(); col_idx++) {
304679 get.GetMutableColumnIds().push_back(ColumnIndex(col_idx));
304680 }
304681 for (const auto &vc : get.virtual_columns) {
304682 get.GetMutableColumnIds().push_back(ColumnIndex(vc.first));
304683 }
304684
304685 // Also temporarily don't project any columns out
304686 projection_ids = std::move(get.projection_ids);
304687
304688 // FIXME: can probably work for nested columns in the future
304689 for (const auto &col_id : column_ids) {
304690 if (col_id.IsVirtualColumn() || col_id.HasChildren()) {
304691 return false;
304692 }
304693 }
304694
304695 // Store mapping for base tables
304696 auto &column_index_map = table_index_map.at(table_indices[0]);
304697 if (projection_ids.empty()) {
304698 for (idx_t col_idx = 0; col_idx < column_ids.size(); col_idx++) {
304699 const auto primary_index = column_ids[col_idx].GetPrimaryIndex();
304700 column_index_map.Insert(col_idx, primary_index);
304701 }
304702 } else {
304703 for (const auto &proj_id : projection_ids) {
304704 const auto primary_index = column_ids[proj_id].GetPrimaryIndex();
304705 column_index_map.Insert(proj_id, primary_index);
304706 }
304707 }
304708 break;
304709 }
304710 case ConversionType::RESTORE_ORIGINAL:
304711 D_ASSERT(!column_ids.empty());
304712 get.GetMutableColumnIds() = std::move(column_ids);
304713 D_ASSERT(get.projection_ids.empty());
304714 get.projection_ids = std::move(projection_ids);
304715 break;
304716 }
304717 }
304718 return true;
304719 }
__host__ cudaTextureObject_t get() const noexcept
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ConvertChildren()

template<ConversionType TYPE>
void duckdb::PlanSignatureTableIndexMap::ConvertChildren ( LogicalOperator & op)
inlineprivate
304722 {
304723 switch (TYPE) {
304724 case ConversionType::TO_CANONICAL:
304725 D_ASSERT(children.empty());
304726 children = std::move(op.children);
304727 break;
304728 case ConversionType::RESTORE_ORIGINAL:
304729 D_ASSERT(op.children.empty());
304730 op.children = std::move(children);
304731 break;
304732 }
304733 }

◆ ConvertExpressions()

template<ConversionType TYPE>
bool duckdb::PlanSignatureTableIndexMap::ConvertExpressions ( LogicalOperator & op)
inlineprivate
304736 {
304737 const auto &table_index_mapping =
304738 TYPE == ConversionType::TO_CANONICAL ? to_canonical_table_index : restore_original_table_index;
304739 bool can_materialize = true;
304740 idx_t info_idx = 0;
304741 LogicalOperatorVisitor::EnumerateExpressions(op, [&](unique_ptr<Expression> *expr) {
304742 ExpressionIterator::EnumerateExpression(*expr, [&](unique_ptr<Expression> &child) {
304743 // Replace column binding
304744 if (child->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) {
304745 auto &column_binding = child->Cast<BoundColumnRefExpression>().binding;
304746 const auto lookup_idx = TYPE == ConversionType::TO_CANONICAL
304747 ? column_binding.table_index
304748 : restore_original_table_index.at(column_binding.table_index);
304749 auto &table_map = table_index_map.at(lookup_idx);
304750 if (!table_map.Empty<TYPE>()) {
304751 // Replace column index
304752 column_binding.column_index = table_map.Get<TYPE>(column_binding.column_index);
304753 }
304754 // Replace table index
304755 column_binding.table_index = table_index_mapping.at(column_binding.table_index);
304756 }
304757
304758 // Replace default fields
304759 switch (TYPE) {
304760 case ConversionType::TO_CANONICAL:
304761 expression_info.emplace_back(std::move(child->alias), child->query_location);
304762 child->alias.clear();
304763 child->query_location.SetInvalid();
304764 break;
304765 case ConversionType::RESTORE_ORIGINAL:
304766 auto &info = expression_info[info_idx++];
304767 child->alias = std::move(info.first);
304768 child->query_location = info.second;
304769 break;
304770 }
304771 if (child->IsVolatile()) {
304772 can_materialize = false;
304773 }
304774 });
304775 });
304776 return can_materialize;
304777 }
TYPE

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