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

Public Member Functions

 DictionaryCompressionCompressState (ColumnDataCheckpointData &checkpoint_data_p, const CompressionInfo &info, idx_t max_unique_count_across_all_segments)
void CreateEmptySegment ()
void Verify () override
bool LookupString (string_t str) override
void AddNewString (string_t str) override
void AddNull () override
void AddLastLookup () override
bool CalculateSpaceRequirements (bool new_string, idx_t string_size) override
void Flush (bool final=false) override
idx_t Finalize ()
Public Member Functions inherited from duckdb::DictionaryCompressionState
 DictionaryCompressionState (const CompressionInfo &info)
bool UpdateState (Vector &scan_vector, 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 current_handle
StringDictionaryContainer current_dictionary
data_ptr_t current_end_ptr
PrimitiveDictionary< string_t > current_string_map
vector< uint32_t > index_buffer
vector< uint32_t > selection_buffer
bitpacking_width_t current_width = 0
bitpacking_width_t next_width = 0
uint32_t latest_lookup_result
Public Attributes inherited from duckdb::CompressionState
CompressionInfo info

Constructor & Destructor Documentation

◆ DictionaryCompressionCompressState()

duckdb::DictionaryCompressionCompressState::DictionaryCompressionCompressState ( ColumnDataCheckpointData & checkpoint_data_p,
const CompressionInfo & info,
idx_t max_unique_count_across_all_segments )
400028 : DictionaryCompressionState(info), checkpoint_data(checkpoint_data_p),
400029 function(checkpoint_data.GetCompressionFunction(CompressionType::COMPRESSION_DICTIONARY)),
400030 current_string_map(
400031 info.GetBlockManager().buffer_manager.GetBufferAllocator(),
400032 max_unique_count_across_all_segments * 2, // * 2 results in less linear probing, improving performance
400033 1 // maximum_target_capacity_p, 1 because we don't care about target for our use-case, as we
400034 // only use PrimitiveDictionary for duplicate checks, and not for writing to any target
400035 ) {
400036 CreateEmptySegment();
400037}

Member Function Documentation

◆ CreateEmptySegment()

void duckdb::DictionaryCompressionCompressState::CreateEmptySegment ( )
400039 {
400040 auto &db = checkpoint_data.GetDatabase();
400041 auto &type = checkpoint_data.GetType();
400042
400043 auto compressed_segment =
400044 ColumnSegment::CreateTransientSegment(db, function, type, info.GetBlockSize(), info.GetBlockManager());
400045 current_segment = std::move(compressed_segment);
400046
400047 // Reset the buffers and the string map.
400048 current_string_map.Clear();
400049 index_buffer.clear();
400050
400051 // Reserve index 0 for null strings.
400052 index_buffer.push_back(0);
400053 selection_buffer.clear();
400054
400055 current_width = 0;
400056 next_width = 0;
400057
400058 // Reset the pointers into the current segment.
400059 auto &buffer_manager = BufferManager::GetBufferManager(checkpoint_data.GetDatabase());
400060 current_handle = buffer_manager.Pin(current_segment->block);
400061 current_dictionary = DictionaryCompression::GetDictionary(*current_segment, current_handle);
400062 current_end_ptr = current_handle.Ptr() + current_dictionary.end;
400063}
db

◆ Verify()

void duckdb::DictionaryCompressionCompressState::Verify ( )
overridevirtual

Implements duckdb::DictionaryCompressionState.

400065 {
400066 current_dictionary.Verify(info.GetBlockSize());
400067 D_ASSERT(current_segment->count == selection_buffer.size());
400068 D_ASSERT(DictionaryCompression::HasEnoughSpace(current_segment->count.load(), index_buffer.size(),
400069 current_dictionary.size, current_width, info.GetBlockSize()));
400070 D_ASSERT(current_dictionary.end == info.GetBlockSize());
400071 D_ASSERT(index_buffer.size() == current_string_map.GetSize() + 1); // +1 is for null value
400072}

◆ LookupString()

bool duckdb::DictionaryCompressionCompressState::LookupString ( string_t str)
overridevirtual

Implements duckdb::DictionaryCompressionState.

400074 {
400075 const auto &entry = current_string_map.Lookup(str);
400076 const auto has_result = !entry.IsEmpty();
400077 if (has_result) {
400078 latest_lookup_result = entry.index + 1;
400079 }
400080 return has_result;
400081}

◆ AddNewString()

void duckdb::DictionaryCompressionCompressState::AddNewString ( string_t str)
overridevirtual

Implements duckdb::DictionaryCompressionState.

400083 {
400084 UncompressedStringStorage::UpdateStringStats(current_segment->stats, str);
400085
400086 // Copy string to dict
400087 current_dictionary.size += str.GetSize();
400088 auto dict_pos = current_end_ptr - current_dictionary.size;
400089 memcpy(dict_pos, str.GetData(), str.GetSize());
400090 current_dictionary.Verify(info.GetBlockSize());
400091 D_ASSERT(current_dictionary.end == info.GetBlockSize());
400092
400093 // Update buffers and map
400094 index_buffer.push_back(current_dictionary.size);
400095 selection_buffer.push_back(UnsafeNumericCast<uint32_t>(index_buffer.size() - 1));
400096 if (str.IsInlined()) {
400097 current_string_map.Insert(str);
400098 } else {
400099 string_t dictionary_string((const char *)dict_pos, UnsafeNumericCast<uint32_t>(str.GetSize())); // NOLINT
400100 D_ASSERT(!dictionary_string.IsInlined());
400101 current_string_map.Insert(dictionary_string);
400102 }
400103 DictionaryCompression::SetDictionary(*current_segment, current_handle, current_dictionary);
400104
400105 current_width = next_width;
400106 current_segment->count++;
400107}

◆ AddNull()

void duckdb::DictionaryCompressionCompressState::AddNull ( )
overridevirtual

Implements duckdb::DictionaryCompressionState.

400109 {
400110 current_segment->stats.statistics.SetHasNullFast();
400111 selection_buffer.push_back(0);
400112 current_segment->count++;
400113}

◆ AddLastLookup()

void duckdb::DictionaryCompressionCompressState::AddLastLookup ( )
overridevirtual

Implements duckdb::DictionaryCompressionState.

400115 {
400116 selection_buffer.push_back(latest_lookup_result);
400117 current_segment->count++;
400118}

◆ CalculateSpaceRequirements()

bool duckdb::DictionaryCompressionCompressState::CalculateSpaceRequirements ( bool new_string,
idx_t string_size )
overridevirtual

Implements duckdb::DictionaryCompressionState.

400120 {
400121 if (!new_string) {
400122 return DictionaryCompression::HasEnoughSpace(current_segment->count.load() + 1, index_buffer.size(),
400123 current_dictionary.size, current_width, info.GetBlockSize());
400124 }
400125 next_width = BitpackingPrimitives::MinimumBitWidth(index_buffer.size() - 1 + new_string);
400126 return DictionaryCompression::HasEnoughSpace(current_segment->count.load() + 1, index_buffer.size() + 1,
400127 current_dictionary.size + string_size, next_width,
400128 info.GetBlockSize());
400129}

◆ Flush()

void duckdb::DictionaryCompressionCompressState::Flush ( bool final = false)
overridevirtual

Implements duckdb::DictionaryCompressionState.

400131 {
400132 auto segment_size = Finalize();
400133 auto &state = checkpoint_data.GetCheckpointState();
400134 state.FlushSegment(std::move(current_segment), std::move(current_handle), segment_size);
400135
400136 if (!final) {
400137 CreateEmptySegment();
400138 }
400139}

◆ Finalize()

idx_t duckdb::DictionaryCompressionCompressState::Finalize ( )
400141 {
400142 auto &buffer_manager = BufferManager::GetBufferManager(checkpoint_data.GetDatabase());
400143 auto handle = buffer_manager.Pin(current_segment->block);
400144 D_ASSERT(current_dictionary.end == info.GetBlockSize());
400145
400146 // calculate sizes
400147 auto compressed_selection_buffer_size =
400148 BitpackingPrimitives::GetRequiredSize(current_segment->count, current_width);
400149 auto index_buffer_size = index_buffer.size() * sizeof(uint32_t);
400150 auto total_size = DictionaryCompression::DICTIONARY_HEADER_SIZE + compressed_selection_buffer_size +
400151 index_buffer_size + current_dictionary.size;
400152
400153 // calculate ptr and offsets
400154 auto base_ptr = handle.Ptr();
400155 auto header_ptr = reinterpret_cast<dictionary_compression_header_t *>(base_ptr);
400156 auto compressed_selection_buffer_offset = DictionaryCompression::DICTIONARY_HEADER_SIZE;
400157 auto index_buffer_offset = compressed_selection_buffer_offset + compressed_selection_buffer_size;
400158
400159 // Write compressed selection buffer
400160 BitpackingPrimitives::PackBuffer<sel_t, false>(base_ptr + compressed_selection_buffer_offset,
400161 (sel_t *)(selection_buffer.data()), current_segment->count,
400162 current_width);
400163
400164 // Write the index buffer
400165 memcpy(base_ptr + index_buffer_offset, index_buffer.data(), index_buffer_size);
400166
400167 // Store sizes and offsets in segment header
400168 Store<uint32_t>(NumericCast<uint32_t>(index_buffer_offset), data_ptr_cast(&header_ptr->index_buffer_offset));
400169 Store<uint32_t>(NumericCast<uint32_t>(index_buffer.size()), data_ptr_cast(&header_ptr->index_buffer_count));
400170 Store<uint32_t>((uint32_t)current_width, data_ptr_cast(&header_ptr->bitpacking_width));
400171
400172 D_ASSERT(current_width == BitpackingPrimitives::MinimumBitWidth(index_buffer.size() - 1));
400173 D_ASSERT(DictionaryCompression::HasEnoughSpace(current_segment->count, index_buffer.size(), current_dictionary.size,
400174 current_width, info.GetBlockSize()));
400175 D_ASSERT((uint64_t)*max_element(std::begin(selection_buffer), std::end(selection_buffer)) ==
400176 index_buffer.size() - 1);
400177
400178 // Early-out, if the block is sufficiently full.
400179 if (total_size >= info.GetCompactionFlushLimit()) {
400180 return info.GetBlockSize();
400181 }
400182
400183 // Sufficient space: calculate how much space we can save.
400184 auto move_amount = info.GetBlockSize() - total_size;
400185
400186 // Move the dictionary to align it with the offsets.
400187 auto new_dictionary_offset = index_buffer_offset + index_buffer_size;
400188 memmove(base_ptr + new_dictionary_offset, base_ptr + current_dictionary.end - current_dictionary.size,
400189 current_dictionary.size);
400190 current_dictionary.end -= move_amount;
400191 D_ASSERT(current_dictionary.end == total_size);
400192
400193 // Write the new dictionary with the updated "end".
400194 DictionaryCompression::SetDictionary(*current_segment, handle, current_dictionary);
400195 return total_size;
400196}
::uint32_t uint32_t
uint32_t sel_t
Type used for the selection vector.
Definition duckdb.hpp:251
static constexpr uint16_t DICTIONARY_HEADER_SIZE
Dictionary header size at the beginning of the string segment (offset + length).
Definition duckdb.cpp:399725

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