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

Public Member Functions

 CompressedStringScanState (ColumnSegment &segment, BufferHandle &&handle_p)
 CompressedStringScanState (ColumnSegment &segment, BufferHandle &handle_p)
void Initialize (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)
const SelectionVector & GetSelVec (idx_t start, idx_t scan_count)
void Select (Vector &result, idx_t start, const SelectionVector &sel, idx_t sel_count)
bool AllowDictionaryScan (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

ColumnSegment & segment
BufferHandle owned_handle
optional_ptr< BufferHandle > handle
DictFSSTMode mode
idx_t dictionary_size
uint32_t dict_count
bitpacking_width_t dictionary_indices_width
bitpacking_width_t string_lengths_width
buffer_ptr< SelectionVector > sel_vec
idx_t sel_vec_size = 0
uint32_t decompress_offset = 0
idx_t decompress_position = 0
vector< uint32_t > string_lengths
data_ptr_t baseptr
 Start of the block (pointing to the dictionary_header).
data_ptr_t dict_ptr
data_ptr_t dictionary_indices_ptr
data_ptr_t string_lengths_ptr
buffer_ptr< VectorChildBuffer > dictionary
void * decoder = nullptr
bool all_values_inlined = false
unsafe_unique_array< bool > filter_result

Private Member Functions

string_t FetchStringFromDict (Vector &result, uint32_t dict_offset, idx_t dict_idx)

Constructor & Destructor Documentation

◆ CompressedStringScanState() [1/2]

duckdb::dict_fsst::CompressedStringScanState::CompressedStringScanState ( ColumnSegment & segment,
BufferHandle && handle_p )
inline
399153 : segment(segment), owned_handle(std::move(handle_p)), handle(owned_handle) {
399154 }

◆ CompressedStringScanState() [2/2]

duckdb::dict_fsst::CompressedStringScanState::CompressedStringScanState ( ColumnSegment & segment,
BufferHandle & handle_p )
inline
399156 : segment(segment), owned_handle(), handle(handle_p) {
399157 }

◆ ~CompressedStringScanState()

duckdb::dict_fsst::CompressedStringScanState::~CompressedStringScanState ( )
override
399217 {
399218 delete reinterpret_cast<duckdb_fsst_decoder_t *>(decoder);
399219}

Member Function Documentation

◆ Initialize()

void duckdb::dict_fsst::CompressedStringScanState::Initialize ( bool initialize_dictionary = true)

We can uncompress during fetching, we need the length of the string inside the dictionary

399251 {
399252 baseptr = handle->Ptr() + segment.GetBlockOffset();
399253
399254 // Load header values
399255 auto header_ptr = reinterpret_cast<dict_fsst_compression_header_t *>(baseptr);
399256 mode = header_ptr->mode;
399257 if (mode >= DictFSSTMode::COUNT) {
399258 throw FatalException("This block was written with a mode that is not recognized by this version, highest "
399259 "available mode %d, found mode: %d",
399260 static_cast<uint8_t>(DictFSSTMode::COUNT), static_cast<uint8_t>(mode));
399261 }
399262
399263 dict_count = header_ptr->dict_count;
399264 auto symbol_table_size = header_ptr->symbol_table_size;
399265 dictionary_size = header_ptr->dict_size;
399266
399267 dictionary_indices_width =
399268 (bitpacking_width_t)(Load<uint8_t>(data_ptr_cast(&header_ptr->dictionary_indices_width)));
399269 string_lengths_width = (bitpacking_width_t)(Load<uint8_t>(data_ptr_cast(&header_ptr->string_lengths_width)));
399270
399271 auto string_lengths_space = BitpackingPrimitives::GetRequiredSize(dict_count, string_lengths_width);
399272 auto dictionary_indices_space =
399273 BitpackingPrimitives::GetRequiredSize(segment.count.load(), dictionary_indices_width);
399274
399276 auto symbol_table_dest = AlignValue<idx_t>(dictionary_dest + dictionary_size);
399277 auto string_lengths_dest = AlignValue<idx_t>(symbol_table_dest + symbol_table_size);
399278 auto dictionary_indices_dest = AlignValue<idx_t>(string_lengths_dest + string_lengths_space);
399279
399280 const auto total_space = segment.GetBlockOffset() + dictionary_indices_dest + dictionary_indices_space;
399281 if (total_space > segment.GetBlockSize()) {
399282 throw IOException(
399283 "Failed to scan dictionary string - index was out of range. Database file appears to be corrupted.");
399284 }
399285 dict_ptr = data_ptr_cast(baseptr + dictionary_dest);
399286 dictionary_indices_ptr = data_ptr_cast(baseptr + dictionary_indices_dest);
399287 string_lengths_ptr = data_ptr_cast(baseptr + string_lengths_dest);
399288
399289 switch (mode) {
399290 case DictFSSTMode::FSST_ONLY:
399291 case DictFSSTMode::DICT_FSST: {
399292 decoder = new duckdb_fsst_decoder_t;
399293 auto ret = duckdb_fsst_import(reinterpret_cast<duckdb_fsst_decoder_t *>(decoder), baseptr + symbol_table_dest);
399294 (void)(ret);
399295 D_ASSERT(ret != 0); // FIXME: the old code set the decoder to nullptr instead, why???
399296 break;
399297 }
399298 default:
399299 break;
399300 }
399301
399303 BitpackingPrimitives::UnPackBuffer<uint32_t>(data_ptr_cast(string_lengths.data()),
399304 data_ptr_cast(string_lengths_ptr), dict_count, string_lengths_width);
399305 if (!initialize_dictionary || mode == DictFSSTMode::FSST_ONLY) {
399306 // Used by fetch, as fetch will never produce a DictionaryVector
399307 return;
399308 }
399309
399310 dictionary = DictionaryVector::CreateReusableDictionary(segment.type, dict_count);
399311 auto dict_child_data = FlatVector::GetData<string_t>(dictionary->data);
399312 auto &validity = FlatVector::Validity(dictionary->data);
399313 D_ASSERT(dict_count >= 1);
399314 validity.SetInvalid(0);
399315
399316 auto &dict_data = dictionary->data;
399317 uint32_t offset = 0;
399318 for (uint32_t i = 0; i < dict_count; i++) {
399320 auto string_len = string_lengths[i];
399321 dict_child_data[i] = FetchStringFromDict(dict_data, offset, i);
399322 offset += string_len;
399323 }
399324}
::uint32_t uint32_t
::uint8_t uint8_t
static T AlignValue(T n)
Align value (ceiling) (not for pointer types).
Definition duckdb.hpp:2126
data_ptr_t baseptr
Start of the block (pointing to the dictionary_header).
Definition duckdb.cpp:399195
static constexpr uint16_t DICTIONARY_HEADER_SIZE
Dictionary header size at the beginning of the string segment (offset + length).
Definition duckdb.cpp:397835
Here is the call graph for this function:

◆ ScanToFlatVector()

void duckdb::dict_fsst::CompressedStringScanState::ScanToFlatVector ( Vector & result,
idx_t result_offset,
idx_t start,
idx_t scan_count )

(index 0 is reserved for NULL, which we don't have in this mode)

399359 {
399360 auto result_data = FlatVector::GetData<string_t>(result);
399361 auto &validity = FlatVector::Validity(result);
399362
399363 // Create a decompression buffer of sufficient size if we don't already have one.
399364 auto &selvec = GetSelVec(start, scan_count);
399365
399367 const idx_t start_offset = mode == DictFSSTMode::FSST_ONLY ? start + 1 : 0;
399368
399369 if (dictionary) {
399370 // We have prepared the full dictionary, we can reference these strings directly
399371 auto dictionary_values = FlatVector::GetData<string_t>(dictionary->data);
399372 for (idx_t i = 0; i < scan_count; i++) {
399373 // Lookup dict offset in index buffer
399374 auto string_number = selvec.get_index(i + start_offset);
399375 if (string_number == 0) {
399376 validity.SetInvalid(result_offset + i);
399377 }
399378 result_data[result_offset + i] = dictionary_values[string_number];
399379 }
399380 } else {
399381 for (idx_t i = 0; i < scan_count; i++) {
399382 // Lookup dict offset in index buffer
399383 auto string_number = selvec.get_index(start_offset + i);
399384 if (string_number == 0) {
399385 validity.SetInvalid(result_offset);
399386 }
399387 if (decompress_position > string_number) {
399388 throw InternalException("DICT_FSST: not performing a sequential scan?");
399389 }
399390 for (; decompress_position < string_number; decompress_position++) {
399391 decompress_offset += string_lengths[decompress_position];
399392 }
399393 result_data[result_offset + i] = FetchStringFromDict(result, decompress_offset, string_number);
399394 }
399395 }
399396 result.Verify(result_offset + scan_count);
399397}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ScanToDictionaryVector()

void duckdb::dict_fsst::CompressedStringScanState::ScanToDictionaryVector ( ColumnSegment & segment,
Vector & result,
idx_t result_offset,
idx_t start,
idx_t scan_count )
399431 {
399432 D_ASSERT(scan_count == STANDARD_VECTOR_SIZE);
399433 D_ASSERT(result_offset == 0);
399434
399435 auto &selvec = GetSelVec(start, scan_count);
399436 result.Dictionary(dictionary, selvec);
399437 result.Verify(result_offset + scan_count);
399438}

◆ GetSelVec()

const SelectionVector & duckdb::dict_fsst::CompressedStringScanState::GetSelVec ( idx_t start,
idx_t scan_count )
399326 {
399327 switch (mode) {
399328 case DictFSSTMode::FSST_ONLY: {
399329 return *FlatVector::IncrementalSelectionVector();
399330 }
399331 default: {
399332 // Handling non-bitpacking-group-aligned start values;
399333 idx_t start_offset = start % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE;
399334
399335 // We will scan in blocks of BITPACKING_ALGORITHM_GROUP_SIZE, so we may scan some extra values.
399336 idx_t decompress_count = BitpackingPrimitives::RoundUpToAlgorithmGroupSize(scan_count + start_offset);
399337
399338 if (!sel_vec || sel_vec_size < decompress_count) {
399339 sel_vec_size = decompress_count;
399340 sel_vec = make_buffer<SelectionVector>(decompress_count);
399341 }
399342
399343 data_ptr_t sel_buf_src = &dictionary_indices_ptr[((start - start_offset) * dictionary_indices_width) / 8];
399344 sel_t *sel_vec_ptr = sel_vec->data();
399345 BitpackingPrimitives::UnPackBuffer<sel_t>(data_ptr_cast(sel_vec_ptr), sel_buf_src, decompress_count,
399346 dictionary_indices_width);
399347
399348 if (start_offset != 0) {
399349 for (idx_t i = 0; i < scan_count; i++) {
399350 sel_vec->set_index(i, sel_vec->get_index(i + start_offset));
399351 }
399352 }
399353
399354 return *sel_vec;
399355 }
399356 }
399357}
uint32_t sel_t
Type used for the selection vector.
Definition duckdb.hpp:251

◆ Select()

void duckdb::dict_fsst::CompressedStringScanState::Select ( Vector & result,
idx_t start,
const SelectionVector & sel,
idx_t sel_count )
399399 {
399400 D_ASSERT(!dictionary);
399401 D_ASSERT(mode == DictFSSTMode::FSST_ONLY);
399402 idx_t start_offset = start + 1;
399403 auto result_data = FlatVector::GetData<string_t>(result);
399404 for (idx_t i = 0; i < sel_count; i++) {
399405 // Lookup dict offset in index buffer
399406 auto string_number = start_offset + sel.get_index(i);
399407 if (decompress_position > string_number) {
399408 throw InternalException("DICT_FSST: not performing a sequential scan?");
399409 }
399410 for (; decompress_position < string_number; decompress_position++) {
399411 decompress_offset += string_lengths[decompress_position];
399412 }
399413 result_data[i] = FetchStringFromDict(result, decompress_offset, string_number);
399414 }
399415}

◆ AllowDictionaryScan()

bool duckdb::dict_fsst::CompressedStringScanState::AllowDictionaryScan ( idx_t scan_count)
399417 {
399418 if (mode == DictFSSTMode::FSST_ONLY) {
399419 return false;
399420 }
399421 if (scan_count != STANDARD_VECTOR_SIZE) {
399422 return false;
399423 }
399424 if (!dictionary) {
399425 return false;
399426 }
399427 return true;
399428}

◆ FetchStringFromDict()

string_t duckdb::dict_fsst::CompressedStringScanState::FetchStringFromDict ( Vector & result,
uint32_t dict_offset,
idx_t dict_idx )
private
399221 {
399222 D_ASSERT(dict_offset <= NumericCast<uint32_t>(segment.GetBlockSize()));
399223
399224 if (dict_idx == 0) {
399225 return string_t(nullptr, 0);
399226 }
399227 uint32_t string_len = string_lengths[dict_idx];
399228
399229 // normal string: read string from this block
399230 auto dict_pos = dict_ptr + dict_offset;
399231
399232 auto str_ptr = char_ptr_cast(dict_pos);
399233 switch (mode) {
399234 case DictFSSTMode::FSST_ONLY:
399235 case DictFSSTMode::DICT_FSST: {
399236 if (string_len == 0) {
399237 return string_t(nullptr, 0);
399238 }
399239 if (all_values_inlined) {
399240 return FSSTPrimitives::DecompressInlinedValue(decoder, str_ptr, string_len);
399241 } else {
399242 return FSSTPrimitives::DecompressValue(decoder, StringVector::GetStringBuffer(result), str_ptr, string_len);
399243 }
399244 }
399245 default:
399246 // FIXME: the Vector doesn't seem to take ownership of the non-inlined string data???
399247 return string_t(str_ptr, string_len);
399248 }
399249}
static DUCKDB_API VectorStringBuffer & GetStringBuffer(Vector &vector)
Returns a reference to the underlying VectorStringBuffer - throws an error if vector is not of type V...
Definition duckdb.cpp:137905

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