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

Public Member Functions

 FSSTCompressionState (ColumnDataCheckpointData &checkpoint_data, const CompressionInfo &info)
void Reset ()
void CreateEmptySegment ()
void UpdateState (string_t uncompressed_string, unsigned char *compressed_string, size_t compressed_string_len)
void AddEmptyStringInternal ()
void AddNull ()
void AddEmptyString ()
size_t GetRequiredSize (size_t string_len)
bool HasEnoughSpace (size_t string_len)
void Flush (bool final=false)
idx_t Finalize ()
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 current_handle
StringDictionaryContainer current_dictionary
data_ptr_t current_end_ptr
vector< uint32_t > index_buffer
size_t max_compressed_string_length
bitpacking_width_t current_width
idx_t last_fitting_size
duckdb_fsst_encoder_t * fsst_encoder = nullptr
unsigned char fsst_serialized_symbol_table [sizeof(duckdb_fsst_decoder_t)]
size_t fsst_serialized_symbol_table_size = sizeof(duckdb_fsst_decoder_t)
Public Attributes inherited from duckdb::CompressionState
CompressionInfo info

Constructor & Destructor Documentation

◆ FSSTCompressionState()

duckdb::FSSTCompressionState::FSSTCompressionState ( ColumnDataCheckpointData & checkpoint_data,
const CompressionInfo & info )
inline
401107 : CompressionState(info), checkpoint_data(checkpoint_data),
401108 function(checkpoint_data.GetCompressionFunction(CompressionType::COMPRESSION_FSST)) {
401109 CreateEmptySegment();
401110 }

◆ ~FSSTCompressionState()

duckdb::FSSTCompressionState::~FSSTCompressionState ( )
inlineoverride
401112 {
401113 if (fsst_encoder) {
401114 duckdb_fsst_destroy(fsst_encoder);
401115 }
401116 }

Member Function Documentation

◆ Reset()

void duckdb::FSSTCompressionState::Reset ( )
inline
401118 {
401119 index_buffer.clear();
401120 current_width = 0;
401121 max_compressed_string_length = 0;
401122 last_fitting_size = 0;
401123
401124 // Reset the pointers into the current segment
401125 auto &buffer_manager = BufferManager::GetBufferManager(current_segment->db);
401126 current_handle = buffer_manager.Pin(current_segment->block);
401127 current_dictionary = FSSTStorage::GetDictionary(*current_segment, current_handle);
401128 current_end_ptr = current_handle.Ptr() + current_dictionary.end;
401129 }

◆ CreateEmptySegment()

void duckdb::FSSTCompressionState::CreateEmptySegment ( )
inline
401131 {
401132 auto &db = checkpoint_data.GetDatabase();
401133 auto &type = checkpoint_data.GetType();
401134
401135 auto compressed_segment =
401136 ColumnSegment::CreateTransientSegment(db, function, type, info.GetBlockSize(), info.GetBlockManager());
401137 current_segment = std::move(compressed_segment);
401138 Reset();
401139 }
db

◆ UpdateState()

void duckdb::FSSTCompressionState::UpdateState ( string_t uncompressed_string,
unsigned char * compressed_string,
size_t compressed_string_len )
inline
401141 {
401142 if (!HasEnoughSpace(compressed_string_len)) {
401143 Flush();
401144 if (!HasEnoughSpace(compressed_string_len)) {
401145 throw InternalException("FSST string compression failed due to insufficient space in empty block");
401146 };
401147 }
401148
401149 UncompressedStringStorage::UpdateStringStats(current_segment->stats, uncompressed_string);
401150
401151 // Write string into dictionary
401152 current_dictionary.size += compressed_string_len;
401153 auto dict_pos = current_end_ptr - current_dictionary.size;
401154 memcpy(dict_pos, compressed_string, compressed_string_len);
401155 current_dictionary.Verify(info.GetBlockSize());
401156
401157 // We just push the string length to effectively delta encode the strings
401158 index_buffer.push_back(NumericCast<uint32_t>(compressed_string_len));
401159
401160 max_compressed_string_length = MaxValue(max_compressed_string_length, compressed_string_len);
401161
401162 current_width = BitpackingPrimitives::MinimumBitWidth(max_compressed_string_length);
401163 current_segment->count++;
401164 }

◆ AddEmptyStringInternal()

void duckdb::FSSTCompressionState::AddEmptyStringInternal ( )
inline
401166 {
401167 if (!HasEnoughSpace(0)) {
401168 Flush();
401169 if (!HasEnoughSpace(0)) {
401170 throw InternalException("FSST string compression failed due to insufficient space in empty block");
401171 };
401172 }
401173 index_buffer.push_back(0);
401174 current_segment->count++;
401175 }

◆ AddNull()

void duckdb::FSSTCompressionState::AddNull ( )
inline
401177 {
401178 AddEmptyStringInternal();
401179 current_segment->stats.statistics.SetHasNullFast();
401180 }

◆ AddEmptyString()

void duckdb::FSSTCompressionState::AddEmptyString ( )
inline
401182 {
401183 AddEmptyStringInternal();
401184 UncompressedStringStorage::UpdateStringStats(current_segment->stats, "");
401185 }

◆ GetRequiredSize()

size_t duckdb::FSSTCompressionState::GetRequiredSize ( size_t string_len)
inline
401187 {
401188 bitpacking_width_t required_minimum_width;
401189 if (string_len > max_compressed_string_length) {
401190 required_minimum_width = BitpackingPrimitives::MinimumBitWidth(string_len);
401191 } else {
401192 required_minimum_width = current_width;
401193 }
401194
401195 size_t current_dict_size = current_dictionary.size;
401196 idx_t current_string_count = index_buffer.size();
401197
401198 size_t dict_offsets_size =
401199 BitpackingPrimitives::GetRequiredSize(current_string_count + 1, required_minimum_width);
401200
401201 // TODO switch to a symbol table per RowGroup, saves a bit of space
401202 return sizeof(fsst_compression_header_t) + current_dict_size + dict_offsets_size + string_len +
401203 fsst_serialized_symbol_table_size;
401204 }
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ HasEnoughSpace()

bool duckdb::FSSTCompressionState::HasEnoughSpace ( size_t string_len)
inline
401207 {
401208 auto required_size = GetRequiredSize(string_len);
401209
401210 if (required_size <= info.GetBlockSize()) {
401211 last_fitting_size = required_size;
401212 return true;
401213 }
401214 return false;
401215 }

◆ Flush()

void duckdb::FSSTCompressionState::Flush ( bool final = false)
inline
401217 {
401218 auto segment_size = Finalize();
401219 auto &state = checkpoint_data.GetCheckpointState();
401220 state.FlushSegment(std::move(current_segment), std::move(current_handle), segment_size);
401221
401222 if (!final) {
401223 CreateEmptySegment();
401224 }
401225 }

◆ Finalize()

idx_t duckdb::FSSTCompressionState::Finalize ( )
inline
401227 {
401228 auto &buffer_manager = BufferManager::GetBufferManager(current_segment->db);
401229 auto handle = buffer_manager.Pin(current_segment->block);
401230 if (current_dictionary.end != info.GetBlockSize()) {
401231 throw InternalException("dictionary end does not match the block size in FSSTCompressionState::Finalize");
401232 }
401233
401234 // calculate sizes
401235 auto compressed_index_buffer_size =
401236 BitpackingPrimitives::GetRequiredSize(current_segment->count, current_width);
401237 auto total_size = sizeof(fsst_compression_header_t) + compressed_index_buffer_size + current_dictionary.size +
401238 fsst_serialized_symbol_table_size;
401239 if (total_size != last_fitting_size) {
401240 throw InternalException("FSST string compression failed due to incorrect size calculation");
401241 }
401242
401243 // calculate ptr and offsets
401244 auto base_ptr = handle.Ptr();
401245 auto header_ptr = reinterpret_cast<fsst_compression_header_t *>(base_ptr);
401246 auto compressed_index_buffer_offset = sizeof(fsst_compression_header_t);
401247 auto symbol_table_offset = compressed_index_buffer_offset + compressed_index_buffer_size;
401248
401249 D_ASSERT(current_segment->count == index_buffer.size());
401250 BitpackingPrimitives::PackBuffer<sel_t, false>(base_ptr + compressed_index_buffer_offset,
401251 reinterpret_cast<uint32_t *>(index_buffer.data()),
401252 current_segment->count, current_width);
401253
401254 // Write the fsst symbol table or nothing
401255 if (fsst_encoder != nullptr) {
401256 memcpy(base_ptr + symbol_table_offset, &fsst_serialized_symbol_table[0], fsst_serialized_symbol_table_size);
401257 } else {
401258 memset(base_ptr + symbol_table_offset, 0, fsst_serialized_symbol_table_size);
401259 }
401260
401261 auto cast_symbol_table_offset = NumericCast<uint32_t>(symbol_table_offset);
401262 if (cast_symbol_table_offset > info.GetBlockSize()) {
401263 throw InternalException("invalid fsst_symbol_table_offset in FSSTCompressionState::Finalize");
401264 }
401265
401266 Store<uint32_t>(cast_symbol_table_offset, data_ptr_cast(&header_ptr->fsst_symbol_table_offset));
401267 Store<uint32_t>((uint32_t)current_width, data_ptr_cast(&header_ptr->bitpacking_width));
401268
401269 if (total_size >= info.GetCompactionFlushLimit()) {
401270 // the block is full enough, don't bother moving around the dictionary
401271 return info.GetBlockSize();
401272 }
401273
401274 // the block has space left: figure out how much space we can save
401275 auto move_amount = info.GetBlockSize() - total_size;
401276 // move the dictionary so it lines up exactly with the offsets
401277 auto new_dictionary_offset = symbol_table_offset + fsst_serialized_symbol_table_size;
401278 memmove(base_ptr + new_dictionary_offset, base_ptr + current_dictionary.end - current_dictionary.size,
401279 current_dictionary.size);
401280 current_dictionary.end -= move_amount;
401281 D_ASSERT(current_dictionary.end == total_size);
401282 // write the new dictionary (with the updated "end")
401283 FSSTStorage::SetDictionary(*current_segment, handle, current_dictionary);
401284
401285 return total_size;
401286 }
::uint32_t uint32_t

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