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

Classes

class  UnionIterator

Public Types

using SortedTable = PhysicalRangeJoin::GlobalSortedTable
using ChunkRange = std::pair<idx_t, idx_t>
using next_row_t = bool (duckdb::IEJoinUnion::*)()

Public Member Functions

 IEJoinUnion (IEJoinGlobalSourceState &gsource, const ChunkRange &chunks)
idx_t SearchL1 (idx_t pos)
template<SortKeyType SORT_KEY_TYPE>
bool NextRow ()
idx_t JoinComplexBlocks (unsafe_vector< idx_t > &lsel, unsafe_vector< idx_t > &rsel)
 Inverted loop.

Static Public Member Functions

static bool IsStrictComparison (ExpressionType comparison)
template<typename T>
static bool Compare (const T &lhs, const T &rhs, const bool strict)
static idx_t AppendKey (ExecutionContext &context, InterruptState &interrupt, SortedTable &table, ExpressionExecutor &executor, SortedTable &marked, int64_t increment, int64_t rid, const ChunkRange &range)
template<typename T, typename VECTOR_TYPE = T>
static void ExtractColumn (SortedTable &table, idx_t col_idx, unsafe_vector< T > &result)

Public Attributes

next_row_t next_row_func
IEJoinGlobalSourceState & gsource
 Constructor arguments.
vector< validity_t > bit_array
 B.
ValidityMask bit_mask
idx_t bloom_count
vector< validity_t > bloom_array
ValidityMask bloom_filter
idx_t n
 Iteration state.
idx_t i
idx_t n_j
idx_t j
unique_ptr< UnionIterator > op2
unique_ptr< UnionIterator > off2
int64_t lrid

Static Public Attributes

static constexpr idx_t BLOOM_CHUNK_BITS = 1024
 Bloom Filter.

Constructor & Destructor Documentation

◆ IEJoinUnion()

duckdb::IEJoinUnion::IEJoinUnion ( IEJoinGlobalSourceState & gsource,
const ChunkRange & chunks )
186637 : gsource(gsource), n(0), i(0) {
186638 auto &op = gsource.op;
186639
186640 // 7. initialize bit-array B (|B| = n), and set all bits to 0
186641 auto &l2 = *gsource.l2;
186642 n_j = l2.count.load();
186643 bit_array.resize(ValidityMask::EntryCount(n_j), 0);
186644 bit_mask.Initialize(bit_array.data(), n_j);
186645
186646 // Bloom filter
186647 bloom_count = (n_j + (BLOOM_CHUNK_BITS - 1)) / BLOOM_CHUNK_BITS;
186648 bloom_array.resize(ValidityMask::EntryCount(bloom_count), 0);
186649 bloom_filter.Initialize(bloom_array.data(), bloom_count);
186650
186651 // 11. for(i←1 to n) do
186652 const auto strict2 = IsStrictComparison(op.conditions[1].comparison);
186653 op2 = make_uniq<UnionIterator>(l2, strict2);
186654 off2 = make_uniq<UnionIterator>(l2, strict2);
186655 n = l2.BlockStart(chunks.second);
186656 i = l2.BlockStart(chunks.first);
186657 j = i;
186658
186659 const auto sort_key_type = l2.GetSortKeyType();
186660 switch (sort_key_type) {
186662 next_row_func = &IEJoinUnion::NextRow<SortKeyType::NO_PAYLOAD_FIXED_8>;
186663 break;
186664 case SortKeyType::NO_PAYLOAD_FIXED_16:
186665 next_row_func = &IEJoinUnion::NextRow<SortKeyType::NO_PAYLOAD_FIXED_16>;
186666 break;
186667 case SortKeyType::NO_PAYLOAD_FIXED_24:
186668 next_row_func = &IEJoinUnion::NextRow<SortKeyType::NO_PAYLOAD_FIXED_24>;
186669 break;
186670 case SortKeyType::NO_PAYLOAD_FIXED_32:
186671 next_row_func = &IEJoinUnion::NextRow<SortKeyType::NO_PAYLOAD_FIXED_32>;
186672 break;
186673 case SortKeyType::NO_PAYLOAD_VARIABLE_32:
186674 next_row_func = &IEJoinUnion::NextRow<SortKeyType::NO_PAYLOAD_VARIABLE_32>;
186675 break;
186677 next_row_func = &IEJoinUnion::NextRow<SortKeyType::PAYLOAD_FIXED_16>;
186678 break;
186679 case SortKeyType::PAYLOAD_FIXED_24:
186680 next_row_func = &IEJoinUnion::NextRow<SortKeyType::PAYLOAD_FIXED_24>;
186681 break;
186682 case SortKeyType::PAYLOAD_FIXED_32:
186683 next_row_func = &IEJoinUnion::NextRow<SortKeyType::PAYLOAD_FIXED_32>;
186684 break;
186685 case SortKeyType::PAYLOAD_VARIABLE_32:
186686 next_row_func = &IEJoinUnion::NextRow<SortKeyType::PAYLOAD_VARIABLE_32>;
186687 break;
186688 default:
186689 throw NotImplementedException("IEJoinUnion for %s", EnumUtil::ToString(sort_key_type));
186690 }
186691
186692 (this->*next_row_func)();
186693}
@ NO_PAYLOAD_FIXED_8
Without payload.
Definition duckdb.cpp:55338
@ PAYLOAD_FIXED_16
With payload (requires row pointer in key).
Definition duckdb.cpp:55344
idx_t n
Iteration state.
Definition duckdb.cpp:186551
vector< validity_t > bit_array
B.
Definition duckdb.cpp:186542
IEJoinGlobalSourceState & gsource
Constructor arguments.
Definition duckdb.cpp:186536
static constexpr idx_t BLOOM_CHUNK_BITS
Bloom Filter.
Definition duckdb.cpp:186545

Member Function Documentation

◆ IsStrictComparison()

bool duckdb::IEJoinUnion::IsStrictComparison ( ExpressionType comparison)
inlinestatic
186440 {
186441 switch (comparison) {
186442 case ExpressionType::COMPARE_LESSTHAN:
186443 case ExpressionType::COMPARE_GREATERTHAN:
186444 return true;
186445 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
186446 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
186447 return false;
186448 default:
186449 throw InternalException("Unimplemented comparison type for IEJoin!");
186450 }
186451 }

◆ Compare()

template<typename T>
bool duckdb::IEJoinUnion::Compare ( const T & lhs,
const T & rhs,
const bool strict )
inlinestatic
186454 {
186455 const bool less_than = lhs < rhs;
186456 if (!less_than && !strict) {
186457 return !(rhs < lhs);
186458 }
186459 return less_than;
186460 }

◆ AppendKey()

idx_t duckdb::IEJoinUnion::AppendKey ( ExecutionContext & context,
InterruptState & interrupt,
SortedTable & table,
ExpressionExecutor & executor,
SortedTable & marked,
int64_t increment,
int64_t rid,
const ChunkRange & range )
static
186562 {
186563 const auto chunk_begin = chunk_range.first;
186564 const auto chunk_end = chunk_range.second;
186565
186566 if (chunk_begin == chunk_end) {
186567 return 0;
186568 }
186569
186570 // Reading
186571 const auto valid = table.count - table.has_null;
186572 auto &source = *table.sorted->payload_data;
186573 TupleDataScanState scanner;
186574 source.InitializeScan(scanner);
186575
186576 DataChunk scanned;
186577 source.InitializeScanChunk(scanner, scanned);
186578 idx_t table_idx = source.Seek(scanner, chunk_begin);
186579
186580 // Writing
186581 auto &sort = *marked.sort;
186582 auto local_sort_state = sort.GetLocalSinkState(context);
186583 vector<LogicalType> types;
186584 for (const auto &expr : executor.expressions) {
186585 types.emplace_back(expr->return_type);
186586 }
186587 const idx_t rid_idx = types.size();
186588 types.emplace_back(LogicalType::BIGINT);
186589
186590 DataChunk keys;
186591 DataChunk payload;
186592 keys.Initialize(Allocator::DefaultAllocator(), types);
186593
186594 OperatorSinkInput sink {*marked.global_sink, *local_sort_state, interrupt};
186595 idx_t inserted = 0;
186596 for (auto chunk_idx = chunk_begin; chunk_idx < chunk_end; ++chunk_idx) {
186597 source.Scan(scanner, scanned);
186598
186599 // NULLs are at the end, so stop when we reach them
186600 auto scan_count = scanned.size();
186601 if (table_idx + scan_count > valid) {
186602 if (table_idx >= valid) {
186603 scan_count = 0;
186604 ;
186605 } else {
186606 scan_count = valid - table_idx;
186607 scanned.SetCardinality(scan_count);
186608 }
186609 }
186610 if (scan_count == 0) {
186611 break;
186612 }
186613 table_idx += scan_count;
186614
186615 // Compute the input columns from the payload
186616 keys.Reset();
186617 keys.Split(payload, rid_idx);
186618 executor.Execute(scanned, keys);
186619
186620 // Mark the rid column
186621 payload.data[0].Sequence(rid, increment, scan_count);
186622 payload.SetCardinality(scan_count);
186623 keys.Fuse(payload);
186624 rid += increment * UnsafeNumericCast<int64_t>(scan_count);
186625
186626 // Sort on the sort columns (which will no longer be needed)
186627 sort.Sink(context, keys, sink);
186628 inserted += scan_count;
186629 }
186630 OperatorSinkCombineInput combine {*marked.global_sink, *local_sort_state, interrupt};
186631 sort.Combine(context, combine);
186632 marked.count += inserted;
186633
186634 return inserted;
186635}
DUCKDB_API void Fuse(DataChunk &other)
Fuses a DataChunk onto the right of this one, and destroys the other. Inverse of Split.
Definition duckdb.cpp:116937
DUCKDB_API void Split(DataChunk &other, idx_t split_idx)
Splits the DataChunk in two.
Definition duckdb.cpp:116920
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
void sort(InputArray src, OutputArray dst, int flags)
cv::GKernelPackage combine(const cv::GKernelPackage &lhs, const cv::GKernelPackage &rhs)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ExtractColumn()

template<typename T, typename VECTOR_TYPE = T>
void duckdb::IEJoinUnion::ExtractColumn ( SortedTable & table,
idx_t col_idx,
unsafe_vector< T > & result )
inlinestatic
186467 {
186468 result.clear();
186469 result.reserve(table.count);
186470
186471 auto &collection = *table.sorted->payload_data;
186472 vector<column_t> scan_ids(1, col_idx);
186473 TupleDataScanState state;
186474 collection.InitializeScan(state, scan_ids);
186475
186476 DataChunk payload;
186477 collection.InitializeScanChunk(state, payload);
186478
186479 while (collection.Scan(state, payload)) {
186480 const auto count = payload.size();
186481 const auto data_ptr = reinterpret_cast<T *>(FlatVector::GetData<VECTOR_TYPE>(payload.data[0]));
186482 result.insert(result.end(), data_ptr, data_ptr + count);
186483 }
186484 }

◆ NextRow()

template<SortKeyType SORT_KEY_TYPE>
bool duckdb::IEJoinUnion::NextRow ( )
186696 {
186697 using SORT_KEY = SortKey<SORT_KEY_TYPE>;
186698 using BLOCKS_ITERATOR = block_iterator_t<ExternalBlockIteratorState, SORT_KEY>;
186699
186700 BLOCKS_ITERATOR off2_itr(*off2->state);
186701 BLOCKS_ITERATOR op2_itr(*op2->state);
186702 const auto strict = off2->strict;
186703
186704 auto &li = gsource.li;
186705 auto &p = gsource.p;
186706
186707 auto pinned_idx = off2->GetChunkIndex();
186708 for (; i < n; ++i) {
186709 // 12. pos ← P[i]
186710 auto pos = p[i];
186711 lrid = li[pos];
186712 if (lrid < 0) {
186713 continue;
186714 }
186715
186716 // 16. B[pos] ← 1
186717 op2->SetIndex(i);
186718 for (; off2->GetIndex() < n_j; ++(*off2)) {
186719 // Prevent buildup of pinned blocks
186720 if (off2->GetChunkIndex() != pinned_idx) {
186721 off2->Repin();
186722 pinned_idx = off2->GetChunkIndex();
186723 }
186724 if (!Compare(off2_itr[off2->GetIndex()], op2_itr[op2->GetIndex()], strict)) {
186725 break;
186726 }
186727 const auto p2 = p[off2->GetIndex()];
186728 if (li[p2] < 0) {
186729 // Only mark rhs matches.
186730 bit_mask.SetValidUnsafe(p2);
186731 bloom_filter.SetValidUnsafe(p2 / BLOOM_CHUNK_BITS);
186732 }
186733 }
186734
186735 // 9. if (op1 ∈ {≤,≥} and op2 ∈ {≤,≥}) eqOff = 0
186736 // 10. else eqOff = 1
186737 // No, because there could be more than one equal value.
186738 // Find the leftmost off1 where L1[pos] op1 L1[off1..n]
186739 // These are the rows that satisfy the op1 condition
186740 // and that is where we should start scanning B from
186741 j = pos;
186742
186743 return true;
186744 }
186745 return false;
186746}

◆ JoinComplexBlocks()

idx_t duckdb::IEJoinUnion::JoinComplexBlocks ( unsafe_vector< idx_t > & lsel,
unsafe_vector< idx_t > & rsel )

Inverted loop.

186803 {
186804 const auto &li = gsource.li;
186805
186806 // Release pinned blocks
186807 op2->Repin();
186808 off2->Repin();
186809
186810 // 8. initialize join result as an empty list for tuple pairs
186811 idx_t result_count = 0;
186812
186813 lsel.resize(STANDARD_VECTOR_SIZE);
186814 rsel.resize(STANDARD_VECTOR_SIZE);
186815
186816 // 11. for(i←1 to n) do
186817 while (i < n) {
186818 // 13. for (j ← pos+eqOff to n) do
186819 for (;;) {
186820 // 14. if B[j] = 1 then
186821
186822 // Use the Bloom filter to find candidate blocks
186823 while (j < n_j) {
186824 auto bloom_begin = NextValid(bloom_filter, j / BLOOM_CHUNK_BITS, bloom_count) * BLOOM_CHUNK_BITS;
186825 auto bloom_end = MinValue<idx_t>(n_j, bloom_begin + BLOOM_CHUNK_BITS);
186826
186827 j = MaxValue<idx_t>(j, bloom_begin);
186828 j = NextValid(bit_mask, j, bloom_end);
186829 if (j < bloom_end) {
186830 break;
186831 }
186832 }
186833
186834 if (j >= n_j) {
186835 break;
186836 }
186837
186838 // Filter out tuples with the same sign (they come from the same table)
186839 const auto rrid = li[j];
186840 ++j;
186841
186842 D_ASSERT(lrid > 0 && rrid < 0);
186843 // 15. add tuples w.r.t. (L1[j], L1[i]) to join result
186844 lsel[result_count] = static_cast<idx_t>(+lrid - 1);
186845 rsel[result_count] = static_cast<idx_t>(-rrid - 1);
186846 ++result_count;
186847 if (result_count == STANDARD_VECTOR_SIZE) {
186848 // out of space!
186849 return result_count;
186850 }
186851 }
186852 ++i;
186853
186854 if (!(this->*next_row_func)()) {
186855 break;
186856 }
186857 }
186858
186859 lsel.resize(result_count);
186860 rsel.resize(result_count);
186861
186862 return result_count;
186863}

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