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

Public Types

using Aggregates = vector<AggregateObject>
using ValidityBytes = TemplatedValidityMask<uint8_t>

Public Member Functions

 TupleDataLayout ()
 Creates an empty TupleDataLayout.
TupleDataLayout Copy () const
 Create a copy of this TupleDataLayout.
void Initialize (vector< LogicalType > types_p, Aggregates aggregates_p, TupleDataValidityType validity_type, TupleDataNestednessType nestedness_type=TupleDataNestednessType::TOP_LEVEL_LAYOUT)
 Initializes the TupleDataLayout with the specified types and aggregates to an empty TupleDataLayout.
void Initialize (vector< LogicalType > types, TupleDataValidityType validity_type, TupleDataNestednessType nestedness_type=TupleDataNestednessType::TOP_LEVEL_LAYOUT)
 Initializes the TupleDataLayout with the specified types to an empty TupleDataLayout.
void Initialize (Aggregates aggregates_p)
 Initializes the TupleDataLayout with the specified aggregates to an empty TupleDataLayout.
void Initialize (const vector< BoundOrderByNode > &orders, const LogicalType &type, bool has_payload)
 Initializes a TupleDataLayout with the specified ORDER BY to an empty TupleDataLayout.
idx_t ColumnCount () const
 Returns the number of data columns.
const vector< LogicalType > & GetTypes () const
 Returns a list of the column types for this data chunk.
idx_t AggregateCount () const
 Returns the number of aggregates.
Aggregates & GetAggregates ()
 Returns a list of the aggregates for this data chunk.
const Aggregates & GetAggregates () const
SortKeyType GetSortKeyType () const
 Gets the sort key type of this layout (if applicable).
bool IsSortKeyLayout () const
 Returns whether this is a sort key layout (in implementation file to avoid including here).
const TupleDataLayout & GetStructLayout (idx_t col_idx) const
 Returns a map from column id to the struct TupleDataLayout.
idx_t GetRowWidth () const
 Returns the total width required for each row, including padding.
idx_t GetDataOffset () const
 Returns the offset to the start of the data.
idx_t GetDataWidth () const
 Returns the total width required for the data, including padding.
idx_t GetAggrOffset () const
 Returns the offset to the start of the aggregates.
idx_t GetAggrWidth () const
 Returns the total width required for the aggregates, including padding.
idx_t GetSortWidth () const
 Returns the total width required for sorting.
const vector< idx_t > & GetSortSkippableBytes () const
const vector< idx_t > & GetOffsets () const
 Returns the column offsets into each row.
bool AllConstant () const
 Returns whether all columns in this layout are constant size.
const vector< idx_t > & GetVariableColumns () const
idx_t GetHeapSizeOffset () const
 Gets offset to where heap size is stored.
bool HasDestructor () const
 Returns whether any of the aggregates have a destructor.
const vector< idx_t > & GetAggregateDestructorIndices () const
 Returns the indices of the aggregates that have destructors.
bool AllValid () const
 Returns whether none of the columns have NULLs.

Private Attributes

vector< LogicalType > types
 The types of the data columns.
Aggregates aggregates
 The aggregate functions.
SortKeyType sort_key_type
 The sort key type associated with orders.
unique_ptr< unordered_map< idx_t, TupleDataLayout > > struct_layouts
 Structs are a recursive TupleDataLayout.
idx_t flag_width
 The width of the validity header.
idx_t data_width
 The width of the data portion.
idx_t aggr_width
 The width of the aggregate state portion.
idx_t sort_width
 The width of the sort key.
vector< idx_t > sort_skippable_bytes
 Bytes that are skippable during sorting.
idx_t row_width
 The width of the entire row.
vector< idx_t > offsets
 The offsets to the columns and aggregate data in each row.
bool all_constant
 Whether all columns in this layout are constant size.
vector< idx_t > variable_columns
 Indices of the variable columns.
idx_t heap_size_offset
 Offset to the heap size of every row.
vector< idx_t > aggr_destructor_idxs
 Indices of aggregate functions that have a destructor.
TupleDataValidityType validity_type
 Whether none of the columns have NULLs.

Constructor & Destructor Documentation

◆ TupleDataLayout()

duckdb::TupleDataLayout::TupleDataLayout ( )

Creates an empty TupleDataLayout.

126532 : sort_key_type(SortKeyType::INVALID), flag_width(0), data_width(0), aggr_width(0), row_width(0),
126533 all_constant(true), heap_size_offset(0), validity_type(TupleDataValidityType::CAN_HAVE_NULL_VALUES) {
126534}
SortKeyType sort_key_type
The sort key type associated with orders.
Definition duckdb.cpp:56240
idx_t data_width
The width of the data portion.
Definition duckdb.cpp:56246
bool all_constant
Whether all columns in this layout are constant size.
Definition duckdb.cpp:56258
idx_t row_width
The width of the entire row.
Definition duckdb.cpp:56254
idx_t aggr_width
The width of the aggregate state portion.
Definition duckdb.cpp:56248
idx_t heap_size_offset
Offset to the heap size of every row.
Definition duckdb.cpp:56262
idx_t flag_width
The width of the validity header.
Definition duckdb.cpp:56244
TupleDataValidityType validity_type
Whether none of the columns have NULLs.
Definition duckdb.cpp:56266
Here is the caller graph for this function:

Member Function Documentation

◆ Copy()

TupleDataLayout duckdb::TupleDataLayout::Copy ( ) const

Create a copy of this TupleDataLayout.

126536 {
126537 TupleDataLayout result;
126538 result.types = this->types;
126539 result.aggregates = this->aggregates;
126540 result.sort_key_type = this->sort_key_type;
126541 if (this->struct_layouts) {
126542 result.struct_layouts = make_uniq<unordered_map<idx_t, TupleDataLayout>>();
126543 for (const auto &entry : *this->struct_layouts) {
126544 result.struct_layouts->emplace(entry.first, entry.second.Copy());
126545 }
126546 }
126547 result.flag_width = this->flag_width;
126548 result.data_width = this->data_width;
126549 result.aggr_width = this->aggr_width;
126550 result.sort_width = this->sort_width;
126551 result.sort_skippable_bytes = this->sort_skippable_bytes;
126552 result.row_width = this->row_width;
126553 result.offsets = this->offsets;
126554 result.all_constant = this->all_constant;
126555 result.heap_size_offset = this->heap_size_offset;
126556 result.aggr_destructor_idxs = this->aggr_destructor_idxs;
126557 result.validity_type = this->validity_type;
126558 return result;
126559}
Aggregates aggregates
The aggregate functions.
Definition duckdb.cpp:56238
unique_ptr< unordered_map< idx_t, TupleDataLayout > > struct_layouts
Structs are a recursive TupleDataLayout.
Definition duckdb.cpp:56242
vector< idx_t > offsets
The offsets to the columns and aggregate data in each row.
Definition duckdb.cpp:56256
idx_t sort_width
The width of the sort key.
Definition duckdb.cpp:56250
vector< idx_t > sort_skippable_bytes
Bytes that are skippable during sorting.
Definition duckdb.cpp:56252
TupleDataLayout()
Creates an empty TupleDataLayout.
Definition duckdb.cpp:126531
vector< idx_t > aggr_destructor_idxs
Indices of aggregate functions that have a destructor.
Definition duckdb.cpp:56264
vector< LogicalType > types
The types of the data columns.
Definition duckdb.cpp:56236
Here is the call graph for this function:

◆ Initialize() [1/4]

void duckdb::TupleDataLayout::Initialize ( vector< LogicalType > types_p,
Aggregates aggregates_p,
TupleDataValidityType validity_type,
TupleDataNestednessType nestedness_type = TupleDataNestednessType::TOP_LEVEL_LAYOUT )

Initializes the TupleDataLayout with the specified types and aggregates to an empty TupleDataLayout.

126562 {
126563 sort_key_type = SortKeyType::INVALID;
126564 offsets.clear();
126565 aggr_destructor_idxs.clear();
126566 types = std::move(types_p);
126567 all_constant = true;
126568 sort_skippable_bytes.clear();
126569 variable_columns.clear();
126570
126571 // Null mask at the front - 1 bit per value.
126572 validity_type = validity_type_p;
126573 flag_width = ValidityBytes::ValidityMaskSize(AllValid() ? 0 : types.size());
126575
126576 // Whether all columns are constant size.
126577 for (idx_t col_idx = 0; col_idx < types.size(); col_idx++) {
126578 const auto &type = types[col_idx];
126579 if (type.InternalType() == PhysicalType::STRUCT) {
126580 // structs are recursively stored as a TupleDataLayout again
126581 const auto &child_types = StructType::GetChildTypes(type);
126582 vector<LogicalType> child_type_vector;
126583 child_type_vector.reserve(child_types.size());
126584 for (auto &ct : child_types) {
126585 child_type_vector.emplace_back(ct.second);
126586 }
126587 if (!struct_layouts) {
126588 struct_layouts = make_uniq<unordered_map<idx_t, TupleDataLayout>>();
126589 }
126590 auto struct_entry = struct_layouts->emplace(col_idx, TupleDataLayout());
126591 struct_entry.first->second.Initialize(std::move(child_type_vector),
126592 TupleDataValidityType::CAN_HAVE_NULL_VALUES,
126593 TupleDataNestednessType::NESTED_STRUCT_LAYOUT);
126594
126595 if (!struct_entry.first->second.AllConstant()) {
126596 all_constant = false;
126597 variable_columns.push_back(col_idx);
126598 }
126599 } else if (!TypeIsConstantSize(type.InternalType())) {
126600 all_constant = false;
126601 variable_columns.push_back(col_idx);
126602 }
126603 }
126604
126605 // This enables pointer recomputation for out-of-core.
126606 if (nestedness_type == TupleDataNestednessType::TOP_LEVEL_LAYOUT && !all_constant) {
126608 row_width += sizeof(idx_t);
126609 }
126610
126611 // Data columns. No alignment required.
126612 for (idx_t col_idx = 0; col_idx < types.size(); col_idx++) {
126613 const auto &type = types[col_idx];
126614 offsets.push_back(row_width);
126615 const auto physical_type = type.InternalType();
126616 if (TypeIsConstantSize(physical_type) || physical_type == PhysicalType::VARCHAR) {
126617 row_width += GetTypeIdSize(physical_type);
126618 } else if (physical_type == PhysicalType::STRUCT) {
126619 // Just get the size of the TupleDataLayout of the struct
126620 row_width += GetStructLayout(col_idx).GetRowWidth();
126621 } else {
126622 // Variable size types use pointers to the actual data (can be swizzled).
126623 // Again, we would use sizeof(data_ptr_t), but this is not guaranteed to be equal to sizeof(idx_t).
126624 row_width += sizeof(idx_t);
126625 }
126626 }
126627
126628 // Alignment padding for aggregates
126629 const auto align = !aggregates_p.empty();
126630#ifndef DUCKDB_ALLOW_UNDEFINED
126631 if (align) {
126633 }
126634#endif
126636
126637 // Aggregate fields.
126638 aggregates = std::move(aggregates_p);
126639 for (auto &aggregate : aggregates) {
126640 offsets.push_back(row_width);
126641 row_width += aggregate.payload_size;
126642#ifndef DUCKDB_ALLOW_UNDEFINED
126643 D_ASSERT(aggregate.payload_size == AlignValue(aggregate.payload_size));
126644#endif
126645 }
126647
126648 // Alignment padding for the next row
126649#ifndef DUCKDB_ALLOW_UNDEFINED
126650 if (align) {
126652 }
126653#endif
126654
126655 for (idx_t aggr_idx = 0; aggr_idx < aggregates.size(); aggr_idx++) {
126656 const auto &aggr = aggregates[aggr_idx];
126657 if (aggr.function.HasStateDestructorCallback()) {
126658 aggr_destructor_idxs.push_back(aggr_idx);
126659 }
126660 }
126661}
vector< idx_t > variable_columns
Indices of the variable columns.
Definition duckdb.cpp:56260
idx_t GetRowWidth() const
Returns the total width required for each row, including padding.
Definition duckdb.cpp:56178
const TupleDataLayout & GetStructLayout(idx_t col_idx) const
Returns a map from column id to the struct TupleDataLayout.
Definition duckdb.cpp:56173
bool AllValid() const
Returns whether none of the columns have NULLs.
Definition duckdb.cpp:56230
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
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:

◆ Initialize() [2/4]

void duckdb::TupleDataLayout::Initialize ( vector< LogicalType > types,
TupleDataValidityType validity_type,
TupleDataNestednessType nestedness_type = TupleDataNestednessType::TOP_LEVEL_LAYOUT )

Initializes the TupleDataLayout with the specified types to an empty TupleDataLayout.

126664 {
126665 Initialize(std::move(types_p), Aggregates(), validity_type, nestedness_type);
126666}
void Initialize(vector< LogicalType > types_p, Aggregates aggregates_p, TupleDataValidityType validity_type, TupleDataNestednessType nestedness_type=TupleDataNestednessType::TOP_LEVEL_LAYOUT)
Initializes the TupleDataLayout with the specified types and aggregates to an empty TupleDataLayout.
Definition duckdb.cpp:126561
Here is the call graph for this function:

◆ Initialize() [3/4]

void duckdb::TupleDataLayout::Initialize ( Aggregates aggregates_p)

Initializes the TupleDataLayout with the specified aggregates to an empty TupleDataLayout.

126668 {
126669 Initialize(vector<LogicalType>(), std::move(aggregates_p), TupleDataValidityType::CANNOT_HAVE_NULL_VALUES,
126670 TupleDataNestednessType::TOP_LEVEL_LAYOUT);
126671}
Here is the call graph for this function:

◆ Initialize() [4/4]

void duckdb::TupleDataLayout::Initialize ( const vector< BoundOrderByNode > & orders,
const LogicalType & type,
bool has_payload )

Initializes a TupleDataLayout with the specified ORDER BY to an empty TupleDataLayout.

126673 {
126674 // Reset state
126675 types.clear();
126676 aggregates.clear();
126677 struct_layouts.reset();
126681 offsets.clear();
126682 sort_skippable_bytes.clear();
126683 all_constant = true;
126685 aggr_destructor_idxs.clear();
126686 validity_type = TupleDataValidityType::CAN_HAVE_NULL_VALUES;
126687
126688 // Type is determined by "create_sort_key", if it is <= 8 we get a bigint
126689 types.push_back(type);
126690
126691 // Compute row width
126692 sort_width = 0;
126693 bool all_valid_and_truely_constant = true;
126694 for (idx_t order_idx = 0; order_idx < orders.size(); order_idx++) {
126695 const auto &order = orders[order_idx];
126696 const auto &logical_type = order.expression->return_type;
126697 const auto physical_type = logical_type.InternalType();
126698
126699 if (all_valid_and_truely_constant && order.stats && !order.stats->CanHaveNull() &&
126700 TypeIsConstantSize(physical_type) && sort_width < 7) {
126701 // We don't have to sort by this byte, all values are valid
126702 sort_skippable_bytes.emplace_back(sort_width);
126703 } else {
126704 all_valid_and_truely_constant = false;
126705 }
126706
126707 if (TypeIsConstantSize(physical_type)) {
126708 // NULL byte + fixed-width type
126709 sort_width += 1 + GetTypeIdSize(physical_type);
126710 } else if (logical_type == LogicalType::VARCHAR && order.stats &&
126711 StringStats::HasMaxStringLength(*order.stats)) {
126712 // NULL byte + maximum string length + string delimiter
126713 sort_width += 1 + StringStats::MaxStringLength(*order.stats) + 1;
126714 } else {
126715 // We don't know how long the key will be
126717 break;
126718 }
126719 }
126720
126721 // Set row width and sort key type accordingly
126722 idx_t temp_row_width = type.id() == LogicalTypeId::BIGINT ? 8 : sort_width;
126723 if (sort_width != DConstants::INVALID_INDEX && has_payload) {
126724 temp_row_width += 8;
126725 }
126726 if (temp_row_width <= 8) {
126727 D_ASSERT(!has_payload);
126728 row_width = 8;
126730 } else if (temp_row_width <= 16) {
126731 row_width = 16;
126732 sort_key_type = has_payload ? SortKeyType::PAYLOAD_FIXED_16 : SortKeyType::NO_PAYLOAD_FIXED_16;
126733 } else if (temp_row_width <= 24) {
126734 row_width = 24;
126735 sort_key_type = has_payload ? SortKeyType::PAYLOAD_FIXED_24 : SortKeyType::NO_PAYLOAD_FIXED_24;
126736 } else if (temp_row_width <= 32) {
126737 row_width = 32;
126738 sort_key_type = has_payload ? SortKeyType::PAYLOAD_FIXED_32 : SortKeyType::NO_PAYLOAD_FIXED_32;
126739 } else {
126740 row_width = 32;
126741 sort_key_type = has_payload ? SortKeyType::PAYLOAD_VARIABLE_32 : SortKeyType::NO_PAYLOAD_VARIABLE_32;
126742
126743 // Variable-size sort key, also set these properties
126744 all_constant = false;
126745 heap_size_offset = has_payload ? SortKey<SortKeyType::PAYLOAD_VARIABLE_32>::HEAP_SIZE_OFFSET
126746 : SortKey<SortKeyType::NO_PAYLOAD_VARIABLE_32>::HEAP_SIZE_OFFSET;
126747 }
126748}
@ NO_PAYLOAD_FIXED_8
Without payload.
Definition duckdb.cpp:55338
@ PAYLOAD_FIXED_16
With payload (requires row pointer in key).
Definition duckdb.cpp:55344
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117
static DUCKDB_API uint32_t MaxStringLength(const BaseStatistics &stats)
Returns the maximum string length, or throws an exception if !HasMaxStringLength().
Definition duckdb.cpp:424560
static DUCKDB_API bool HasMaxStringLength(const BaseStatistics &stats)
Whether or not the statistics have a maximum string length defined.
Definition duckdb.cpp:424553
Here is the call graph for this function:

◆ ColumnCount()

idx_t duckdb::TupleDataLayout::ColumnCount ( ) const
inline

Returns the number of data columns.

56148 {
56149 return types.size();
56150 }
Here is the caller graph for this function:

◆ GetTypes()

const vector< LogicalType > & duckdb::TupleDataLayout::GetTypes ( ) const
inline

Returns a list of the column types for this data chunk.

56152 {
56153 return types;
56154 }
Here is the caller graph for this function:

◆ AggregateCount()

idx_t duckdb::TupleDataLayout::AggregateCount ( ) const
inline

Returns the number of aggregates.

56156 {
56157 return aggregates.size();
56158 }

◆ GetAggregates() [1/2]

Aggregates & duckdb::TupleDataLayout::GetAggregates ( )
inline

Returns a list of the aggregates for this data chunk.

56160 {
56161 return aggregates;
56162 }
Here is the caller graph for this function:

◆ GetAggregates() [2/2]

const Aggregates & duckdb::TupleDataLayout::GetAggregates ( ) const
inline
56163 {
56164 return aggregates;
56165 }

◆ GetSortKeyType()

SortKeyType duckdb::TupleDataLayout::GetSortKeyType ( ) const
inline

Gets the sort key type of this layout (if applicable).

56167 {
56168 return sort_key_type;
56169 }

◆ IsSortKeyLayout()

bool duckdb::TupleDataLayout::IsSortKeyLayout ( ) const

Returns whether this is a sort key layout (in implementation file to avoid including here).

126750 {
126751 return sort_key_type != SortKeyType::INVALID;
126752}
Here is the caller graph for this function:

◆ GetStructLayout()

const TupleDataLayout & duckdb::TupleDataLayout::GetStructLayout ( idx_t col_idx) const
inline

Returns a map from column id to the struct TupleDataLayout.

56173 {
56174 D_ASSERT(struct_layouts->find(col_idx) != struct_layouts->end());
56175 return struct_layouts->find(col_idx)->second;
56176 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRowWidth()

idx_t duckdb::TupleDataLayout::GetRowWidth ( ) const
inline

Returns the total width required for each row, including padding.

56178 {
56179 return row_width;
56180 }
Here is the caller graph for this function:

◆ GetDataOffset()

idx_t duckdb::TupleDataLayout::GetDataOffset ( ) const
inline

Returns the offset to the start of the data.

56182 {
56183 return flag_width;
56184 }

◆ GetDataWidth()

idx_t duckdb::TupleDataLayout::GetDataWidth ( ) const
inline

Returns the total width required for the data, including padding.

56186 {
56187 return data_width;
56188 }

◆ GetAggrOffset()

idx_t duckdb::TupleDataLayout::GetAggrOffset ( ) const
inline

Returns the offset to the start of the aggregates.

56190 {
56191 return flag_width + data_width;
56192 }
Here is the caller graph for this function:

◆ GetAggrWidth()

idx_t duckdb::TupleDataLayout::GetAggrWidth ( ) const
inline

Returns the total width required for the aggregates, including padding.

56194 {
56195 return aggr_width;
56196 }

◆ GetSortWidth()

idx_t duckdb::TupleDataLayout::GetSortWidth ( ) const
inline

Returns the total width required for sorting.

56198 {
56199 D_ASSERT(IsSortKeyLayout());
56200 return sort_width;
56201 }
bool IsSortKeyLayout() const
Returns whether this is a sort key layout (in implementation file to avoid including here).
Definition duckdb.cpp:126750
Here is the call graph for this function:

◆ GetSortSkippableBytes()

const vector< idx_t > & duckdb::TupleDataLayout::GetSortSkippableBytes ( ) const
inline
56202 {
56203 D_ASSERT(IsSortKeyLayout());
56204 return sort_skippable_bytes;
56205 }

◆ GetOffsets()

const vector< idx_t > & duckdb::TupleDataLayout::GetOffsets ( ) const
inline

Returns the column offsets into each row.

56207 {
56208 return offsets;
56209 }
Here is the caller graph for this function:

◆ AllConstant()

bool duckdb::TupleDataLayout::AllConstant ( ) const
inline

Returns whether all columns in this layout are constant size.

56211 {
56212 return all_constant;
56213 }
Here is the caller graph for this function:

◆ GetVariableColumns()

const vector< idx_t > & duckdb::TupleDataLayout::GetVariableColumns ( ) const
inline
56214 {
56215 return variable_columns;
56216 }

◆ GetHeapSizeOffset()

idx_t duckdb::TupleDataLayout::GetHeapSizeOffset ( ) const
inline

Gets offset to where heap size is stored.

56218 {
56219 return heap_size_offset;
56220 }

◆ HasDestructor()

bool duckdb::TupleDataLayout::HasDestructor ( ) const
inline

Returns whether any of the aggregates have a destructor.

56222 {
56223 return !aggr_destructor_idxs.empty();
56224 }

◆ GetAggregateDestructorIndices()

const vector< idx_t > & duckdb::TupleDataLayout::GetAggregateDestructorIndices ( ) const
inline

Returns the indices of the aggregates that have destructors.

56226 {
56227 return aggr_destructor_idxs;
56228 }

◆ AllValid()

bool duckdb::TupleDataLayout::AllValid ( ) const
inline

Returns whether none of the columns have NULLs.

56230 {
56231 return validity_type == TupleDataValidityType::CANNOT_HAVE_NULL_VALUES;
56232 }
Here is the caller graph for this function:

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