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

Public Types

using EXACT_TYPE = typename FloatingToExact<T>::TYPE

Public Member Functions

 AlpCompressionState (ColumnDataCheckpointData &checkpoint_data, AlpAnalyzeState< T > *analyze_state)
idx_t UsedSpace () const
bool HasEnoughSpace (idx_t vector_size)
void ResetVector ()
void CreateEmptySegment ()
void CompressVector ()
void FlushCompressedVector ()
void FlushUncompressedVector ()
void FlushSegment ()
void Finalize ()
void Append (UnifiedVectorFormat &vdata, idx_t count)
Public Member Functions inherited from duckdb::CompressionState
 CompressionState (const CompressionInfo &info)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

ColumnDataCheckpointData & checkpoint_data
const CompressionFunction & function
unique_ptr< ColumnSegment > current_segment
BufferHandle handle
idx_t vector_idx = 0
idx_t nulls_idx = 0
idx_t vectors_flushed = 0
idx_t data_bytes_used = 0
data_ptr_t data_ptr
data_ptr_t metadata_ptr
uint32_t next_vector_byte_index_start = AlpConstants::HEADER_SIZE
T input_vector [AlpConstants::ALP_VECTOR_SIZE]
uint16_t vector_null_positions [AlpConstants::ALP_VECTOR_SIZE]
alp::AlpCompressionData< T, false > compression_data
Public Attributes inherited from duckdb::CompressionState
CompressionInfo info

Constructor & Destructor Documentation

◆ AlpCompressionState()

template<class T>
duckdb::AlpCompressionState< T >::AlpCompressionState ( ColumnDataCheckpointData & checkpoint_data,
AlpAnalyzeState< T > * analyze_state )
inline

Combinations found on the analyze step are needed for compression

393240 : CompressionState(analyze_state->info), checkpoint_data(checkpoint_data),
393241 function(checkpoint_data.GetCompressionFunction(CompressionType::COMPRESSION_ALP)) {
393242 CreateEmptySegment();
393243
393245 compression_data.best_k_combinations = analyze_state->compression_data.best_k_combinations;
393246 }
Definition duckdb.cpp:393235

Member Function Documentation

◆ UsedSpace()

template<class T>
idx_t duckdb::AlpCompressionState< T >::UsedSpace ( ) const
inline
393269 {
393270 return AlpConstants::METADATA_POINTER_SIZE + data_bytes_used;
393271 }

◆ HasEnoughSpace()

template<class T>
bool duckdb::AlpCompressionState< T >::HasEnoughSpace ( idx_t vector_size)
inline

If [start of block + used space + required space] is more than whats left (current position of metadata pointer - the size of a new metadata pointer)

393273 {
393276 if ((handle.Ptr() + AlignValue(UsedSpace() + vector_size)) >=
393277 (metadata_ptr - AlpConstants::METADATA_POINTER_SIZE)) {
393278 return false;
393279 }
393280 return true;
393281 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetVector()

template<class T>
void duckdb::AlpCompressionState< T >::ResetVector ( )
inline
393283 {
393284 compression_data.Reset();
393285 }

◆ CreateEmptySegment()

template<class T>
void duckdb::AlpCompressionState< T >::CreateEmptySegment ( )
inline
393287 {
393288 auto &db = checkpoint_data.GetDatabase();
393289 auto &type = checkpoint_data.GetType();
393290
393291 auto compressed_segment =
393292 ColumnSegment::CreateTransientSegment(db, function, type, info.GetBlockSize(), info.GetBlockManager());
393293 current_segment = std::move(compressed_segment);
393294
393295 auto &buffer_manager = BufferManager::GetBufferManager(current_segment->db);
393296 handle = buffer_manager.Pin(current_segment->block);
393297
393298 // The pointer to the start of the compressed data.
393299 data_ptr = handle.Ptr() + current_segment->GetBlockOffset() + AlpConstants::HEADER_SIZE;
393300 // The pointer to the start of the metadata.
393301 metadata_ptr = handle.Ptr() + current_segment->GetBlockOffset() + info.GetBlockSize();
393302 next_vector_byte_index_start = AlpConstants::HEADER_SIZE;
393303 }

◆ CompressVector()

template<class T>
void duckdb::AlpCompressionState< T >::CompressVector ( )
inline

Check if the compressed vector fits on current segment

At least there is one valid value in the vector

393305 {
393306 if (nulls_idx) {
393307 alp::AlpUtils::FindAndReplaceNullsInVector<T>(input_vector, vector_null_positions, vector_idx, nulls_idx);
393308 }
393309 alp::AlpCompression<T, false>::Compress(input_vector, vector_idx, vector_null_positions, nulls_idx,
393310 compression_data);
393311 const idx_t uncompressed_size = AlpConstants::EXPONENT_SIZE + sizeof(T) * vector_idx;
393312 const idx_t compressed_size = compression_data.RequiredSpace();
393313
393314 const auto storage_version = checkpoint_data.GetStorageManager().GetStorageVersion();
393316
393318
393320 if (!HasEnoughSpace(vector_size)) {
393321 FlushSegment();
393322 CreateEmptySegment();
393323 }
393324
393325 if (nulls_idx) {
393326 current_segment->stats.statistics.SetHasNullFast();
393327 }
393328 if (vector_idx != nulls_idx) {
393329 current_segment->stats.statistics.SetHasNoNullFast();
393330 for (idx_t i = 0; i < vector_idx; i++) {
393331 current_segment->stats.statistics.UpdateNumericStats<T>(input_vector[i]);
393332 }
393333 }
393334 current_segment->count += vector_idx;
393335
393336 if (should_compress) {
393337 FlushCompressedVector();
393338 } else {
393339 FlushUncompressedVector();
393340 }
393341 }
void FlushSegment()
Definition duckdb.cpp:393416
bool HasEnoughSpace(idx_t vector_size)
Definition duckdb.cpp:393273
static void Compress(const T *input_vector, idx_t n_values, const uint16_t *vector_null_positions, idx_t nulls_count, CompressionData &compression_data)
Definition duckdb.cpp:392917
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlushCompressedVector()

template<class T>
void duckdb::AlpCompressionState< T >::FlushCompressedVector ( )
inline
393344 {
393345 Store<uint8_t>(compression_data.vector_encoding_indices.exponent, data_ptr);
393346 data_ptr += AlpConstants::EXPONENT_SIZE;
393347
393348 Store<uint8_t>(compression_data.vector_encoding_indices.factor, data_ptr);
393349 data_ptr += AlpConstants::FACTOR_SIZE;
393350
393351 Store<uint16_t>(compression_data.exceptions_count, data_ptr);
393353
393354 Store<uint64_t>(compression_data.frame_of_reference, data_ptr);
393355 data_ptr += AlpConstants::FOR_SIZE;
393356
393357 Store<uint8_t>(UnsafeNumericCast<uint8_t>(compression_data.bit_width), data_ptr);
393358 data_ptr += AlpConstants::BIT_WIDTH_SIZE;
393359
393360 memcpy((void *)data_ptr, (void *)compression_data.values_encoded, compression_data.bp_size);
393361 // We should never go out of bounds in the values_encoded array
393362 D_ASSERT((AlpConstants::ALP_VECTOR_SIZE * 8) >= compression_data.bp_size);
393363
393364 data_ptr += compression_data.bp_size;
393365
393366 if (compression_data.exceptions_count > 0) {
393367 memcpy((void *)data_ptr, (void *)compression_data.exceptions,
393368 sizeof(EXACT_TYPE) * compression_data.exceptions_count);
393369 data_ptr += sizeof(EXACT_TYPE) * compression_data.exceptions_count;
393370 memcpy((void *)data_ptr, (void *)compression_data.exceptions_positions,
393371 AlpConstants::EXCEPTION_POSITION_SIZE * compression_data.exceptions_count);
393372 data_ptr += AlpConstants::EXCEPTION_POSITION_SIZE * compression_data.exceptions_count;
393373 }
393374
393375 data_bytes_used +=
393376 compression_data.bp_size +
393377 (compression_data.exceptions_count * (sizeof(EXACT_TYPE) + AlpConstants::EXCEPTION_POSITION_SIZE)) +
393380
393381 // Write pointer to the vector data (metadata)
393382 metadata_ptr -= sizeof(uint32_t);
393383 Store<uint32_t>(next_vector_byte_index_start, metadata_ptr);
393384 next_vector_byte_index_start = NumericCast<uint32_t>(UsedSpace());
393385
393386 vectors_flushed++;
393387 vector_idx = 0;
393388 nulls_idx = 0;
393389 ResetVector();
393390 }

◆ FlushUncompressedVector()

template<class T>
void duckdb::AlpCompressionState< T >::FlushUncompressedVector ( )
inline
393393 {
393394 // Store a sentinel value instead of the exponent, signaling the coming data is stored uncompressed.
393396 Store<uint8_t>(sentinel, data_ptr);
393397 data_ptr += AlpConstants::EXPONENT_SIZE;
393398
393399 // Store uncompressed data
393400 memcpy(data_ptr, input_vector, sizeof(T) * vector_idx);
393401 data_ptr += sizeof(T) * vector_idx;
393402
393403 data_bytes_used += AlpConstants::EXPONENT_SIZE + (sizeof(T) * vector_idx);
393404
393405 // Write pointer to the vector data (metadata)
393406 metadata_ptr -= sizeof(uint32_t);
393407 Store<uint32_t>(next_vector_byte_index_start, metadata_ptr);
393408 next_vector_byte_index_start = NumericCast<uint32_t>(UsedSpace());
393409
393410 vectors_flushed++;
393411 vector_idx = 0;
393412 nulls_idx = 0;
393413 ResetVector();
393414 }

◆ FlushSegment()

template<class T>
void duckdb::AlpCompressionState< T >::FlushSegment ( )
inline

We compact the block if the space used is less than a threshold

393416 {
393417 auto &checkpoint_state = checkpoint_data.GetCheckpointState();
393418 auto dataptr = handle.Ptr();
393419
393420 idx_t metadata_offset = AlignValue(UsedSpace());
393421
393422 // Verify that the metadata_ptr is not smaller than the space used by the data
393423 D_ASSERT(dataptr + metadata_offset <= metadata_ptr);
393424
393425 auto bytes_used_by_metadata = UnsafeNumericCast<idx_t>(dataptr + info.GetBlockSize() - metadata_ptr);
393426
393427 // Initially the total segment size is the size of the block
393428 auto total_segment_size = info.GetBlockSize();
393429
393431 const auto used_space_percentage =
393432 static_cast<float>(metadata_offset + bytes_used_by_metadata) / static_cast<float>(total_segment_size);
393434#ifdef DEBUG
393437 memcpy((void *)&verify_bytes, metadata_ptr, 4);
393438#endif
393440#ifdef DEBUG
393443#endif
393445 }
393446
393447 // Store the offset to the end of metadata (to be used as a backwards pointer in decoding)
393449
393451 data_bytes_used = 0;
393452 vectors_flushed = 0;
393453 }
static T AlignValue(T n)
Align value (ceiling) (not for pointer types).
Definition duckdb.hpp:2126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Finalize()

template<class T>
void duckdb::AlpCompressionState< T >::Finalize ( )
inline
393455 {
393456 if (vector_idx != 0) {
393457 CompressVector();
393458 D_ASSERT(vector_idx == 0);
393459 }
393460 FlushSegment();
393461 current_segment.reset();
393462 }
void CompressVector()
Definition duckdb.cpp:393305

◆ Append()

template<class T>
void duckdb::AlpCompressionState< T >::Append ( UnifiedVectorFormat & vdata,
idx_t count )
inline

Stages uncompressed input values into fixed-size batches (ALP_VECTOR_SIZE), calling CompressVector() to compress and flush each full batch to the segment. Handles nulls and processes arbitrarily large inputs.

We optimize a loop when there are no null

We resolve null values with a predicated comparison

393465 {
393468 idx_t offset_in_data = 0;
393469 while (values_left_in_data > 0) {
393470 // We calculate until which value in data we must go to fill the input_vector
393471 // to avoid checking if input_vector is filled in each iteration
393474 if (vdata.validity.AllValid()) {
393475 for (idx_t i = 0; i < values_to_fill_alp_input; i++) {
393476 auto idx = vdata.sel->get_index(offset_in_data + i);
393477 T value = data[idx];
393478 input_vector[vector_idx + i] = value;
393479 }
393480 } else {
393481 for (idx_t i = 0; i < values_to_fill_alp_input; i++) {
393482 auto idx = vdata.sel->get_index(offset_in_data + i);
393483 T value = data[idx];
393484 bool is_null = !vdata.validity.RowIsValid(idx);
393486 vector_null_positions[nulls_idx] = UnsafeNumericCast<uint16_t>(vector_idx + i);
393487 nulls_idx += is_null;
393488 input_vector[vector_idx + i] = value;
393489 }
393490 }
393493 vector_idx += values_to_fill_alp_input;
393494 // We still need this check since we could have an incomplete input_vector at the end of data
393495 if (vector_idx == AlpConstants::ALP_VECTOR_SIZE) {
393496 CompressVector();
393497 D_ASSERT(vector_idx == 0);
393498 }
393499 }
393500 }
Here is the call graph for this function:

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