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

Public Member Functions

 LocalSortedTable (ExecutionContext &context, GlobalSortedTable &global_table, const idx_t child)
void Sink (ExecutionContext &context, DataChunk &input)

Public Attributes

GlobalSortedTable & global_table
 The global table we are connected to.
unique_ptr< LocalSinkState > local_sink
 The local sort state.
ExpressionExecutor executor
 Local copy of the sorting expression executor.
DataChunk keys
 Holds a vector of incoming sorting columns.
DataChunk sort_chunk
 The sort data.
idx_t has_null
 The number of NULL values.
idx_t count
 The total number of rows.

Private Member Functions

idx_t MergeNulls (Vector &primary, const vector< JoinCondition > &conditions)

Constructor & Destructor Documentation

◆ LocalSortedTable()

duckdb::PhysicalRangeJoin::LocalSortedTable::LocalSortedTable ( ExecutionContext & context,
GlobalSortedTable & global_table,
const idx_t child )
189844 : global_table(global_table), executor(context.client), has_null(0), count(0) {
189845 // Initialize order clause expression executor and key DataChunk
189846 const auto &op = global_table.op;
189847 vector<LogicalType> types;
189848 for (const auto &cond : op.conditions) {
189849 const auto &expr = child ? cond.right : cond.left;
189850 executor.AddExpression(*expr);
189851
189852 types.push_back(expr->return_type);
189853 }
189854 auto &allocator = Allocator::Get(context.client);
189855 keys.Initialize(allocator, types);
189856
189857 local_sink = global_table.sort->GetLocalSinkState(context);
189858
189859 // Only sort the primary key
189860 types.resize(1);
189861 const auto &payload_types = op.children[child].get().types;
189862 types.insert(types.end(), payload_types.begin(), payload_types.end());
189863 sort_chunk.InitializeEmpty(types);
189864}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
unique_ptr< LocalSinkState > local_sink
The local sort state.
Definition duckdb.cpp:185877
ExpressionExecutor executor
Local copy of the sorting expression executor.
Definition duckdb.cpp:185879
idx_t has_null
The number of NULL values.
Definition duckdb.cpp:185885
DataChunk keys
Holds a vector of incoming sorting columns.
Definition duckdb.cpp:185881
GlobalSortedTable & global_table
The global table we are connected to.
Definition duckdb.cpp:185875
DataChunk sort_chunk
The sort data.
Definition duckdb.cpp:185883
idx_t count
The total number of rows.
Definition duckdb.cpp:185887

Member Function Documentation

◆ Sink()

void duckdb::PhysicalRangeJoin::LocalSortedTable::Sink ( ExecutionContext & context,
DataChunk & input )
189866 {
189867 // Obtain sorting columns
189868 keys.Reset();
189869 executor.Execute(input, keys);
189870
189871 // Do not operate on primary key directly to avoid modifying the input chunk
189872 Vector primary = keys.data[0];
189873 // Count the NULLs so we can exclude them later
189874 has_null += MergeNulls(primary, global_table.op.conditions);
189875 count += keys.size();
189876
189877 // Only sort the primary key
189878 sort_chunk.data[0].Reference(primary);
189879 for (column_t col_idx = 0; col_idx < input.ColumnCount(); ++col_idx) {
189880 sort_chunk.data[col_idx + 1].Reference(input.data[col_idx]);
189881 }
189882 sort_chunk.SetCardinality(input);
189883
189884 // Sink the data into the local sort state
189885 InterruptState interrupt;
189886 OperatorSinkInput sink {*global_table.global_sink, *local_sink, interrupt};
189887 global_table.sort->Sink(context, sort_chunk, sink);
189888}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
idx_t column_t
Type used for column identifiers.
Definition duckdb.hpp:259

◆ MergeNulls()

idx_t duckdb::PhysicalRangeJoin::LocalSortedTable::MergeNulls ( Vector & primary,
const vector< JoinCondition > & conditions )
private
190124 {
190125 // Merge the validity masks of the comparison keys into the primary
190126 // Return the number of NULLs in the resulting chunk
190127 D_ASSERT(keys.ColumnCount() > 0);
190128 const auto count = keys.size();
190129
190130 size_t all_constant = 0;
190131 for (auto &v : keys.data) {
190132 if (v.GetVectorType() == VectorType::CONSTANT_VECTOR) {
190133 ++all_constant;
190134 }
190135 }
190136
190137 if (all_constant == keys.data.size()) {
190138 // Either all NULL or no NULLs
190139 if (ConstantVector::IsNull(primary)) {
190140 // Primary is already NULL
190141 return count;
190142 }
190143 for (size_t c = 1; c < keys.data.size(); ++c) {
190144 // Skip comparisons that accept NULLs
190145 if (conditions[c].comparison == ExpressionType::COMPARE_DISTINCT_FROM) {
190146 continue;
190147 }
190148 auto &v = keys.data[c];
190149 if (ConstantVector::IsNull(v)) {
190150 // Create a new validity mask to avoid modifying original mask
190151 auto &pvalidity = ConstantVector::Validity(primary);
190152 ValidityMask pvalidity_copy = ConstantVector::Validity(primary);
190153 pvalidity.Copy(pvalidity_copy, count);
190154 ConstantVector::SetNull(primary, true);
190155 return count;
190156 }
190157 }
190158 return 0;
190159 } else if (keys.ColumnCount() > 1) {
190160 // Flatten the primary, as it will need to merge arbitrary validity masks
190161 primary.Flatten(count);
190162 auto &pvalidity = FlatVector::Validity(primary);
190163 // Make a copy of validity to avoid modifying original mask
190164 ValidityMask pvalidity_copy = FlatVector::Validity(primary);
190165 pvalidity.Copy(pvalidity_copy, count);
190166
190167 D_ASSERT(keys.ColumnCount() == conditions.size());
190168 for (size_t c = 1; c < keys.data.size(); ++c) {
190169 // Skip comparisons that accept NULLs
190170 if (conditions[c].comparison == ExpressionType::COMPARE_DISTINCT_FROM) {
190171 continue;
190172 }
190173 // ToUnifiedFormat the rest, as the sort code will do this anyway.
190174 auto &v = keys.data[c];
190175 UnifiedVectorFormat vdata;
190176 v.ToUnifiedFormat(count, vdata);
190177 auto &vvalidity = vdata.validity;
190178 if (vvalidity.AllValid()) {
190179 continue;
190180 }
190181 pvalidity.EnsureWritable();
190182 switch (v.GetVectorType()) {
190183 case VectorType::FLAT_VECTOR: {
190184 // Merge entire entries
190185 auto pmask = pvalidity.GetData();
190186 const auto entry_count = pvalidity.EntryCount(count);
190187 for (idx_t entry_idx = 0; entry_idx < entry_count; ++entry_idx) {
190188 pmask[entry_idx] &= vvalidity.GetValidityEntry(entry_idx);
190189 }
190190 break;
190191 }
190192 case VectorType::CONSTANT_VECTOR:
190193 // All or nothing
190194 if (ConstantVector::IsNull(v)) {
190195 pvalidity.SetAllInvalid(count);
190196 return count;
190197 }
190198 break;
190199 default:
190200 // One by one
190201 for (idx_t i = 0; i < count; ++i) {
190202 const auto idx = vdata.sel->get_index(i);
190203 if (!vvalidity.RowIsValidUnsafe(idx)) {
190204 pvalidity.SetInvalidUnsafe(i);
190205 }
190206 }
190207 break;
190208 }
190209 }
190210 return count - pvalidity.CountValid(count);
190211 } else {
190212 return count - VectorOperations::CountNotNull(primary, count);
190213 }
190214}
uint32_t v
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static idx_t CountNotNull(Vector &input, const idx_t count)
Count the number of not-NULL values.
Definition duckdb.cpp:143370

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