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::VariantColumnData Class Reference

Struct column data represents a struct. More...

Inheritance diagram for duckdb::VariantColumnData:
Collaboration diagram for duckdb::VariantColumnData:

Public Member Functions

 VariantColumnData (BlockManager &block_manager, DataTableInfo &info, idx_t column_index, LogicalType type, ColumnDataType data_type, optional_ptr< ColumnData > parent)
idx_t GetMaxEntry () override
bool IsShredded () const
void InitializePrefetch (PrefetchState &prefetch_state, ColumnScanState &scan_state, idx_t rows) override
 Initialize prefetch state with required I/O data for the next N rows.
void InitializeScan (ColumnScanState &state) override
 Initialize a scan of the column.
void InitializeScanWithOffset (ColumnScanState &state, idx_t row_idx) override
 Initialize a scan starting at the specified offset.
idx_t Scan (TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, idx_t scan_count) override
idx_t ScanCount (ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset=0) override
void Skip (ColumnScanState &state, idx_t count=STANDARD_VECTOR_SIZE) override
 Skip the scan forward by "count" rows.
void InitializeAppend (ColumnAppendState &state) override
 Initialize an appending phase for this column.
void Append (BaseStatistics &stats, ColumnAppendState &state, Vector &vector, idx_t count) override
 Append a vector of type [type] to the end of the column.
void RevertAppend (row_t new_count) override
 Revert a set of appends to the ColumnData.
idx_t Fetch (ColumnScanState &state, row_t row_id, Vector &result) override
 Fetch the vector from the column data that belongs to this specific row.
void FetchRow (TransactionData transaction, ColumnFetchState &state, const StorageIndex &storage_index, row_t row_id, Vector &result, idx_t result_idx) override
 Fetch a specific row id and append it to the vector.
void Update (TransactionData transaction, DataTable &data_table, idx_t column_index, Vector &update_vector, row_t *row_ids, idx_t update_count, idx_t row_group_start) override
void UpdateColumn (TransactionData transaction, DataTable &data_table, const vector< column_t > &column_path, Vector &update_vector, row_t *row_ids, idx_t update_count, idx_t depth, idx_t row_group_start) override
unique_ptr< BaseStatistics > GetUpdateStatistics () override
void VisitBlockIds (BlockIdVisitor &visitor) const override
unique_ptr< ColumnCheckpointState > CreateCheckpointState (const RowGroup &row_group, PartialBlockManager &partial_block_manager) override
unique_ptr< ColumnCheckpointState > Checkpoint (const RowGroup &row_group, ColumnCheckpointInfo &info, const BaseStatistics &old_stats) override
bool IsPersistent () override
bool HasAnyChanges () const override
 Whether or not the column has ANY changes, including in child columns.
PersistentColumnData Serialize () override
void InitializeColumn (PersistentColumnData &column_data, BaseStatistics &target_stats) override
void GetColumnSegmentInfo (const QueryContext &context, duckdb::idx_t row_group_index, vector< duckdb::idx_t > col_path, vector< duckdb::ColumnSegmentInfo > &result) override
void Verify (RowGroup &parent) override
void SetValidityData (shared_ptr< ValidityColumnData > validity_p)
void SetChildData (vector< shared_ptr< ColumnData > > child_data)
Public Member Functions inherited from duckdb::ColumnData
 ColumnData (BlockManager &block_manager, DataTableInfo &info, idx_t column_index, LogicalType type, ColumnDataType data_type, optional_ptr< ColumnData > parent)
virtual FilterPropagateResult CheckZonemap (ColumnScanState &state, TableFilter &filter)
BlockManager & GetBlockManager () const
DatabaseInstance & GetDatabase () const
DataTableInfo & GetTableInfo () const
StorageManager & GetStorageManager () const
idx_t GetAllocationSize () const
optional_ptr< const CompressionFunction > GetCompressionFunction () const
virtual void SetDataType (ColumnDataType data_type)
ColumnDataType GetDataType () const
bool HasParent () const
void SetParent (optional_ptr< ColumnData > parent)
const ColumnData & Parent () const
virtual const BaseStatistics & GetChildStats (const ColumnData &child) const
const LogicalType & GetType () const
ColumnSegmentTree & GetSegmentTree ()
void SetCount (idx_t new_count)
bool HasUpdates () const
 Whether or not the column has any updates.
bool HasChanges (idx_t start_row, idx_t end_row) const
bool HasChanges () const
 Whether or not the column has changes at this level.
virtual ScanVectorType GetVectorScanType (ColumnScanState &state, idx_t scan_count, Vector &result)
 Whether or not we can scan an entire vector.
idx_t Scan (TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result)
 Scan the next vector from the column.
virtual void ScanCommittedRange (idx_t row_group_start, idx_t offset_in_row_group, idx_t count, Vector &result)
virtual void Filter (TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, SelectionVector &sel, idx_t &count, const TableFilter &filter, TableFilterState &filter_state)
 Select.
virtual void Select (TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, SelectionVector &sel, idx_t count)
void Append (ColumnAppendState &state, Vector &vector, idx_t count)
 Append a vector of type [type] to the end of the column.
virtual void AppendData (BaseStatistics &stats, ColumnAppendState &state, UnifiedVectorFormat &vdata, idx_t count)
unique_ptr< ColumnCheckpointState > Checkpoint (const RowGroup &row_group, ColumnCheckpointInfo &info)
 If this is a nested column, "stats" are the corresponding statistics from the parent column Otherwise, "stats" == this->statistics->stats.
virtual void CheckpointScan (ColumnSegment &segment, ColumnScanState &state, idx_t count, Vector &scan_vector) const
vector< DataPointer > GetDataPointers ()
void InitializeColumn (PersistentColumnData &column_data)
FilterPropagateResult CheckZonemap (const StorageIndex &index, TableFilter &filter)
void MergeStatistics (const BaseStatistics &other)
void MergeIntoStatistics (BaseStatistics &other)
unique_ptr< BaseStatistics > GetStatistics () const
const BaseStatistics & GetStatisticsRef () const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
Public Member Functions inherited from duckdb::enable_shared_from_this< ColumnData >
shared_ptr< ColumnData > shared_from_this ()

Static Public Member Functions

static void ShredVariantData (Vector &input, Vector &output, idx_t count)
static void UnshredVariantData (Vector &input, Vector &output, idx_t count)
Static Public Member Functions inherited from duckdb::ColumnData
static shared_ptr< ColumnData > Deserialize (BlockManager &block_manager, DataTableInfo &info, idx_t column_index, ReadStream &source, const LogicalType &type)
static shared_ptr< ColumnData > CreateColumn (BlockManager &block_manager, DataTableInfo &info, idx_t column_index, const LogicalType &type, ColumnDataType data_type=ColumnDataType::MAIN_TABLE, optional_ptr< ColumnData > parent=nullptr)

Public Attributes

vector< shared_ptr< ColumnData > > sub_columns
 The sub-columns of the struct.
shared_ptr< ValidityColumnData > validity
Public Attributes inherited from duckdb::ColumnData
atomic< idx_t > count
 The count of the column data.
BlockManager & block_manager
 The block manager.
DataTableInfo & info
 Table info for the column.
idx_t column_index
 The column index of the column, either within the parent table or within the parent.
LogicalType type
 The type of the column.

Static Public Attributes

static constexpr idx_t TYPED_VALUE_INDEX = 0
 Indices into the inner shredded struct: STRUCT(typed_value <type>, untyped_value_index UINTEGER).
static constexpr idx_t UNTYPED_VALUE_INDEX = 1

Private Member Functions

Vector CreateUnshreddingIntermediate (idx_t count) const
vector< shared_ptr< ColumnData > > WriteShreddedData (const RowGroup &row_group, const LogicalType &shredded_type, BaseStatistics &stats)
bool PushdownShreddedFieldExtract (const StorageIndex &variant_extract, StorageIndex &out_struct_extract) const
void CreateScanStates (ColumnScanState &state)
idx_t ScanWithCallback (ColumnScanState &state, Vector &result, idx_t target_count, const std::function< idx_t(ColumnData &column, ColumnScanState &child_state, Vector &target_vector, idx_t count)> &callback) const
LogicalType GetShreddedType ()

Additional Inherited Members

Protected Member Functions inherited from duckdb::ColumnData
void AppendTransientSegment (SegmentLock &l, idx_t start_row)
 Append a transient segment.
void AppendSegment (SegmentLock &l, unique_ptr< ColumnSegment > segment)
void BeginScanVectorInternal (ColumnScanState &state)
idx_t ScanVector (ColumnScanState &state, Vector &result, idx_t remaining, ScanVectorType scan_type, idx_t result_offset=0)
 Scans a base vector from the column.
idx_t ScanVector (TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, idx_t target_scan, ScanVectorType scan_type, UpdateScanType update_type)
 Scans a vector from the column merged with any potential updates.
idx_t ScanVector (TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, idx_t target_scan, UpdateScanType update_type)
void SelectVector (ColumnScanState &state, Vector &result, idx_t target_count, const SelectionVector &sel, idx_t sel_count)
void FilterVector (ColumnScanState &state, Vector &result, idx_t target_count, SelectionVector &sel, idx_t &sel_count, const TableFilter &filter, TableFilterState &filter_state)
void FetchUpdates (TransactionData transaction, idx_t vector_index, Vector &result, idx_t scan_count, UpdateScanType update_type)
void FetchUpdateRow (TransactionData transaction, row_t row_id, Vector &result, idx_t result_idx)
void UpdateInternal (TransactionData transaction, DataTable &data_table, idx_t column_index, Vector &update_vector, row_t *row_ids, idx_t update_count, Vector &base_vector, idx_t row_group_start)
idx_t FetchUpdateData (ColumnScanState &state, row_t *row_ids, Vector &base_vector, idx_t row_group_start)
idx_t GetVectorCount (idx_t vector_index) const
Protected Member Functions inherited from duckdb::enable_shared_from_this< ColumnData >
enable_shared_from_this & operator= (enable_shared_from_this const &) noexcept
Protected Attributes inherited from duckdb::ColumnData
ColumnSegmentTree data
 The segments holding the data of this column segment.
mutex update_lock
 The lock for the updates.
unique_ptr< UpdateSegment > updates
 The updates for this column segment.
mutex stats_lock
 The lock for the stats.
atomic< idx_t > allocation_size
 Total transient allocation size.
unique_ptr< SegmentStatistics > stats
 The stats of the root segment.

Detailed Description

Struct column data represents a struct.

Constructor & Destructor Documentation

◆ VariantColumnData()

duckdb::VariantColumnData::VariantColumnData ( BlockManager & block_manager,
DataTableInfo & info,
idx_t column_index,
LogicalType type,
ColumnDataType data_type,
optional_ptr< ColumnData > parent )
441420 : ColumnData(block_manager, info, column_index, std::move(type_p), data_type, parent) {
441421 D_ASSERT(type.InternalType() == PhysicalType::STRUCT);
441422
441423 if (data_type != ColumnDataType::CHECKPOINT_TARGET) {
441424 validity = make_shared_ptr<ValidityColumnData>(block_manager, info, 0, *this);
441425 // the sub column index, starting at 1 (0 is the validity mask)
441426 idx_t sub_column_index = 1;
441427 auto unshredded_type = VariantShredding::GetUnshreddedType();
441428 sub_columns.push_back(
441429 ColumnData::CreateColumn(block_manager, info, sub_column_index++, unshredded_type, data_type, this));
441430 } else {
441431 // leave empty, gets populated by 'SetChildData'
441432 (void)validity;
441433 (void)sub_columns;
441434 }
441435}
atomic< ColumnDataType > data_type
Whether or not this column data belongs to a main table or if it is transaction local.
Definition duckdb.hpp:49469
optional_ptr< ColumnData > parent
The parent column (if any).
Definition duckdb.hpp:49471
LogicalType type
The type of the column.
Definition duckdb.hpp:49281
DataTableInfo & info
Table info for the column.
Definition duckdb.hpp:49277
idx_t column_index
The column index of the column, either within the parent table or within the parent.
Definition duckdb.hpp:49279
BlockManager & block_manager
The block manager.
Definition duckdb.hpp:49275
vector< shared_ptr< ColumnData > > sub_columns
The sub-columns of the struct.
Definition duckdb.cpp:428604
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ GetMaxEntry()

idx_t duckdb::VariantColumnData::GetMaxEntry ( )
overridevirtual

Reimplemented from duckdb::ColumnData.

441567 {
441568 return sub_columns[0]->GetMaxEntry();
441569}

◆ IsShredded()

bool duckdb::VariantColumnData::IsShredded ( ) const
inline
428609 {
428610 return sub_columns.size() == 2;
428611 }

◆ InitializePrefetch()

void duckdb::VariantColumnData::InitializePrefetch ( PrefetchState & prefetch_state,
ColumnScanState & scan_state,
idx_t rows )
overridevirtual

Initialize prefetch state with required I/O data for the next N rows.

FIXME: does this also need CreateScanStates ??

Reimplemented from duckdb::ColumnData.

441571 {
441573 validity->InitializePrefetch(prefetch_state, scan_state.child_states[0], rows);
441574 for (idx_t i = 0; i < sub_columns.size(); i++) {
441575 sub_columns[i]->InitializePrefetch(prefetch_state, scan_state.child_states[i + 1], rows);
441576 }
441577}
int rows
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeScan()

void duckdb::VariantColumnData::InitializeScan ( ColumnScanState & state)
overridevirtual

Initialize a scan of the column.

Reimplemented from duckdb::ColumnData.

441579 {
441580 CreateScanStates(state);
441581 state.current = nullptr;
441582
441583 // initialize the validity segment
441584 validity->InitializeScan(state.child_states[0]);
441585
441586 // initialize the sub-columns
441587 for (idx_t i = 0; i < sub_columns.size(); i++) {
441588 sub_columns[i]->InitializeScan(state.child_states[i + 1]);
441589 }
441590}
void CreateScanStates(ColumnScanState &state)
Definition duckdb.cpp:441537
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeScanWithOffset()

void duckdb::VariantColumnData::InitializeScanWithOffset ( ColumnScanState & state,
idx_t row_idx )
overridevirtual

Initialize a scan starting at the specified offset.

Reimplemented from duckdb::ColumnData.

441592 {
441593 CreateScanStates(state);
441594 state.current = nullptr;
441595
441596 // initialize the validity segment
441597 validity->InitializeScanWithOffset(state.child_states[0], row_idx);
441598
441599 // initialize the sub-columns
441600 for (idx_t i = 0; i < sub_columns.size(); i++) {
441601 sub_columns[i]->InitializeScanWithOffset(state.child_states[i + 1], row_idx);
441602 }
441603}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Scan()

idx_t duckdb::VariantColumnData::Scan ( TransactionData transaction,
idx_t vector_index,
ColumnScanState & state,
Vector & result,
idx_t scan_count )
overridevirtual

Reimplemented from duckdb::ColumnData.

441718 {
441719 return ScanWithCallback(state, result, target_count,
441720 [&](ColumnData &col, ColumnScanState &child_state, Vector &target_vector, idx_t count) {
441721 return col.Scan(transaction, vector_index, child_state, target_vector, count);
441722 });
441723}
atomic< idx_t > count
The count of the column data.
Definition duckdb.hpp:49273
idx_t ScanWithCallback(ColumnScanState &state, Vector &result, idx_t target_count, const std::function< idx_t(ColumnData &column, ColumnScanState &child_state, Vector &target_vector, idx_t count)> &callback) const
Definition duckdb.cpp:441617

◆ ScanCount()

idx_t duckdb::VariantColumnData::ScanCount ( ColumnScanState & state,
Vector & result,
idx_t count,
idx_t result_offset = 0 )
overridevirtual

Reimplemented from duckdb::ColumnData.

441725 {
441726 return ScanWithCallback(state, result, count,
441727 [&](ColumnData &col, ColumnScanState &child_state, Vector &target_vector, idx_t count) {
441728 return col.ScanCount(child_state, target_vector, count, result_offset);
441729 });
441730}

◆ Skip()

void duckdb::VariantColumnData::Skip ( ColumnScanState & state,
idx_t count = STANDARD_VECTOR_SIZE )
overridevirtual

Skip the scan forward by "count" rows.

Reimplemented from duckdb::ColumnData.

441732 {
441733 validity->Skip(state.child_states[0], count);
441734
441735 // skip inside the sub-columns
441736 for (idx_t child_idx = 0; child_idx < sub_columns.size(); child_idx++) {
441737 sub_columns[child_idx]->Skip(state.child_states[child_idx + 1], count);
441738 }
441739}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeAppend()

void duckdb::VariantColumnData::InitializeAppend ( ColumnAppendState & state)
overridevirtual

Initialize an appending phase for this column.

Reimplemented from duckdb::ColumnData.

441741 {
441742 ColumnAppendState validity_append;
441743 validity->InitializeAppend(validity_append);
441744 state.child_appends.push_back(std::move(validity_append));
441745
441746 for (idx_t i = 0; i < sub_columns.size(); i++) {
441747 auto &sub_column = sub_columns[i];
441748 ColumnAppendState child_append;
441749 sub_column->InitializeAppend(child_append);
441750 state.child_appends.push_back(std::move(child_append));
441751 }
441752}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Append()

void duckdb::VariantColumnData::Append ( BaseStatistics & stats,
ColumnAppendState & state,
Vector & vector,
idx_t count )
overridevirtual

Append a vector of type [type] to the end of the column.

Reimplemented from duckdb::ColumnData.

441790 {
441791 if (vector.GetVectorType() != VectorType::FLAT_VECTOR) {
441792 Vector append_vector(vector);
441793 append_vector.Flatten(count);
441794 Append(stats, state, append_vector, count);
441795 return;
441796 }
441797
441798 // append the null values
441799 validity->Append(stats, state.child_appends[0], vector, count);
441800
441801 if (IsShredded()) {
441802 throw InternalException("Can't append to a shredded VariantColumnData");
441803 } else {
441804 for (idx_t i = 0; i < sub_columns.size(); i++) {
441805 sub_columns[i]->Append(VariantStats::GetUnshreddedStats(stats), state.child_appends[i + 1], vector, count);
441806 }
441808 }
441809 this->count += count;
441810}
unique_ptr< SegmentStatistics > stats
The stats of the root segment.
Definition duckdb.hpp:49465
void Append(BaseStatistics &stats, ColumnAppendState &state, Vector &vector, idx_t count) override
Append a vector of type [type] to the end of the column.
Definition duckdb.cpp:441790
static DUCKDB_API void MarkAsNotShredded(BaseStatistics &stats)
Definition duckdb.cpp:425091
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RevertAppend()

void duckdb::VariantColumnData::RevertAppend ( row_t new_count)
overridevirtual

Revert a set of appends to the ColumnData.

Reimplemented from duckdb::ColumnData.

441812 {
441813 validity->RevertAppend(new_count);
441814 for (idx_t i = 0; i < sub_columns.size(); i++) {
441815 auto &sub_column = sub_columns[i];
441816 sub_column->RevertAppend(new_count);
441817 }
441818 this->count = UnsafeNumericCast<idx_t>(new_count);
441819}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Fetch()

idx_t duckdb::VariantColumnData::Fetch ( ColumnScanState & state,
row_t row_id,
Vector & result )
overridevirtual

Fetch the vector from the column data that belongs to this specific row.

Reimplemented from duckdb::ColumnData.

441821 {
441822 throw NotImplementedException("VARIANT Fetch");
441823}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FetchRow()

void duckdb::VariantColumnData::FetchRow ( TransactionData transaction,
ColumnFetchState & state,
const StorageIndex & storage_index,
row_t row_id,
Vector & result,
idx_t result_idx )
overridevirtual

Fetch a specific row id and append it to the vector.

Shredded field exists and is fully shredded, add the storage index to create a pushed-down 'struct_extract' to get the leaf

FIXME: adjust UnshredVariantData so we can write the value in place directly.

No extract required

No cast required

Need to perform the cast here as well

Reimplemented from duckdb::ColumnData.

441841 {
441842 if (storage_index.IsPushdownExtract() && IsShredded()) {
441843 StorageIndex struct_extract;
441844 if (PushdownShreddedFieldExtract(storage_index.GetChildIndex(0), struct_extract)) {
441847 sub_columns[1]->FetchRow(transaction, state, struct_extract, row_id, result, result_idx);
441848 return;
441849 }
441850 }
441851 Vector variant_vec(LogicalType::VARIANT(), result_idx + 1);
441852 validity->FetchRow(transaction, state, storage_index, row_id, variant_vec, result_idx);
441853 if (IsShredded()) {
441854 auto intermediate = CreateUnshreddingIntermediate(result_idx + 1);
441855 auto &child_vectors = StructVector::GetEntries(intermediate);
441856 // fetch the validity state
441857 // fetch the sub-column states
441858 StorageIndex empty(0);
441859 for (idx_t i = 0; i < sub_columns.size(); i++) {
441860 sub_columns[i]->FetchRow(transaction, state, empty, row_id, *child_vectors[i], result_idx);
441861 }
441862 if (result_idx) {
441863 intermediate.SetValue(0, intermediate.GetValue(result_idx));
441864 }
441865
441867 Vector unshredded(variant_vec.GetType(), 1);
441868 VariantColumnData::UnshredVariantData(intermediate, unshredded, 1);
441869 variant_vec.SetValue(0, unshredded.GetValue(0));
441870 } else {
441871 sub_columns[0]->FetchRow(transaction, state, storage_index, row_id, variant_vec, result_idx);
441872 if (result_idx) {
441873 variant_vec.SetValue(0, variant_vec.GetValue(result_idx));
441874 }
441875 }
441876
441877 if (!storage_index.IsPushdownExtract()) {
441879 D_ASSERT(result.GetType().id() == LogicalTypeId::VARIANT);
441880 result.SetValue(result_idx, variant_vec.GetValue(0));
441881 return;
441882 }
441883
441884 Vector extracted_variant(variant_vec.GetType(), 1);
441885 vector<VariantPathComponent> components;
441886 reference<const StorageIndex> path_iter(storage_index.GetChildIndex(0));
441887
441888 while (true) {
441889 auto &current = path_iter.get();
441890 auto &field_name = current.GetFieldName();
441891 components.emplace_back(field_name);
441892 if (!current.HasChildren()) {
441893 break;
441894 }
441895 path_iter = current.GetChildIndex(0);
441896 }
441897 VariantUtils::VariantExtract(variant_vec, components, extracted_variant, 1);
441898
441899 if (result.GetType().id() == LogicalTypeId::VARIANT) {
441901 result.SetValue(result_idx, extracted_variant.GetValue(0));
441902 return;
441903 }
441904
441906 auto context = transaction.transaction->context.lock();
441907 auto fetched_row = extracted_variant.GetValue(0).CastAs(*context, result.GetType());
441908 result.SetValue(result_idx, fetched_row);
441909}
bool PushdownShreddedFieldExtract(const StorageIndex &variant_extract, StorageIndex &out_struct_extract) const
Definition duckdb.cpp:441506
static DUCKDB_API LogicalType VARIANT()
Definition duckdb.cpp:140950
static DUCKDB_API void VariantExtract(Vector &input, const vector< VariantPathComponent > &components, Vector &result, idx_t count)
Definition duckdb.cpp:237857
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update()

void duckdb::VariantColumnData::Update ( TransactionData transaction,
DataTable & data_table,
idx_t column_index,
Vector & update_vector,
row_t * row_ids,
idx_t update_count,
idx_t row_group_start )
overridevirtual

Reimplemented from duckdb::ColumnData.

441826 {
441827 throw NotImplementedException("VARIANT Update is not supported.");
441828}

◆ UpdateColumn()

void duckdb::VariantColumnData::UpdateColumn ( TransactionData transaction,
DataTable & data_table,
const vector< column_t > & column_path,
Vector & update_vector,
row_t * row_ids,
idx_t update_count,
idx_t depth,
idx_t row_group_start )
overridevirtual

Reimplemented from duckdb::ColumnData.

441832 {
441833 throw NotImplementedException("VARIANT Update Column is not supported");
441834}

◆ GetUpdateStatistics()

unique_ptr< BaseStatistics > duckdb::VariantColumnData::GetUpdateStatistics ( )
overridevirtual

Reimplemented from duckdb::ColumnData.

441836 {
441837 return nullptr;
441838}

◆ VisitBlockIds()

void duckdb::VariantColumnData::VisitBlockIds ( BlockIdVisitor & visitor) const
overridevirtual

Reimplemented from duckdb::ColumnData.

441911 {
441912 validity->VisitBlockIds(visitor);
441913 for (idx_t i = 0; i < sub_columns.size(); i++) {
441914 auto &sub_column = sub_columns[i];
441915 sub_column->VisitBlockIds(visitor);
441916 }
441917}

◆ CreateCheckpointState()

unique_ptr< ColumnCheckpointState > duckdb::VariantColumnData::CreateCheckpointState ( const RowGroup & row_group,
PartialBlockManager & partial_block_manager )
overridevirtual

Reimplemented from duckdb::ColumnData.

441999 {
442000 return make_uniq<VariantColumnCheckpointState>(row_group, *this, partial_block_manager);
442001}

◆ Checkpoint()

unique_ptr< ColumnCheckpointState > duckdb::VariantColumnData::Checkpoint ( const RowGroup & row_group,
ColumnCheckpointInfo & info,
const BaseStatistics & old_stats )
overridevirtual

We couldn't determine a shredding type from the data

STRUCT(unshredded VARIANT, shredded <...>)

Now checkpoint the shredded data

Reimplemented from duckdb::ColumnData.

442092 {
442093 auto &partial_block_manager = checkpoint_info.GetPartialBlockManager();
442094 auto checkpoint_state = make_uniq<VariantColumnCheckpointState>(row_group, *this, partial_block_manager);
442095 checkpoint_state->validity_state = validity->Checkpoint(row_group, checkpoint_info, old_stats);
442096
442097 auto &table_info = row_group.GetTableInfo();
442098 auto &db = table_info.GetDB();
442099 auto &config = DBConfig::Get(db);
442100
442101 bool should_shred = true;
442102 if (!HasAnyChanges()) {
442103 should_shred = false;
442104 }
442105 if (!EnableShredding(Settings::Get<VariantMinimumShreddingSizeSetting>(config), count.load())) {
442106 should_shred = false;
442107 }
442108
442109 LogicalType shredded_type;
442110 if (should_shred) {
442111 if (config.options.force_variant_shredding.id() != LogicalTypeId::INVALID) {
442112 shredded_type = config.options.force_variant_shredding;
442113 } else {
442114 shredded_type = GetShreddedType();
442115 }
442116 D_ASSERT(shredded_type.id() == LogicalTypeId::STRUCT);
442117 auto &type_entries = StructType::GetChildTypes(shredded_type);
442118 if (type_entries.size() != 2) {
442120 should_shred = false;
442121 }
442122 }
442123
442124 if (!should_shred) {
442125 checkpoint_state->child_states.push_back(
442126 sub_columns[0]->Checkpoint(row_group, checkpoint_info, VariantStats::GetUnshreddedStats(old_stats)));
442127 if (sub_columns.size() > 1) {
442128 checkpoint_state->child_states.push_back(
442129 sub_columns[1]->Checkpoint(row_group, checkpoint_info, VariantStats::GetShreddedStats(old_stats)));
442130 }
442131 return std::move(checkpoint_state);
442132 }
442133
442135 BaseStatistics column_stats = BaseStatistics::CreateEmpty(shredded_type);
442136 checkpoint_state->shredded_data = WriteShreddedData(row_group, shredded_type, column_stats);
442137 D_ASSERT(checkpoint_state->shredded_data.size() == 2);
442138 auto &unshredded = checkpoint_state->shredded_data[0];
442139 auto &shredded = checkpoint_state->shredded_data[1];
442140
442142 checkpoint_state->child_states.push_back(
442143 unshredded->Checkpoint(row_group, checkpoint_info, VariantStats::GetUnshreddedStats(column_stats)));
442144 checkpoint_state->child_states.push_back(
442145 shredded->Checkpoint(row_group, checkpoint_info, VariantStats::GetShreddedStats(column_stats)));
442146
442147 return std::move(checkpoint_state);
442148}
static BaseStatistics CreateEmpty(LogicalType type)
Definition duckdb.cpp:422871
bool HasAnyChanges() const override
Whether or not the column has ANY changes, including in child columns.
Definition duckdb.cpp:442163
vector< shared_ptr< ColumnData > > WriteShreddedData(const RowGroup &row_group, const LogicalType &shredded_type, BaseStatistics &stats)
Definition duckdb.cpp:442003
unique_ptr< ColumnCheckpointState > Checkpoint(const RowGroup &row_group, ColumnCheckpointInfo &info, const BaseStatistics &old_stats) override
Definition duckdb.cpp:442090
LogicalType GetShreddedType()
Definition duckdb.cpp:442060
db
static bool EnableShredding(int64_t minimum_size, idx_t current_size)
Definition duckdb.cpp:442082
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsPersistent()

bool duckdb::VariantColumnData::IsPersistent ( )
overridevirtual

Reimplemented from duckdb::ColumnData.

442150 {
442151 if (!validity->IsPersistent()) {
442152 return false;
442153 }
442154 for (idx_t i = 0; i < sub_columns.size(); i++) {
442155 auto &sub_column = sub_columns[i];
442156 if (!sub_column->IsPersistent()) {
442157 return false;
442158 }
442159 }
442160 return true;
442161}

◆ HasAnyChanges()

bool duckdb::VariantColumnData::HasAnyChanges ( ) const
overridevirtual

Whether or not the column has ANY changes, including in child columns.

Reimplemented from duckdb::ColumnData.

442163 {
442164 if (validity->HasAnyChanges()) {
442165 return true;
442166 }
442167 for (idx_t i = 0; i < sub_columns.size(); i++) {
442168 auto &sub_column = sub_columns[i];
442169 if (sub_column->HasAnyChanges()) {
442170 return true;
442171 }
442172 }
442173 return false;
442174}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serialize()

PersistentColumnData duckdb::VariantColumnData::Serialize ( )
overridevirtual

Reimplemented from duckdb::ColumnData.

442176 {
442177 PersistentColumnData persistent_data(type);
442178 if (IsShredded()) {
442179 // Set the extra data to indicate that this is shredded data
442180 persistent_data.extra_data = make_uniq<VariantPersistentColumnData>(sub_columns[1]->type);
442181 }
442182 persistent_data.child_columns.push_back(validity->Serialize());
442183 for (idx_t i = 0; i < sub_columns.size(); i++) {
442184 auto &sub_column = sub_columns[i];
442185 persistent_data.child_columns.push_back(sub_column->Serialize());
442186 }
442187 return persistent_data;
442188}

◆ InitializeColumn()

void duckdb::VariantColumnData::InitializeColumn ( PersistentColumnData & column_data,
BaseStatistics & target_stats )
overridevirtual

This means the VARIANT is shredded

Reimplemented from duckdb::ColumnData.

442190 {
442191 validity->InitializeColumn(column_data.child_columns[0], target_stats);
442192
442193 if (column_data.child_columns.size() == 3) {
442195 auto &unshredded_stats = VariantStats::GetUnshreddedStats(target_stats);
442196 sub_columns[0]->InitializeColumn(column_data.child_columns[1], unshredded_stats);
442197
442198 // TODO:
442199 D_ASSERT(column_data.extra_data);
442200 auto &variant_extra_data = column_data.extra_data->Cast<VariantPersistentColumnData>();
442201 auto &shredded_type = variant_extra_data.logical_type;
442202 if (!IsShredded()) {
442203 VariantStats::SetShreddedStats(target_stats, BaseStatistics::CreateEmpty(shredded_type));
442204 sub_columns.push_back(ColumnData::CreateColumn(block_manager, info, 2, shredded_type, GetDataType(), this));
442205 }
442206 auto &shredded_stats = VariantStats::GetShreddedStats(target_stats);
442207 sub_columns[1]->InitializeColumn(column_data.child_columns[2], shredded_stats);
442208 } else {
442209 auto &unshredded_stats = VariantStats::GetUnshreddedStats(target_stats);
442210 sub_columns[0]->InitializeColumn(column_data.child_columns[1], unshredded_stats);
442211 }
442212 this->count = validity->count.load();
442213}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetColumnSegmentInfo()

void duckdb::VariantColumnData::GetColumnSegmentInfo ( const QueryContext & context,
duckdb::idx_t row_group_index,
vector< duckdb::idx_t > col_path,
vector< duckdb::ColumnSegmentInfo > & result )
overridevirtual

Reimplemented from duckdb::ColumnData.

442216 {
442217 col_path.push_back(0);
442218 validity->GetColumnSegmentInfo(context, row_group_index, col_path, result);
442219 for (idx_t i = 0; i < sub_columns.size(); i++) {
442220 col_path.back() = i + 1;
442221 sub_columns[i]->GetColumnSegmentInfo(context, row_group_index, col_path, result);
442222 }
442223}

◆ Verify()

void duckdb::VariantColumnData::Verify ( RowGroup & parent)
overridevirtual

Reimplemented from duckdb::ColumnData.

442225 {
442226#ifdef DEBUG
442227 ColumnData::Verify(parent);
442228 validity->Verify(parent);
442229 for (idx_t i = 0; i < sub_columns.size(); i++) {
442230 auto &sub_column = sub_columns[i];
442231 sub_column->Verify(parent);
442232 }
442233#endif
442234}

◆ ShredVariantData()

void duckdb::VariantColumnData::ShredVariantData ( Vector & input,
Vector & output,
idx_t count )
static

First traverse the Variant to write the shredded values and collect the 'untyped_value_index'es

Now we can write the unshredded values

Allocate for the new data, use the same size as source

441040 {
441041 RecursiveUnifiedVectorFormat recursive_format;
441042 Vector::RecursiveToUnifiedFormat(input, count, recursive_format);
441043 UnifiedVariantVectorData variant(recursive_format);
441044
441045 auto &child_vectors = StructVector::GetEntries(output);
441046
441048 DuckDBVariantShredding shredding(count);
441049 shredding.WriteVariantValues(variant, *child_vectors[1], nullptr, nullptr, nullptr, count);
441050
441052 auto &unshredded = *child_vectors[0];
441053 auto original_keys_size = ListVector::GetListSize(VariantVector::GetKeys(input));
441054 auto original_children_size = ListVector::GetListSize(VariantVector::GetChildren(input));
441055 auto original_values_size = ListVector::GetListSize(VariantVector::GetValues(input));
441056
441057 auto &keys = VariantVector::GetKeys(unshredded);
441058 auto &children = VariantVector::GetChildren(unshredded);
441059 auto &values = VariantVector::GetValues(unshredded);
441060 auto &data = VariantVector::GetData(unshredded);
441061
441062 ListVector::Reserve(keys, original_keys_size);
441063 ListVector::SetListSize(keys, 0);
441064 ListVector::Reserve(children, original_children_size);
441065 ListVector::SetListSize(children, 0);
441066 ListVector::Reserve(values, original_values_size);
441067 ListVector::SetListSize(values, 0);
441068
441069 auto &keys_entry = ListVector::GetEntry(keys);
441070 OrderedOwningStringMap<uint32_t> dictionary(StringVector::GetStringBuffer(keys_entry).GetStringAllocator());
441071 SelectionVector keys_selvec;
441072 keys_selvec.Initialize(original_keys_size);
441073
441074 VariantVectorData variant_data(unshredded);
441075 for (idx_t row = 0; row < count; row++) {
441076 auto &unshredded_values = shredding.unshredded_values[row];
441077
441078 if (unshredded_values.empty()) {
441079 FlatVector::SetNull(unshredded, row, true);
441080 continue;
441081 }
441082
441084 auto &blob_data = variant_data.blob_data[row];
441085 auto original_data = variant.GetData(row);
441086 blob_data = StringVector::EmptyString(data, original_data.GetSize());
441087
441088 auto &keys_list_entry = variant_data.keys_data[row];
441089 keys_list_entry.offset = ListVector::GetListSize(keys);
441090
441091 auto &children_list_entry = variant_data.children_data[row];
441092 children_list_entry.offset = ListVector::GetListSize(children);
441093
441094 auto &values_list_entry = variant_data.values_data[row];
441095 values_list_entry.offset = ListVector::GetListSize(values);
441096
441097 VariantNormalizerState normalizer_state(row, variant_data, dictionary, keys_selvec);
441098 for (idx_t i = 0; i < unshredded_values.size(); i++) {
441099 auto &unshredded_value = unshredded_values[i];
441100 auto value_index = unshredded_value.source_value_index;
441101
441102 unshredded_value.target_value_index = normalizer_state.values_size + 1;
441103 if (!unshredded_value.unshredded_children.empty()) {
441104 D_ASSERT(variant.GetTypeId(row, value_index) == VariantLogicalType::OBJECT);
441105 auto nested_data = VariantUtils::DecodeNestedData(variant, row, value_index);
441106
441107 normalizer_state.type_ids[normalizer_state.values_size] =
441108 static_cast<uint8_t>(VariantLogicalType::OBJECT);
441109 normalizer_state.byte_offsets[normalizer_state.values_size] = normalizer_state.blob_size;
441110 normalizer_state.values_size++;
441111 VisitObject(variant, row, nested_data, normalizer_state, unshredded_value.unshredded_children);
441112 continue;
441113 }
441114 VariantVisitor<VariantNormalizer>::Visit(variant, row, value_index, normalizer_state);
441115 }
441116 blob_data.SetSizeAndFinalize(normalizer_state.blob_size, original_data.GetSize());
441117 keys_list_entry.length = normalizer_state.keys_size;
441118 children_list_entry.length = normalizer_state.children_size;
441119 values_list_entry.length = normalizer_state.values_size;
441120
441121 ListVector::SetListSize(keys, ListVector::GetListSize(keys) + normalizer_state.keys_size);
441122 ListVector::SetListSize(children, ListVector::GetListSize(children) + normalizer_state.children_size);
441123 ListVector::SetListSize(values, ListVector::GetListSize(values) + normalizer_state.values_size);
441124 }
441125
441126 VariantUtils::FinalizeVariantKeys(unshredded, dictionary, keys_selvec, ListVector::GetListSize(keys));
441127 keys_entry.Slice(keys_selvec, ListVector::GetListSize(keys));
441128
441129 if (input.GetVectorType() == VectorType::CONSTANT_VECTOR) {
441130 unshredded.SetVectorType(VectorType::CONSTANT_VECTOR);
441131 }
441132
441133#ifdef DEBUG
441134 Vector roundtrip_result(LogicalType::VARIANT(), count);
441135 VariantColumnData::UnshredVariantData(output, roundtrip_result, count);
441136
441137 for (idx_t i = 0; i < count; i++) {
441138 auto input_val = input.GetValue(i);
441139 auto roundtripped_val = roundtrip_result.GetValue(i);
441140 if (!ValueOperations::NotDistinctFrom(input_val, roundtripped_val)) {
441141 throw InternalException("Shredding roundtrip verification failed for row: %d, expected: %s, actual: %s", i,
441142 input_val.ToString(), roundtripped_val.ToString());
441143 }
441144 }
441145
441146#endif
441147}
ColumnSegmentTree data
The segments holding the data of this column segment.
Definition duckdb.hpp:49455
static void RecursiveToUnifiedFormat(Vector &input, idx_t count, RecursiveUnifiedVectorFormat &data)
Recursively calls UnifiedVectorFormat on a vector and its child vectors (for nested types).
Definition duckdb.cpp:136924
::uint8_t uint8_t
static void VisitObject(const UnifiedVariantVectorData &variant, idx_t row, const VariantNestedData &nested_data, VariantNormalizerState &state, const vector< uint32_t > &child_indices)
Definition duckdb.cpp:440857
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of a list.
Definition duckdb.cpp:138203
static DUCKDB_API void SetListSize(Vector &vec, idx_t size)
Sets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138248
static DUCKDB_API void Reserve(Vector &vec, idx_t required_capacity)
Sets the total capacity of the underlying child-vector of a list.
Definition duckdb.cpp:138211
static DUCKDB_API idx_t GetListSize(const Vector &vector)
Gets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138221
static DUCKDB_API string_t EmptyString(Vector &vector, idx_t len)
Definition duckdb.cpp:137942
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
static DUCKDB_API void FinalizeVariantKeys(Vector &variant, OrderedOwningStringMap< uint32_t > &dictionary, SelectionVector &sel, idx_t sel_size)
Definition duckdb.cpp:238627
static DUCKDB_API Vector & GetKeys(Vector &vec)
Gets a reference to the 'keys' list (dictionary) of a Variant.
Definition duckdb.cpp:138595
static DUCKDB_API Vector & GetData(Vector &vec)
Gets a reference to the binary blob 'value', which encodes the data of the row.
Definition duckdb.cpp:138652
static DUCKDB_API Vector & GetChildren(Vector &vec)
Gets a reference to the 'children' list of a Variant.
Definition duckdb.cpp:138602
static DUCKDB_API Vector & GetValues(Vector &vec)
Gets a reference to the 'values' list of a Variant.
Definition duckdb.cpp:138627
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnshredVariantData()

void duckdb::VariantColumnData::UnshredVariantData ( Vector & input,
Vector & output,
idx_t count )
static
441387 {
441388 D_ASSERT(input.GetType().id() == LogicalTypeId::STRUCT);
441389 auto &child_vectors = StructVector::GetEntries(input);
441390 D_ASSERT(child_vectors.size() == 2);
441391
441392 auto &unshredded = *child_vectors[0];
441393 auto &shredded = *child_vectors[1];
441394
441395 RecursiveUnifiedVectorFormat recursive_format;
441396 Vector::RecursiveToUnifiedFormat(unshredded, count, recursive_format);
441397 UnifiedVariantVectorData variant(recursive_format);
441398
441399 auto variant_values = Unshred(variant, shredded, count, nullptr);
441400 VariantValue::ToVARIANT(variant_values, output);
441401}
static vector< VariantValue > Unshred(UnifiedVariantVectorData &variant, Vector &shredded, idx_t count, optional_ptr< SelectionVector > row_sel)
Definition duckdb.cpp:441328
static void ToVARIANT(vector< VariantValue > &input, Vector &result)
Definition duckdb.cpp:135093

◆ SetValidityData()

void duckdb::VariantColumnData::SetValidityData ( shared_ptr< ValidityColumnData > validity_p)
441919 {
441920 if (validity) {
441921 throw InternalException("VariantColumnData::SetValidityData cannot be used to overwrite existing validity");
441922 }
441923 validity_p->SetParent(this);
441924 this->validity = std::move(validity_p);
441925}

◆ SetChildData()

void duckdb::VariantColumnData::SetChildData ( vector< shared_ptr< ColumnData > > child_data)
441927 {
441928 if (!sub_columns.empty()) {
441929 throw InternalException("VariantColumnData::SetChildData cannot be used to overwrite existing data");
441930 }
441931 for (auto &col : child_data) {
441932 col->SetParent(this);
441933 }
441934 this->sub_columns = std::move(child_data);
441935}

◆ CreateUnshreddingIntermediate()

Vector duckdb::VariantColumnData::CreateUnshreddingIntermediate ( idx_t count) const
private
441605 {
441606 D_ASSERT(IsShredded());
441607 D_ASSERT(sub_columns.size() == 2);
441608
441609 child_list_t<LogicalType> child_types;
441610 child_types.emplace_back("unshredded", sub_columns[0]->type);
441611 child_types.emplace_back("shredded", sub_columns[1]->type);
441612 auto intermediate_type = LogicalType::STRUCT(child_types);
441613 Vector intermediate(intermediate_type, count);
441614 return intermediate;
441615}

◆ WriteShreddedData()

vector< shared_ptr< ColumnData > > duckdb::VariantColumnData::WriteShreddedData ( const RowGroup & row_group,
const LogicalType & shredded_type,
BaseStatistics & stats )
private

scan_chunk

append_chunk

Create the new column data for the shredded data

Scan + transform + append

442005 {
442007 DataChunk scan_chunk;
442008 scan_chunk.Initialize(Allocator::DefaultAllocator(), {LogicalType::VARIANT()}, STANDARD_VECTOR_SIZE);
442009 auto &scan_vector = scan_chunk.data[0];
442010
442012 auto &child_types = StructType::GetChildTypes(shredded_type);
442013
442014 DataChunk append_chunk;
442015 append_chunk.Initialize(Allocator::DefaultAllocator(), {shredded_type}, STANDARD_VECTOR_SIZE);
442016 auto &append_vector = append_chunk.data[0];
442017
442019 D_ASSERT(child_types.size() == 2);
442020 auto &unshredded_type = child_types[0].second;
442021 auto &typed_value_type = child_types[1].second;
442022
442023 vector<shared_ptr<ColumnData>> ret(2);
442024 ret[0] = ColumnData::CreateColumn(block_manager, info, 1, unshredded_type, GetDataType(), this);
442025 ret[1] = ColumnData::CreateColumn(block_manager, info, 2, typed_value_type, GetDataType(), this);
442026 auto &unshredded = ret[0];
442027 auto &shredded = ret[1];
442028
442029 ColumnAppendState unshredded_append_state;
442030 unshredded->InitializeAppend(unshredded_append_state);
442031
442032 ColumnAppendState shredded_append_state;
442033 shredded->InitializeAppend(shredded_append_state);
442034
442035 ColumnScanState scan_state(nullptr);
442036
442037 InitializeScan(scan_state);
442039 idx_t total_count = count.load();
442040
442041 auto transformed_stats = VariantStats::CreateShredded(typed_value_type);
442042 auto &unshredded_stats = VariantStats::GetUnshreddedStats(transformed_stats);
442043 auto &shredded_stats = VariantStats::GetShreddedStats(transformed_stats);
442044
442045 VariantShreddedAppendInput append_data {*unshredded, *shredded, unshredded_append_state,
442046 shredded_append_state, unshredded_stats, shredded_stats};
442047 idx_t vector_index = 0;
442048 for (idx_t scanned = 0; scanned < total_count; scanned += STANDARD_VECTOR_SIZE) {
442049 scan_chunk.Reset();
442050 auto to_scan = MinValue(total_count - scanned, static_cast<idx_t>(STANDARD_VECTOR_SIZE));
442051 Scan(TransactionData::Committed(), vector_index++, scan_state, scan_vector, to_scan);
442052 append_chunk.Reset();
442053
442054 AppendShredded(scan_vector, append_vector, to_scan, append_data);
442055 }
442056 stats = std::move(transformed_stats);
442057 return ret;
442058}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
void InitializeScan(ColumnScanState &state) override
Initialize a scan of the column.
Definition duckdb.cpp:441579
static void AppendShredded(Vector &input, Vector &append_vector, idx_t count, VariantShreddedAppendInput &append_data)
Definition duckdb.cpp:441767
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PushdownShreddedFieldExtract()

bool duckdb::VariantColumnData::PushdownShreddedFieldExtract ( const StorageIndex & variant_extract,
StorageIndex & out_struct_extract ) const
private

FIXME: this happens when we Checkpoint but don't restart, the stats of the ColumnData aren't updated by Checkpoint The variant is shredded, but there are no stats / the stats are cluttered (?)

shredded.typed_value

Can't push down an extract if the leaf we're extracting is not a primitive (Since the shredded representation for OBJECT/ARRAY is interleaved with 'untyped_value_index' fields)

441507 {
441508 D_ASSERT(IsShredded());
441509 auto &shredded = *sub_columns[1];
441510 auto &variant_stats = GetStatisticsRef();
441511
441512 if (!VariantStats::IsShredded(variant_stats)) {
441515 return false;
441516 }
441517
441519 ColumnIndex column_index(0);
441520
441521 reference<const BaseStatistics> shredded_stats(VariantStats::GetShreddedStats(variant_stats));
441522 reference<const StorageIndex> path_iter(variant_extract);
441523 if (!FindShreddedColumnInternal(shredded, shredded_stats, path_iter, column_index)) {
441524 return false;
441525 }
441526 if (shredded_stats.get().GetType().IsNested()) {
441529 return false;
441530 }
441531
441532 column_index.SetPushdownExtractType(shredded.type, path_iter.get().GetType());
441533 out_struct_extract = StorageIndex::FromColumnIndex(column_index);
441534 return true;
441535}
bool FindShreddedColumnInternal(const ColumnData &shredded, reference< const BaseStatistics > &stats, reference< const StorageIndex > &path_iter, ColumnIndex &out)
Definition duckdb.cpp:441437
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateScanStates()

void duckdb::VariantColumnData::CreateScanStates ( ColumnScanState & state)
private

Re-initialize the scan state, since VARIANT can have a different shape for every RowGroup

Shredded field exists and is fully shredded, add the storage index to create a pushed-down 'struct_extract' to get the leaf

441537 {
441539 state.child_states.clear();
441540
441541 state.child_states.emplace_back(state.parent);
441542 state.child_states[0].scan_options = state.scan_options;
441543
441544 auto unshredded_type = VariantShredding::GetUnshreddedType();
441545 state.child_states.emplace_back(state.parent);
441546 state.child_states[1].Initialize(state.context, unshredded_type, state.scan_options);
441547
441548 const bool is_pushed_down_cast =
441549 state.storage_index.HasType() && state.storage_index.GetScanType().id() != LogicalTypeId::VARIANT;
441550 if (IsShredded()) {
441551 auto &shredded_column = sub_columns[1];
441552 state.child_states.emplace_back(state.parent);
441553 if (state.storage_index.IsPushdownExtract() && is_pushed_down_cast) {
441554 StorageIndex struct_extract;
441555 if (PushdownShreddedFieldExtract(state.storage_index.GetChildIndex(0), struct_extract)) {
441558 state.child_states[2].Initialize(state.context, shredded_column->type, struct_extract,
441559 state.scan_options);
441560 return;
441561 }
441562 }
441563 state.child_states[2].Initialize(state.context, shredded_column->type, state.scan_options);
441564 }
441565}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScanWithCallback()

idx_t duckdb::VariantColumnData::ScanWithCallback ( ColumnScanState & state,
Vector & result,
idx_t target_count,
const std::function< idx_t(ColumnData &column, ColumnScanState &child_state, Vector &target_vector, idx_t count)> & callback ) const
private

FIXME: We could also push down the extract if we're returning VARIANT Then we can do the unshredding on the extracted data, rather than falling back to unshredding+extracting This invariant is ensured by CreateScanStates

In the initialize we have verified that the field exists and the data is fully shredded (for this rowgroup) We have created a scan state that performs a 'struct_extract' in the shredded data, to extract the requested field.s

Shredded ARRAY Variant looks like: LIST(STRUCT(typed_value <child_type>, untyped_value_index UINTEGER)) We need to transform this to: LIST(<child_type>)

Fall back to unshredding

441620 {
441621 if (state.storage_index.IsPushdownExtract()) {
441622 if (IsShredded() && state.child_states[2].storage_index.IsPushdownExtract()) {
441626 D_ASSERT(result.GetType().id() != LogicalTypeId::VARIANT);
441627
441631 auto res = callback(*sub_columns[1], state.child_states[2], result, target_count);
441632 if (result.GetType().id() == LogicalTypeId::LIST) {
441637
441638 auto &list_child = ListVector::GetEntry(result);
441639 D_ASSERT(list_child.GetType().id() == LogicalTypeId::STRUCT);
441640 D_ASSERT(StructType::GetChildCount(list_child.GetType()) == 2);
441641
441642 auto &typed_value = *StructVector::GetEntries(list_child)[TYPED_VALUE_INDEX];
441643 auto list_res = Vector(LogicalType::LIST(typed_value.GetType()));
441645 list_res.CopyBuffer(result);
441646 ListVector::GetEntry(list_res).Reference(typed_value);
441647 return res;
441648 }
441649 return res;
441650 }
441652 Vector intermediate(LogicalType::VARIANT(), target_count);
441653 idx_t scan_count;
441654 if (IsShredded()) {
441655 auto unshredding_intermediate = CreateUnshreddingIntermediate(target_count);
441656 auto &child_vectors = StructVector::GetEntries(unshredding_intermediate);
441657
441658 callback(*sub_columns[0], state.child_states[1], *child_vectors[0], target_count);
441659 callback(*sub_columns[1], state.child_states[2], *child_vectors[1], target_count);
441660 scan_count = callback(*validity, state.child_states[0], unshredding_intermediate, target_count);
441661
441662 VariantColumnData::UnshredVariantData(unshredding_intermediate, intermediate, target_count);
441663 } else {
441664 scan_count = callback(*validity, state.child_states[0], intermediate, target_count);
441665 callback(*sub_columns[0], state.child_states[1], intermediate, target_count);
441666 }
441667
441668 Vector extract_intermediate(LogicalType::VARIANT(), target_count);
441669 vector<VariantPathComponent> components;
441670 reference<const StorageIndex> path_iter(state.storage_index.GetChildIndex(0));
441671
441672 while (true) {
441673 auto &current = path_iter.get();
441674 auto &field_name = current.GetFieldName();
441675 components.emplace_back(field_name);
441676 if (!current.HasChildren()) {
441677 break;
441678 }
441679 path_iter = current.GetChildIndex(0);
441680 }
441681 VariantUtils::VariantExtract(intermediate, components, extract_intermediate, target_count);
441682
441683 if (state.expression_state) {
441684 auto &expression_state = *state.expression_state;
441685 auto &executor = expression_state.executor;
441686
441687 auto &input = expression_state.input;
441688 auto &target = expression_state.target;
441689 input.Reset();
441690 target.Reset();
441691 input.data[0].Reference(extract_intermediate);
441692 input.SetCardinality(scan_count);
441693 executor.Execute(input, target);
441694 result.Reference(target.data[0]);
441695 } else {
441696 result.Reference(extract_intermediate);
441697 }
441698 return scan_count;
441699 } else {
441700 if (IsShredded()) {
441701 auto intermediate = CreateUnshreddingIntermediate(target_count);
441702 auto &child_vectors = StructVector::GetEntries(intermediate);
441703
441704 callback(*sub_columns[0], state.child_states[1], *child_vectors[0], target_count);
441705 callback(*sub_columns[1], state.child_states[2], *child_vectors[1], target_count);
441706 auto scan_count = callback(*validity, state.child_states[0], intermediate, target_count);
441707
441708 VariantColumnData::UnshredVariantData(intermediate, result, target_count);
441709 return scan_count;
441710 }
441711 auto scan_count = callback(*validity, state.child_states[0], result, target_count);
441712 callback(*sub_columns[0], state.child_states[1], result, target_count);
441713 return scan_count;
441714 }
441715}
static constexpr idx_t TYPED_VALUE_INDEX
Indices into the inner shredded struct: STRUCT(typed_value <type>, untyped_value_index UINTEGER).
Definition duckdb.cpp:428596
DUCKDB_API void Reference(const Value &value)
Create a vector that references the specified value.
Definition duckdb.cpp:135784
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetShreddedType()

LogicalType duckdb::VariantColumnData::GetShreddedType ( )
private

scan_chunk

442060 {
442061 VariantShreddingStats variant_stats;
442062
442064 DataChunk scan_chunk;
442065 scan_chunk.Initialize(Allocator::DefaultAllocator(), {LogicalType::VARIANT()}, STANDARD_VECTOR_SIZE);
442066 auto &scan_vector = scan_chunk.data[0];
442067
442068 ColumnScanState scan_state(nullptr);
442069 InitializeScan(scan_state);
442070 idx_t total_count = count.load();
442071 idx_t vector_index = 0;
442072 for (idx_t scanned = 0; scanned < total_count; scanned += STANDARD_VECTOR_SIZE) {
442073 scan_chunk.Reset();
442074 auto to_scan = MinValue(total_count - scanned, static_cast<idx_t>(STANDARD_VECTOR_SIZE));
442075 Scan(TransactionData::Committed(), vector_index++, scan_state, scan_vector, to_scan);
442076 variant_stats.Update(scan_vector, to_scan);
442077 }
442078
442079 return variant_stats.GetShreddedType();
442080}
Here is the call graph for this function:
Here is the caller graph for this function:

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