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

Public Member Functions

 CompressedStringScanState (BufferHandle &&handle_p)
 CompressedStringScanState (BufferHandle &handle_p)
void Initialize (ColumnSegment &segment, bool initialize_dictionary=true)
void ScanToFlatVector (Vector &result, idx_t result_offset, idx_t start, idx_t scan_count)
void ScanToDictionaryVector (ColumnSegment &segment, Vector &result, idx_t result_offset, idx_t start, idx_t scan_count)
Public Member Functions inherited from duckdb::SegmentScanState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

BufferHandle owned_handle
optional_ptr< BufferHandle > handle
bitpacking_width_t current_width
buffer_ptr< SelectionVector > sel_vec
idx_t sel_vec_size = 0
data_ptr_t baseptr
 Start of the block (pointing to the dictionary_header).
data_ptr_t base_data
 Start of the data (pointing to the start of the selection buffer).
uint32_t * index_buffer_ptr
uint32_t index_buffer_count
buffer_ptr< VectorChildBuffer > dictionary
idx_t dictionary_size
StringDictionaryContainer dict
idx_t block_size
Public Attributes inherited from duckdb::StringScanState
BufferHandle handle

Private Member Functions

string_t FetchStringFromDict (int32_t dict_offset, uint16_t string_len)
uint16_t GetStringLength (sel_t index)

Constructor & Destructor Documentation

◆ CompressedStringScanState() [1/2]

duckdb::CompressedStringScanState::CompressedStringScanState ( BufferHandle && handle_p)
inlineexplicit
400212 : StringScanState(), owned_handle(std::move(handle_p)), handle(owned_handle) {
400213 }

◆ CompressedStringScanState() [2/2]

duckdb::CompressedStringScanState::CompressedStringScanState ( BufferHandle & handle_p)
inlineexplicit
400214 : StringScanState(), owned_handle(), handle(handle_p) {
400215 }

Member Function Documentation

◆ Initialize()

void duckdb::CompressedStringScanState::Initialize ( ColumnSegment & segment,
bool initialize_dictionary = true )
400275 {
400276 baseptr = handle->Ptr() + segment.GetBlockOffset();
400277
400278 // Load header values
400279 auto header_ptr = reinterpret_cast<dictionary_compression_header_t *>(baseptr);
400280 auto index_buffer_offset = Load<uint32_t>(data_ptr_cast(&header_ptr->index_buffer_offset));
400281 index_buffer_count = Load<uint32_t>(data_ptr_cast(&header_ptr->index_buffer_count));
400282 current_width = (bitpacking_width_t)(Load<uint32_t>(data_ptr_cast(&header_ptr->bitpacking_width)));
400283 if (segment.GetBlockOffset() + index_buffer_offset + sizeof(uint32_t) * index_buffer_count >
400284 segment.GetBlockSize()) {
400285 throw IOException(
400286 "Failed to scan dictionary string - index was out of range. Database file appears to be corrupted.");
400287 }
400288 index_buffer_ptr = reinterpret_cast<uint32_t *>(baseptr + index_buffer_offset);
400290
400291 block_size = segment.GetBlockSize();
400292
400293 dict = DictionaryCompression::GetDictionary(segment, *handle);
400294 if (!initialize_dictionary) {
400295 // Used by fetch, as fetch will never produce a DictionaryVector
400296 return;
400297 }
400298
400299 dictionary = DictionaryVector::CreateReusableDictionary(segment.type, index_buffer_count);
400300 dictionary_size = index_buffer_count;
400301 auto dict_child_data = FlatVector::GetData<string_t>(dictionary->data);
400302 FlatVector::SetNull(dictionary->data, 0, true);
400303 for (uint32_t i = 1; i < index_buffer_count; i++) {
400304 // NOTE: the passing of dict_child_vector, will not be used, its for big strings
400305 uint16_t str_len = GetStringLength(i);
400306 dict_child_data[i] = FetchStringFromDict(UnsafeNumericCast<int32_t>(index_buffer_ptr[i]), str_len);
400307 }
400308}
::uint32_t uint32_t
::uint16_t uint16_t
data_ptr_t base_data
Start of the data (pointing to the start of the selection buffer).
Definition duckdb.cpp:400238
data_ptr_t baseptr
Start of the block (pointing to the dictionary_header).
Definition duckdb.cpp:400236
static constexpr uint16_t DICTIONARY_HEADER_SIZE
Dictionary header size at the beginning of the string segment (offset + length).
Definition duckdb.cpp:399725

◆ ScanToFlatVector()

void duckdb::CompressedStringScanState::ScanToFlatVector ( Vector & result,
idx_t result_offset,
idx_t start,
idx_t scan_count )
400310 {
400311 auto result_data = FlatVector::GetData<string_t>(result);
400312
400313 // Handling non-bitpacking-group-aligned start values;
400314 idx_t start_offset = start % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE;
400315
400316 // We will scan in blocks of BITPACKING_ALGORITHM_GROUP_SIZE, so we may scan some extra values.
400317 idx_t decompress_count = BitpackingPrimitives::RoundUpToAlgorithmGroupSize(scan_count + start_offset);
400318
400319 // Create a decompression buffer of sufficient size if we don't already have one.
400320 if (!sel_vec || sel_vec_size < decompress_count) {
400321 sel_vec_size = decompress_count;
400322 sel_vec = make_buffer<SelectionVector>(decompress_count);
400323 }
400324
400325 data_ptr_t src = &base_data[((start - start_offset) * current_width) / 8];
400326 sel_t *sel_vec_ptr = sel_vec->data();
400327
400328 BitpackingPrimitives::UnPackBuffer<sel_t>(data_ptr_cast(sel_vec_ptr), src, decompress_count, current_width);
400329
400330 for (idx_t i = 0; i < scan_count; i++) {
400331 // Lookup dict offset in index buffer
400332 auto string_number = sel_vec->get_index(i + start_offset);
400333 auto dict_offset = index_buffer_ptr[string_number];
400334 auto str_len = GetStringLength(UnsafeNumericCast<sel_t>(string_number));
400335 result_data[result_offset + i] = FetchStringFromDict(UnsafeNumericCast<int32_t>(dict_offset), str_len);
400336 }
400337}
uint32_t sel_t
Type used for the selection vector.
Definition duckdb.hpp:251
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ScanToDictionaryVector()

void duckdb::CompressedStringScanState::ScanToDictionaryVector ( ColumnSegment & segment,
Vector & result,
idx_t result_offset,
idx_t start,
idx_t scan_count )
400340 {
400341 D_ASSERT(scan_count == STANDARD_VECTOR_SIZE);
400342 D_ASSERT(result_offset == 0);
400343
400344 idx_t start_offset = start % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE;
400345 idx_t decompress_count = BitpackingPrimitives::RoundUpToAlgorithmGroupSize(scan_count + start_offset);
400346
400347 // Create a selection vector of sufficient size if we don't already have one.
400348 if (!sel_vec || sel_vec_size < decompress_count) {
400349 sel_vec_size = decompress_count;
400350 sel_vec = make_buffer<SelectionVector>(decompress_count);
400351 }
400352
400353 // Scanning 2048 values, emitting a dict vector
400354 data_ptr_t dst = data_ptr_cast(sel_vec->data());
400355 data_ptr_t src = data_ptr_cast(&base_data[((start - start_offset) * current_width) / 8]);
400356
400357 BitpackingPrimitives::UnPackBuffer<sel_t>(dst, src, decompress_count, current_width);
400358
400359 if (start_offset != 0) {
400360 for (idx_t i = 0; i < scan_count; i++) {
400361 sel_vec->set_index(i, sel_vec->get_index(i + start_offset));
400362 }
400363 }
400364
400365 result.Dictionary(dictionary, *sel_vec);
400366}

◆ FetchStringFromDict()

string_t duckdb::CompressedStringScanState::FetchStringFromDict ( int32_t dict_offset,
uint16_t string_len )
private
400261 {
400262 D_ASSERT(dict_offset >= 0 && dict_offset <= NumericCast<int32_t>(block_size));
400263 if (dict_offset == 0) {
400264 return string_t(nullptr, 0);
400265 }
400266
400267 // normal string: read string from this block
400268 auto dict_end = baseptr + dict.end;
400269 auto dict_pos = dict_end - dict_offset;
400270
400271 auto str_ptr = char_ptr_cast(dict_pos);
400272 return string_t(str_ptr, string_len);
400273}

◆ GetStringLength()

uint16_t duckdb::CompressedStringScanState::GetStringLength ( sel_t index)
private
400253 {
400254 if (index == 0) {
400255 return 0;
400256 } else {
400257 return UnsafeNumericCast<uint16_t>(index_buffer_ptr[index] - index_buffer_ptr[index - 1]);
400258 }
400259}

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