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

Classes

struct  CachedCollection

Public Member Functions

DUCKDB_API BatchedDataCollection (ClientContext &context, vector< LogicalType > types, ColumnDataAllocatorType allocator_type=ColumnDataAllocatorType::IN_MEMORY_ALLOCATOR, ColumnDataCollectionLifetime lifetime=ColumnDataCollectionLifetime::REGULAR)
DUCKDB_API BatchedDataCollection (ClientContext &context, vector< LogicalType > types, QueryResultMemoryType memory_type)
DUCKDB_API BatchedDataCollection (ClientContext &context, vector< LogicalType > types, batch_map_t batches, ColumnDataAllocatorType allocator_type=ColumnDataAllocatorType::IN_MEMORY_ALLOCATOR, ColumnDataCollectionLifetime lifetime=ColumnDataCollectionLifetime::REGULAR)
DUCKDB_API void Append (DataChunk &input, idx_t batch_index)
 Appends a datachunk with the given batch index to the batched collection.
DUCKDB_API void Merge (BatchedDataCollection &other)
 Merge the other batched chunk collection into this batched collection.
void InitializeScan (BatchedChunkScanState &state, const BatchedChunkIteratorRange &range)
DUCKDB_API void InitializeScan (BatchedChunkScanState &state)
 Initialize a scan over the batched chunk collection.
DUCKDB_API void Scan (BatchedChunkScanState &state, DataChunk &output)
 Scan a chunk from the batched chunk collection, in-order of batch index.
DUCKDB_API unique_ptr< ColumnDataCollection > FetchCollection ()
 Fetch a column data collection from the batched data collection - this consumes all of the data stored within.
DUCKDB_API idx_t Count () const
 Inspect how many tuples this batched data collection contains.
DUCKDB_API const vector< LogicalType > & Types () const
 Inspect the types of the collection.
DUCKDB_API idx_t BatchCount () const
 Inspect how many batches this collection contains.
DUCKDB_API idx_t IndexToBatchIndex (idx_t index) const
 Retrieve the batch index of the nth batch in the collection.
DUCKDB_API idx_t BatchSize (idx_t batch_index) const
 Inspect how big a given batch is.
const ColumnDataCollection & Batch (idx_t batch_index) const
 Inspect a given batch through a const reference.
BatchedChunkIteratorRange BatchRange (idx_t begin=0, idx_t end=DConstants::INVALID_INDEX)
 Create an iterator range from the provided indices.
DUCKDB_API string ToString () const
DUCKDB_API void Print () const

Private Member Functions

unique_ptr< ColumnDataCollection > CreateCollection () const

Private Attributes

ClientContext & context
vector< LogicalType > types
ColumnDataAllocatorType allocator_type
ColumnDataCollectionLifetime lifetime
map< idx_t, unique_ptr< ColumnDataCollection > > data
 The data of the batched chunk collection - a set of batch_index -> ColumnDataCollection pointers.
CachedCollection last_collection
 The last batch collection that was inserted into.

Detailed Description

A BatchedDataCollection holds a number of data entries that are partitioned by batch index Scans over a BatchedDataCollection are ordered by batch index

Constructor & Destructor Documentation

◆ BatchedDataCollection() [1/3]

duckdb::BatchedDataCollection::BatchedDataCollection ( ClientContext & context,
vector< LogicalType > types,
ColumnDataAllocatorType allocator_type = ColumnDataAllocatorType::IN_MEMORY_ALLOCATOR,
ColumnDataCollectionLifetime lifetime = ColumnDataCollectionLifetime::REGULAR )
112137 : context(context_p), types(std::move(types_p)), allocator_type(allocator_type_p), lifetime(lifetime_p) {
112138}

◆ BatchedDataCollection() [2/3]

duckdb::BatchedDataCollection::BatchedDataCollection ( ClientContext & context,
vector< LogicalType > types,
QueryResultMemoryType memory_type )
112142 : BatchedDataCollection(context, std::move(types),
112143 memory_type == QueryResultMemoryType::BUFFER_MANAGED
112146 memory_type == QueryResultMemoryType::BUFFER_MANAGED
112149}
@ BUFFER_MANAGER_ALLOCATOR
Use a buffer manager to allocate large chunks of memory that vectors then use.
Definition duckdb.hpp:18799
@ IN_MEMORY_ALLOCATOR
Definition duckdb.hpp:18802
@ THROW_ERROR_AFTER_DATABASE_CLOSES
Definition duckdb.hpp:18822
@ REGULAR
Regular lifetime management.
Definition duckdb.hpp:18819

◆ BatchedDataCollection() [3/3]

duckdb::BatchedDataCollection::BatchedDataCollection ( ClientContext & context,
vector< LogicalType > types,
batch_map_t batches,
ColumnDataAllocatorType allocator_type = ColumnDataAllocatorType::IN_MEMORY_ALLOCATOR,
ColumnDataCollectionLifetime lifetime = ColumnDataCollectionLifetime::REGULAR )
112154 : context(context_p), types(std::move(types_p)), allocator_type(allocator_type_p), lifetime(lifetime_p),
112155 data(std::move(batches)) {
112156}
map< idx_t, unique_ptr< ColumnDataCollection > > data
The data of the batched chunk collection - a set of batch_index -> ColumnDataCollection pointers.
Definition duckdb.cpp:35246

Member Function Documentation

◆ Append()

void duckdb::BatchedDataCollection::Append ( DataChunk & input,
idx_t batch_index )

Appends a datachunk with the given batch index to the batched collection.

112172 {
112173 D_ASSERT(batch_index != DConstants::INVALID_INDEX);
112174 optional_ptr<ColumnDataCollection> collection;
112175 if (last_collection.collection && last_collection.batch_index == batch_index) {
112176 // we are inserting into the same collection as before: use it directly
112177 collection = last_collection.collection;
112178 } else {
112179 // new collection: check if there is already an entry
112180 D_ASSERT(data.find(batch_index) == data.end());
112181 unique_ptr<ColumnDataCollection> new_collection = CreateCollection();
112182 last_collection.collection = new_collection.get();
112183 last_collection.batch_index = batch_index;
112184 new_collection->InitializeAppend(last_collection.append_state);
112185 collection = new_collection.get();
112186 data.insert(make_pair(batch_index, std::move(new_collection)));
112187 }
112188 collection->Append(last_collection.append_state, input);
112189}
CachedCollection last_collection
The last batch collection that was inserted into.
Definition duckdb.cpp:35248
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117
Here is the caller graph for this function:

◆ Merge()

void duckdb::BatchedDataCollection::Merge ( BatchedDataCollection & other)

Merge the other batched chunk collection into this batched collection.

112191 {
112192 for (auto &entry : other.data) {
112193 if (data.find(entry.first) != data.end()) {
112194 throw InternalException(
112195 "BatchedDataCollection::Merge error - batch index %d is present in both collections. This occurs when "
112196 "batch indexes are not uniquely distributed over threads",
112197 entry.first);
112198 }
112199 data[entry.first] = std::move(entry.second);
112200 }
112201 other.data.clear();
112202}

◆ InitializeScan() [1/2]

void duckdb::BatchedDataCollection::InitializeScan ( BatchedChunkScanState & state,
const BatchedChunkIteratorRange & range )
112204 {
112205 state.range = range;
112206 if (state.range.begin == state.range.end) {
112207 return;
112208 }
112209 state.range.begin->second->InitializeScan(state.scan_state);
112210}

◆ InitializeScan() [2/2]

void duckdb::BatchedDataCollection::InitializeScan ( BatchedChunkScanState & state)

Initialize a scan over the batched chunk collection.

112212 {
112213 auto range = BatchRange();
112214 return InitializeScan(state, range);
112215}
BatchedChunkIteratorRange BatchRange(idx_t begin=0, idx_t end=DConstants::INVALID_INDEX)
Create an iterator range from the provided indices.
Definition duckdb.cpp:112292
Here is the call graph for this function:

◆ Scan()

void duckdb::BatchedDataCollection::Scan ( BatchedChunkScanState & state,
DataChunk & output )

Scan a chunk from the batched chunk collection, in-order of batch index.

112217 {
112218 while (state.range.begin != state.range.end) {
112219 // check if there is a chunk remaining in this collection
112220 auto collection = state.range.begin->second.get();
112221 collection->Scan(state.scan_state, output);
112222 if (output.size() > 0) {
112223 return;
112224 }
112225 // there isn't! move to the next collection
112226 state.range.begin->second.reset();
112227 state.range.begin++;
112228 if (state.range.begin == state.range.end) {
112229 return;
112230 }
112231 state.range.begin->second->InitializeScan(state.scan_state);
112232 }
112233}

◆ FetchCollection()

unique_ptr< ColumnDataCollection > duckdb::BatchedDataCollection::FetchCollection ( )

Fetch a column data collection from the batched data collection - this consumes all of the data stored within.

112235 {
112236 unique_ptr<ColumnDataCollection> result;
112237 for (auto &entry : data) {
112238 if (!result) {
112239 result = std::move(entry.second);
112240 } else {
112241 result->Combine(*entry.second);
112242 }
112243 }
112244 data.clear();
112245 if (!result) {
112246 // empty result
112247 return CreateCollection();
112248 }
112249 return result;
112250}

◆ Count()

idx_t duckdb::BatchedDataCollection::Count ( ) const

Inspect how many tuples this batched data collection contains.

112256 {
112257 idx_t count = 0;
112258 for (auto &collection : data) {
112259 count += collection.second->Count();
112260 }
112261 return count;
112262}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the caller graph for this function:

◆ Types()

const vector< LogicalType > & duckdb::BatchedDataCollection::Types ( ) const

Inspect the types of the collection.

112252 {
112253 return types;
112254}

◆ BatchCount()

idx_t duckdb::BatchedDataCollection::BatchCount ( ) const

Inspect how many batches this collection contains.

112264 {
112265 return data.size();
112266}

◆ IndexToBatchIndex()

idx_t duckdb::BatchedDataCollection::IndexToBatchIndex ( idx_t index) const

Retrieve the batch index of the nth batch in the collection.

112268 {
112269 if (index >= data.size()) {
112270 throw InternalException("Index %d is out of range for this collection, it only contains %d batches", index,
112271 data.size());
112272 }
112273 auto entry = data.begin();
112274 std::advance(entry, index);
112275 return entry->first;
112276}

◆ BatchSize()

idx_t duckdb::BatchedDataCollection::BatchSize ( idx_t batch_index) const

Inspect how big a given batch is.

112278 {
112279 auto &collection = Batch(batch_index);
112280 return collection.Count();
112281}
const ColumnDataCollection & Batch(idx_t batch_index) const
Inspect a given batch through a const reference.
Definition duckdb.cpp:112283
Here is the call graph for this function:

◆ Batch()

const ColumnDataCollection & duckdb::BatchedDataCollection::Batch ( idx_t batch_index) const

Inspect a given batch through a const reference.

112283 {
112284 auto entry = data.find(batch_index);
112285 if (entry == data.end()) {
112286 throw InternalException("This batched data collection does not contain a collection for batch_index %d",
112287 batch_index);
112288 }
112289 return *entry->second;
112290}
Here is the caller graph for this function:

◆ BatchRange()

BatchedChunkIteratorRange duckdb::BatchedDataCollection::BatchRange ( idx_t begin = 0,
idx_t end = DConstants::INVALID_INDEX )

Create an iterator range from the provided indices.

112292 {
112293 D_ASSERT(begin_idx < end_idx);
112294 if (end_idx > data.size()) {
112295 // Limit the iterator to the end
112296 end_idx = DConstants::INVALID_INDEX;
112297 }
112298 BatchedChunkIteratorRange range;
112299 range.begin = data.begin();
112300 std::advance(range.begin, begin_idx);
112301 if (end_idx == DConstants::INVALID_INDEX) {
112302 range.end = data.end();
112303 } else {
112304 range.end = data.begin();
112305 std::advance(range.end, end_idx);
112306 }
112307 return range;
112308}
Here is the caller graph for this function:

◆ ToString()

string duckdb::BatchedDataCollection::ToString ( ) const
112310 {
112311 string result;
112312 result += "Batched Data Collection\n";
112313 for (auto &entry : data) {
112314 result += "Batch Index - " + to_string(entry.first) + "\n";
112315 result += entry.second->ToString() + "\n\n";
112316 }
112317 return result;
112318}
std::string to_string(const T &value)
Definition duckdb.cpp:19425

◆ Print()

void duckdb::BatchedDataCollection::Print ( ) const
112320 {
112321 Printer::Print(ToString());
112322}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.
Definition duckdb.cpp:92556

◆ CreateCollection()

unique_ptr< ColumnDataCollection > duckdb::BatchedDataCollection::CreateCollection ( ) const
private
112158 {
112159 if (last_collection.collection) {
112160 return make_uniq<ColumnDataCollection>(*last_collection.collection);
112161 } else if (allocator_type == ColumnDataAllocatorType::BUFFER_MANAGER_ALLOCATOR) {
112162 auto &buffer_manager = lifetime == ColumnDataCollectionLifetime::REGULAR
112163 ? BufferManager::GetBufferManager(context)
112164 : BufferManager::GetBufferManager(*context.db);
112165 return make_uniq<ColumnDataCollection>(buffer_manager, types, lifetime);
112166 } else {
112167 D_ASSERT(allocator_type == ColumnDataAllocatorType::IN_MEMORY_ALLOCATOR);
112168 return make_uniq<ColumnDataCollection>(Allocator::DefaultAllocator(), types);
112169 }
112170}
db

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