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

Vector of values of a specified PhysicalType. More...

#include <duckdb.hpp>

Collaboration diagram for duckdb::Vector:

Public Member Functions

DUCKDB_API Vector (Vector &other)
 Create a vector that references the other vector.
DUCKDB_API Vector (const Vector &other, const SelectionVector &sel, idx_t count)
 Create a vector that slices another vector.
DUCKDB_API Vector (const Vector &other, idx_t offset, idx_t end)
 Create a vector that slices another vector between a pair of offsets.
DUCKDB_API Vector (const Value &value)
 Create a vector of size one holding the passed on value.
DUCKDB_API Vector (LogicalType type, idx_t capacity=STANDARD_VECTOR_SIZE)
 Create a vector of size tuple_count (non-standard).
DUCKDB_API Vector (const VectorCache &cache)
 Create an empty standard vector with a type, equivalent to calling Vector(type, true, false).
DUCKDB_API Vector (LogicalType type, data_ptr_t dataptr)
 Create a non-owning vector that references the specified data.
DUCKDB_API Vector (LogicalType type, bool create_data, bool initialize_to_zero, idx_t capacity=STANDARD_VECTOR_SIZE)
 Create an owning vector that holds at most STANDARD_VECTOR_SIZE entries.
 Vector (const Vector &)=delete
DUCKDB_API Vector (Vector &&other) noexcept
DUCKDB_API void Reference (const Value &value)
 Create a vector that references the specified value.
DUCKDB_API void Reference (const Vector &other)
DUCKDB_API void Reinterpret (const Vector &other)
DUCKDB_API void ReferenceAndSetType (const Vector &other)
 Causes this vector to reference the data held by the other vector, changes the type if required.
DUCKDB_API void ResetFromCache (const VectorCache &cache)
DUCKDB_API void Slice (const Vector &other, idx_t offset, idx_t end)
 Creates a reference to a slice of the other vector.
DUCKDB_API void Slice (const Vector &other, const SelectionVector &sel, idx_t count)
 Creates a reference to a slice of the other vector.
DUCKDB_API void Slice (const SelectionVector &sel, idx_t count)
 Turns the vector into a dictionary vector with the specified dictionary.
DUCKDB_API void Slice (const SelectionVector &sel, idx_t count, SelCache &cache)
 Slice the vector, keeping the result around in a cache or potentially using the cache instead of slicing.
DUCKDB_API void Dictionary (idx_t dictionary_size, const SelectionVector &sel, idx_t count)
 Turn this vector into a dictionary vector.
DUCKDB_API void Dictionary (Vector &dict, idx_t dictionary_size, const SelectionVector &sel, idx_t count)
 Creates a reference to a dictionary of the other vector.
DUCKDB_API void Dictionary (buffer_ptr< VectorChildBuffer > reusable_dict, const SelectionVector &sel)
 Creates a dictionary on the reusable dict.
DUCKDB_API void Initialize (bool initialize_to_zero=false, idx_t capacity=STANDARD_VECTOR_SIZE)
DUCKDB_API string ToString (idx_t count) const
 Converts this Vector to a printable string representation.
DUCKDB_API void Print (idx_t count) const
DUCKDB_API string ToString () const
DUCKDB_API void Print () const
DUCKDB_API void Flatten (idx_t count)
 Flatten the vector, removing any compression and turning it into a FLAT_VECTOR.
DUCKDB_API void Flatten (const SelectionVector &sel, idx_t count)
DUCKDB_API void ToUnifiedFormat (idx_t count, UnifiedVectorFormat &data)
DUCKDB_API void Sequence (int64_t start, int64_t increment, idx_t count)
 Turn the vector into a sequence vector.
DUCKDB_API void Verify (idx_t count)
DUCKDB_API void UTFVerify (idx_t count)
DUCKDB_API void UTFVerify (const SelectionVector &sel, idx_t count)
DUCKDB_API Value GetValue (idx_t index) const
 Returns the [index] element of the Vector as a Value.
DUCKDB_API void SetValue (idx_t index, const Value &val)
 Sets the [index] element of the Vector to the specified Value.
void SetAuxiliary (buffer_ptr< VectorBuffer > new_buffer)
void CopyBuffer (Vector &other)
DUCKDB_API void Resize (idx_t cur_size, idx_t new_size)
 Resizes the vector.
DUCKDB_API void FindResizeInfos (vector< ResizeInfo > &resize_infos, const idx_t multiplier)
 Returns a vector of ResizeInfo containing each (nested) vector to resize.
DUCKDB_API void Serialize (Serializer &serializer, idx_t count, bool compressed_serialization=true)
DUCKDB_API void Deserialize (Deserializer &deserializer, idx_t count)
idx_t GetAllocationSize (idx_t cardinality) const
VectorType GetVectorType () const
const LogicalType & GetType () const
data_ptr_t GetData () const
buffer_ptr< VectorBuffer > GetAuxiliary ()
buffer_ptr< VectorBuffer > GetBuffer ()
DUCKDB_API void SetVectorType (VectorType vector_type)

Static Public Member Functions

static void RecursiveToUnifiedFormat (Vector &input, idx_t count, RecursiveUnifiedVectorFormat &data)
 Recursively calls UnifiedVectorFormat on a vector and its child vectors (for nested types).
static DUCKDB_API void VerifyMap (Vector &map, const SelectionVector &sel, idx_t count)
 Asserts that the CheckMapValidity returns MapInvalidReason::VALID.
static DUCKDB_API void VerifyUnion (Vector &map, const SelectionVector &sel, idx_t count)
static DUCKDB_API void VerifyVariant (Vector &map, const SelectionVector &sel, idx_t count)
static DUCKDB_API void Verify (Vector &vector, const SelectionVector &sel, idx_t count)
static void DebugTransformToDictionary (Vector &vector, idx_t count)
static void DebugShuffleNestedVector (Vector &vector, idx_t count)

Protected Attributes

VectorType vector_type
LogicalType type
 The type of the elements stored in the vector (e.g. integer, float).
data_ptr_t data
 A pointer to the data.
ValidityMask validity
 The validity mask of the vector.
buffer_ptr< VectorBuffer > buffer
 The main buffer holding the data of the vector.
buffer_ptr< VectorBuffer > auxiliary

Static Private Member Functions

static Value GetValue (const Vector &v, idx_t index)
 Returns the [index] element of the Vector as a Value.
static Value GetValueInternal (const Vector &v, idx_t index)
 Returns the [index] element of the Vector as a Value.

Friends

struct ConstantVector
struct DictionaryVector
struct FlatVector
struct ListVector
struct StringVector
struct FSSTVector
struct StructVector
struct UnionVector
struct SequenceVector
struct ArrayVector
class DataChunk
class VectorCacheBuffer

Detailed Description

Vector of values of a specified PhysicalType.

Constructor & Destructor Documentation

◆ Vector() [1/9]

duckdb::Vector::Vector ( Vector & other)

Create a vector that references the other vector.

135763 : type(other.type) {
135764 Reference(other);
135765}
LogicalType type
The type of the elements stored in the vector (e.g. integer, float).
Definition duckdb.hpp:10765
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:

◆ Vector() [2/9]

duckdb::Vector::Vector ( const Vector & other,
const SelectionVector & sel,
idx_t count )
explicit

Create a vector that slices another vector.

135767 : type(other.type) {
135768 Slice(other, sel, count);
135769}
DUCKDB_API void Slice(const Vector &other, idx_t offset, idx_t end)
Creates a reference to a slice of the other vector.
Definition duckdb.cpp:135864
Here is the call graph for this function:

◆ Vector() [3/9]

duckdb::Vector::Vector ( const Vector & other,
idx_t offset,
idx_t end )
explicit

Create a vector that slices another vector between a pair of offsets.

135771 : type(other.type) {
135772 Slice(other, offset, end);
135773}
Here is the call graph for this function:

◆ Vector() [4/9]

duckdb::Vector::Vector ( const Value & value)
explicit

Create a vector of size one holding the passed on value.

135775 : type(value.type()) {
135776 Reference(value);
135777}
Here is the call graph for this function:

◆ Vector() [5/9]

duckdb::Vector::Vector ( LogicalType type,
idx_t capacity = STANDARD_VECTOR_SIZE )
explicit

Create a vector of size tuple_count (non-standard).

135749 : Vector(std::move(type_p), true, false, capacity) {
135750}
DUCKDB_API Vector(Vector &other)
Create a vector that references the other vector.
Definition duckdb.cpp:135763
Here is the call graph for this function:

◆ Vector() [6/9]

duckdb::Vector::Vector ( const VectorCache & cache)
explicit

Create an empty standard vector with a type, equivalent to calling Vector(type, true, false).

135759 : type(cache.GetType()) {
135760 ResetFromCache(cache);
135761}
DUCKDB_API void ResetFromCache(const VectorCache &cache)
Definition duckdb.cpp:135860
Here is the call graph for this function:

◆ Vector() [7/9]

duckdb::Vector::Vector ( LogicalType type,
data_ptr_t dataptr )

Create a non-owning vector that references the specified data.

135753 : vector_type(VectorType::FLAT_VECTOR), type(std::move(type_p)), data(dataptr) {
135754 if (dataptr && !type.IsValid()) {
135755 throw InternalException("Cannot create a vector of type INVALID!");
135756 }
135757}
data_ptr_t data
A pointer to the data.
Definition duckdb.hpp:10767
VectorType vector_type
Definition duckdb.hpp:10763

◆ Vector() [8/9]

duckdb::Vector::Vector ( LogicalType type,
bool create_data,
bool initialize_to_zero,
idx_t capacity = STANDARD_VECTOR_SIZE )

Create an owning vector that holds at most STANDARD_VECTOR_SIZE entries.

Create a new vector If create_data is true, the vector will be an owning empty vector. If initialize_to_zero is true, the allocated data will be zero-initialized.

135743 : vector_type(VectorType::FLAT_VECTOR), type(std::move(type_p)), data(nullptr), validity(capacity) {
135744 if (create_data) {
135745 Initialize(initialize_to_zero, capacity);
135746 }
135747}
ValidityMask validity
The validity mask of the vector.
Definition duckdb.hpp:10769
DUCKDB_API void Initialize(bool initialize_to_zero=false, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:136018
Here is the call graph for this function:

◆ Vector() [9/9]

duckdb::Vector::Vector ( Vector && other)
noexcept
135780 : vector_type(other.vector_type), type(std::move(other.type)), data(other.data),
135781 validity(std::move(other.validity)), buffer(std::move(other.buffer)), auxiliary(std::move(other.auxiliary)) {
135782}
buffer_ptr< VectorBuffer > buffer
The main buffer holding the data of the vector.
Definition duckdb.hpp:10771
buffer_ptr< VectorBuffer > auxiliary
Definition duckdb.hpp:10774

Member Function Documentation

◆ Reference() [1/2]

void duckdb::Vector::Reference ( const Value & value)

Create a vector that references the specified value.

135784 {
135785 D_ASSERT(GetType().id() == value.type().id());
135786 this->vector_type = VectorType::CONSTANT_VECTOR;
135787 buffer = VectorBuffer::CreateConstantVector(value.type());
135788 auto internal_type = value.type().InternalType();
135789 if (internal_type == PhysicalType::STRUCT) {
135790 auto struct_buffer = make_uniq<VectorStructBuffer>();
135791 auto &child_types = StructType::GetChildTypes(value.type());
135792 auto &child_vectors = struct_buffer->GetChildren();
135793 for (idx_t i = 0; i < child_types.size(); i++) {
135794 auto vector =
135795 make_uniq<Vector>(value.IsNull() ? Value(child_types[i].second) : StructValue::GetChildren(value)[i]);
135796 child_vectors.push_back(std::move(vector));
135797 }
135798 auxiliary = shared_ptr<VectorBuffer>(struct_buffer.release());
135799 if (value.IsNull()) {
135800 SetValue(0, value);
135801 }
135802 } else if (internal_type == PhysicalType::LIST) {
135803 auto list_buffer = make_uniq<VectorListBuffer>(value.type());
135804 auxiliary = shared_ptr<VectorBuffer>(list_buffer.release());
135805 data = buffer->GetData();
135806 SetValue(0, value);
135807 } else if (internal_type == PhysicalType::ARRAY) {
135808 auto array_buffer = make_uniq<VectorArrayBuffer>(value.type());
135809 auxiliary = shared_ptr<VectorBuffer>(array_buffer.release());
135810 SetValue(0, value);
135811 } else {
135812 auxiliary.reset();
135813 data = buffer->GetData();
135814 SetValue(0, value);
135815 }
135816}
DUCKDB_API void SetValue(idx_t index, const Value &val)
Sets the [index] element of the Vector to the specified Value.
Definition duckdb.cpp:136134
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ 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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reference() [2/2]

void duckdb::Vector::Reference ( const Vector & other)

Causes this vector to reference the data held by the other vector. The type of the "other" vector should match the type of this vector

135818 {
135819 if (other.GetType().id() != GetType().id()) {
135820 throw InternalException("Vector::Reference used on vector of different type (source %s referenced %s)",
135821 GetType(), other.GetType());
135822 }
135823 D_ASSERT(other.GetType() == GetType());
135824 Reinterpret(other);
135825}
DUCKDB_API void Reinterpret(const Vector &other)
Definition duckdb.cpp:135832
Here is the call graph for this function:

◆ Reinterpret()

void duckdb::Vector::Reinterpret ( const Vector & other)

Reinterpret the data of the other vector as the type of this vector Note that this takes the data of the other vector as-is and places it in this vector Without changing the type of this vector

135832 {
135833 vector_type = other.vector_type;
135834 auto &this_type = GetType();
135835 auto &other_type = other.GetType();
135836#ifdef DEBUG
135837 auto type_is_same = other_type == this_type;
135838 bool this_is_nested = this_type.IsNested();
135839 bool other_is_nested = other_type.IsNested();
135840
135841 bool not_nested = this_is_nested == false && other_is_nested == false;
135842 bool type_size_equal = GetTypeIdSize(this_type.InternalType()) == GetTypeIdSize(other_type.InternalType());
135846 D_ASSERT((not_nested && type_size_equal) || type_is_same);
135847#endif
135848 AssignSharedPointer(buffer, other.buffer);
135849 if (vector_type == VectorType::DICTIONARY_VECTOR && other_type != this_type) {
135850 Vector new_vector(GetType(), nullptr);
135851 new_vector.Reinterpret(DictionaryVector::Child(other));
135852 auxiliary = make_shared_ptr<VectorChildBuffer>(std::move(new_vector));
135853 } else {
135854 AssignSharedPointer(auxiliary, other.auxiliary);
135855 }
135856 data = other.data;
135857 validity = other.validity;
135858}
void AssignSharedPointer(shared_ptr< T > &target, const shared_ptr< T > &source)
Definition duckdb.hpp:2180
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReferenceAndSetType()

void duckdb::Vector::ReferenceAndSetType ( const Vector & other)

Causes this vector to reference the data held by the other vector, changes the type if required.

135827 {
135828 type = other.GetType();
135829 Reference(other);
135830}
Here is the call graph for this function:

◆ ResetFromCache()

void duckdb::Vector::ResetFromCache ( const VectorCache & cache)

Resets a vector from a vector cache. This turns the vector back into an empty FlatVector with STANDARD_VECTOR_SIZE entries. The VectorCache is used so this can be done without requiring any allocations.

135860 {
135861 cache.ResetFromCache(*this);
135862}
Here is the caller graph for this function:

◆ Slice() [1/4]

void duckdb::Vector::Slice ( const Vector & other,
idx_t offset,
idx_t end )

Creates a reference to a slice of the other vector.

135864 {
135865 D_ASSERT(end >= offset);
135866 if (other.GetVectorType() == VectorType::CONSTANT_VECTOR) {
135867 Reference(other);
135868 return;
135869 }
135870 if (other.GetVectorType() != VectorType::FLAT_VECTOR) {
135871 // we can slice the data directly only for flat vectors
135872 // for non-flat vectors slice using a selection vector instead
135873 idx_t count = end - offset;
135874 SelectionVector sel(count);
135875 for (idx_t i = 0; i < count; i++) {
135876 sel.set_index(i, offset + i);
135877 }
135878 Slice(other, sel, count);
135879 return;
135880 }
135881
135882 auto internal_type = GetType().InternalType();
135883 if (internal_type == PhysicalType::STRUCT) {
135884 Vector new_vector(GetType());
135885 auto &entries = StructVector::GetEntries(new_vector);
135886 auto &other_entries = StructVector::GetEntries(other);
135887 D_ASSERT(entries.size() == other_entries.size());
135888 for (idx_t i = 0; i < entries.size(); i++) {
135889 entries[i]->Slice(*other_entries[i], offset, end);
135890 }
135891 new_vector.validity.Slice(other.validity, offset, end - offset);
135892 Reference(new_vector);
135893 } else if (internal_type == PhysicalType::ARRAY) {
135894 Vector new_vector(GetType());
135895 auto &child_vec = ArrayVector::GetEntry(new_vector);
135896 auto &other_child_vec = ArrayVector::GetEntry(other);
135897 D_ASSERT(ArrayType::GetSize(GetType()) == ArrayType::GetSize(other.GetType()));
135898 const auto array_size = ArrayType::GetSize(GetType());
135899 // We need to slice the child vector with the multiplied offset and end
135900 child_vec.Slice(other_child_vec, offset * array_size, end * array_size);
135901 new_vector.validity.Slice(other.validity, offset, end - offset);
135902 Reference(new_vector);
135903 } else {
135904 Reference(other);
135905 if (offset > 0) {
135906 data = data + GetTypeIdSize(internal_type) * offset;
135907 validity.Slice(other.validity, offset, end - offset);
135908 }
135909 }
135910}
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of an array.
Definition duckdb.cpp:138574
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Slice() [2/4]

void duckdb::Vector::Slice ( const Vector & other,
const SelectionVector & sel,
idx_t count )

Creates a reference to a slice of the other vector.

135912 {
135913 Reference(other);
135914 Slice(sel, count);
135915}
Here is the call graph for this function:

◆ Slice() [3/4]

void duckdb::Vector::Slice ( const SelectionVector & sel,
idx_t count )

Turns the vector into a dictionary vector with the specified dictionary.

135917 {
135918 if (!sel.IsSet() || count == 0) {
135919 return; // Nothing to do here
135920 }
135921 if (GetVectorType() == VectorType::CONSTANT_VECTOR) {
135922 // dictionary on a constant is just a constant
135923 return;
135924 }
135925 if (GetVectorType() == VectorType::DICTIONARY_VECTOR) {
135926 // already a dictionary, slice the current dictionary
135927 auto &current_sel = DictionaryVector::SelVector(*this);
135928 auto dictionary_size = DictionaryVector::DictionarySize(*this);
135929 auto dictionary_id = DictionaryVector::DictionaryId(*this);
135930 auto sliced_dictionary = current_sel.Slice(sel, count);
135931 buffer = make_buffer<DictionaryBuffer>(std::move(sliced_dictionary));
135932 if (GetType().InternalType() == PhysicalType::STRUCT) {
135933 auto &child_vector = DictionaryVector::Child(*this);
135934
135935 Vector new_child(child_vector);
135936 new_child.auxiliary = make_buffer<VectorStructBuffer>(new_child, sel, count);
135937 auxiliary = make_buffer<VectorChildBuffer>(std::move(new_child));
135938 }
135939 if (dictionary_size.IsValid()) {
135940 auto &dict_buffer = buffer->Cast<DictionaryBuffer>();
135941 dict_buffer.SetDictionarySize(dictionary_size.GetIndex());
135942 dict_buffer.SetDictionaryId(std::move(dictionary_id));
135943 }
135944 return;
135945 }
135946
135947 if (GetVectorType() == VectorType::FSST_VECTOR) {
135948 Flatten(sel, count);
135949 return;
135950 }
135951
135952 Vector child_vector(*this);
135953 auto internal_type = GetType().InternalType();
135954 if (internal_type == PhysicalType::STRUCT) {
135955 child_vector.auxiliary = make_buffer<VectorStructBuffer>(*this, sel, count);
135956 }
135957 auto child_ref = make_buffer<VectorChildBuffer>(std::move(child_vector));
135958 auto dict_buffer = make_buffer<DictionaryBuffer>(sel);
135959 vector_type = VectorType::DICTIONARY_VECTOR;
135960 buffer = std::move(dict_buffer);
135961 auxiliary = std::move(child_ref);
135962}
DUCKDB_API void Flatten(idx_t count)
Flatten the vector, removing any compression and turning it into a FLAT_VECTOR.
Definition duckdb.cpp:136652
Here is the call graph for this function:

◆ Slice() [4/4]

void duckdb::Vector::Slice ( const SelectionVector & sel,
idx_t count,
SelCache & cache )

Slice the vector, keeping the result around in a cache or potentially using the cache instead of slicing.

135991 {
135992 if (GetVectorType() == VectorType::DICTIONARY_VECTOR && GetType().InternalType() != PhysicalType::STRUCT) {
135993 // dictionary vector: need to merge dictionaries
135994 // check if we have a cached entry
135995 auto &current_sel = DictionaryVector::SelVector(*this);
135996 auto dictionary_size = DictionaryVector::DictionarySize(*this);
135997 auto dictionary_id = DictionaryVector::DictionaryId(*this);
135998 auto target_data = current_sel.data();
135999 auto entry = cache.cache.find(target_data);
136000 if (entry != cache.cache.end()) {
136001 // cached entry exists: use that
136002 this->buffer = make_buffer<DictionaryBuffer>(entry->second->Cast<DictionaryBuffer>().GetSelVector());
136003 vector_type = VectorType::DICTIONARY_VECTOR;
136004 } else {
136005 Slice(sel, count);
136006 cache.cache[target_data] = this->buffer;
136007 }
136008 if (dictionary_size.IsValid()) {
136009 auto &dict_buffer = buffer->Cast<DictionaryBuffer>();
136010 dict_buffer.SetDictionarySize(dictionary_size.GetIndex());
136011 dict_buffer.SetDictionaryId(std::move(dictionary_id));
136012 }
136013 } else {
136014 Slice(sel, count);
136015 }
136016}
Here is the call graph for this function:

◆ Dictionary() [1/3]

void duckdb::Vector::Dictionary ( idx_t dictionary_size,
const SelectionVector & sel,
idx_t count )

Turn this vector into a dictionary vector.

135964 {
135965 Slice(sel, count);
135966 if (GetVectorType() == VectorType::DICTIONARY_VECTOR) {
135967 buffer->Cast<DictionaryBuffer>().SetDictionarySize(dictionary_size);
135968 }
135969}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dictionary() [2/3]

void duckdb::Vector::Dictionary ( Vector & dict,
idx_t dictionary_size,
const SelectionVector & sel,
idx_t count )

Creates a reference to a dictionary of the other vector.

135971 {
135972 Reference(dict);
135973 Dictionary(dictionary_size, sel, count);
135974}
DUCKDB_API void Dictionary(idx_t dictionary_size, const SelectionVector &sel, idx_t count)
Turn this vector into a dictionary vector.
Definition duckdb.cpp:135964
Here is the call graph for this function:

◆ Dictionary() [3/3]

void duckdb::Vector::Dictionary ( buffer_ptr< VectorChildBuffer > reusable_dict,
const SelectionVector & sel )

Creates a dictionary on the reusable dict.

135976 {
135977 D_ASSERT(type.InternalType() != PhysicalType::STRUCT);
135978 D_ASSERT(type == reusable_dict->data.GetType());
135979 vector_type = VectorType::DICTIONARY_VECTOR;
135980 data = reusable_dict->data.data;
135981 validity.Reset();
135982
135983 auto dict_buffer = make_buffer<DictionaryBuffer>(sel);
135984 dict_buffer->SetDictionarySize(reusable_dict->size.GetIndex());
135985 dict_buffer->SetDictionaryId(reusable_dict->id);
135986 buffer = std::move(dict_buffer);
135987
135988 auxiliary = std::move(reusable_dict);
135989}

◆ Initialize()

void duckdb::Vector::Initialize ( bool initialize_to_zero = false,
idx_t capacity = STANDARD_VECTOR_SIZE )

Creates the data of this vector with the specified type. Any data that is currently in the vector is destroyed.

136018 {
136019 auxiliary.reset();
136020 validity.Reset();
136021 auto &type = GetType();
136022 auto internal_type = type.InternalType();
136023 if (internal_type == PhysicalType::STRUCT) {
136024 auto struct_buffer = make_uniq<VectorStructBuffer>(type, capacity);
136025 auxiliary = shared_ptr<VectorBuffer>(struct_buffer.release());
136026 } else if (internal_type == PhysicalType::LIST) {
136027 auto list_buffer = make_uniq<VectorListBuffer>(type, capacity);
136028 auxiliary = shared_ptr<VectorBuffer>(list_buffer.release());
136029 } else if (internal_type == PhysicalType::ARRAY) {
136030 auto array_buffer = make_uniq<VectorArrayBuffer>(type, capacity);
136031 auxiliary = shared_ptr<VectorBuffer>(array_buffer.release());
136032 }
136033 auto type_size = GetTypeIdSize(internal_type);
136034 if (type_size > 0) {
136035 buffer = VectorBuffer::CreateStandardVector(type, capacity);
136036 data = buffer->GetData();
136037 if (initialize_to_zero) {
136038 memset(data, 0, capacity * type_size);
136039 }
136040 }
136041
136042 if (capacity > validity.Capacity()) {
136043 validity.Resize(capacity);
136044 }
136045}
Here is the caller graph for this function:

◆ ToString() [1/2]

string duckdb::Vector::ToString ( idx_t count) const

Converts this Vector to a printable string representation.

136537 {
136538 string retval =
136539 VectorTypeToString(GetVectorType()) + " " + GetType().ToString() + ": " + to_string(count) + " = [ ";
136540 switch (GetVectorType()) {
136541 case VectorType::FLAT_VECTOR:
136542 case VectorType::DICTIONARY_VECTOR:
136543 for (idx_t i = 0; i < count; i++) {
136544 retval += GetValue(i).ToString() + (i == count - 1 ? "" : ", ");
136545 }
136546 break;
136547 case VectorType::FSST_VECTOR: {
136548 for (idx_t i = 0; i < count; i++) {
136549 string_t compressed_string = reinterpret_cast<string_t *>(data)[i];
136550 auto decoder = FSSTVector::GetDecoder(*this);
136551 auto &decompress_buffer = FSSTVector::GetDecompressBuffer(*this);
136552 Value val = FSSTPrimitives::DecompressValue(decoder, compressed_string.GetData(),
136553 compressed_string.GetSize(), decompress_buffer);
136554 retval += GetValue(i).ToString() + (i == count - 1 ? "" : ", ");
136555 }
136556 } break;
136557 case VectorType::CONSTANT_VECTOR:
136558 retval += GetValue(0).ToString();
136559 break;
136560 case VectorType::SEQUENCE_VECTOR: {
136561 int64_t start, increment;
136562 SequenceVector::GetSequence(*this, start, increment);
136563 for (idx_t i = 0; i < count; i++) {
136564 retval += to_string(start + static_cast<int64_t>(static_cast<uint64_t>(increment) * i)) +
136565 (i == count - 1 ? "" : ", ");
136566 }
136567 break;
136568 }
136569 default:
136570 retval += "UNKNOWN VECTOR TYPE";
136571 break;
136572 }
136573 retval += "]";
136574 return retval;
136575}
DUCKDB_API string ToString() const
Convert this value to a string.
Definition duckdb.cpp:133318
DUCKDB_API Value GetValue(idx_t index) const
Returns the [index] element of the Vector as a Value.
Definition duckdb.cpp:136515
std::string to_string(const T &value)
Definition duckdb.cpp:19425
::int64_t int64_t
::uint64_t uint64_t
Here is the call graph for this function:

◆ Print() [1/2]

void duckdb::Vector::Print ( idx_t count) const
136577 {
136578 Printer::Print(ToString(count));
136579}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.
Definition duckdb.cpp:92556
DUCKDB_API string ToString(idx_t count) const
Converts this Vector to a printable string representation.
Definition duckdb.cpp:136537

◆ ToString() [2/2]

string duckdb::Vector::ToString ( ) const
136618 {
136619 string retval = VectorTypeToString(GetVectorType()) + " " + GetType().ToString() + ": (UNKNOWN COUNT) [ ";
136620 switch (GetVectorType()) {
136621 case VectorType::FLAT_VECTOR:
136622 case VectorType::DICTIONARY_VECTOR:
136623 break;
136624 case VectorType::CONSTANT_VECTOR:
136625 retval += GetValue(0).ToString();
136626 break;
136627 case VectorType::SEQUENCE_VECTOR: {
136628 break;
136629 }
136630 default:
136631 retval += "UNKNOWN VECTOR TYPE";
136632 break;
136633 }
136634 retval += "]";
136635 return retval;
136636}

◆ Print() [2/2]

void duckdb::Vector::Print ( ) const
136638 {
136640}

◆ Flatten() [1/2]

void duckdb::Vector::Flatten ( idx_t count)

Flatten the vector, removing any compression and turning it into a FLAT_VECTOR.

136652 {
136653 switch (GetVectorType()) {
136654 case VectorType::FLAT_VECTOR:
136655 // already a flat vector
136656 switch (GetType().InternalType()) {
136657 case PhysicalType::STRUCT: {
136658 auto &entries = StructVector::GetEntries(*this);
136659 for (auto &entry : entries) {
136660 entry->Flatten(count);
136661 }
136662 break;
136663 }
136664 case PhysicalType::LIST: {
136665 auto &entry = ListVector::GetEntry(*this);
136666 entry.Flatten(ListVector::GetListSize(*this));
136667 break;
136668 }
136669 case PhysicalType::ARRAY: {
136670 auto &entry = ArrayVector::GetEntry(*this);
136671 entry.Flatten(ArrayVector::GetTotalSize(*this));
136672 break;
136673 }
136674 default:
136675 break;
136676 }
136677 break;
136678 case VectorType::FSST_VECTOR: {
136679 // Even though count may only be a part of the vector, we need to flatten the whole thing due to the way
136680 // ToUnifiedFormat uses flatten
136681 idx_t total_count = FSSTVector::GetCount(*this);
136682 // create vector to decompress into
136683 Vector other(GetType(), total_count);
136684 // now copy the data of this vector to the other vector, decompressing the strings in the process
136685 VectorOperations::Copy(*this, other, total_count, 0, 0);
136686 // create a reference to the data in the other vector
136687 this->Reference(other);
136688 break;
136689 }
136690 case VectorType::DICTIONARY_VECTOR: {
136691 // create a new flat vector of this type
136692 Vector other(GetType(), count);
136693 // now copy the data of this vector to the other vector, removing the selection vector in the process
136694 VectorOperations::Copy(*this, other, count, 0, 0);
136695 // create a reference to the data in the other vector
136696 this->Reference(other);
136697 break;
136698 }
136699 case VectorType::CONSTANT_VECTOR: {
136700 bool is_null = ConstantVector::IsNull(*this);
136701 // allocate a new buffer for the vector
136702 auto old_buffer = std::move(buffer);
136703 auto old_data = data;
136704 buffer = VectorBuffer::CreateStandardVector(type, MaxValue<idx_t>(STANDARD_VECTOR_SIZE, count));
136705 if (old_buffer) {
136706 D_ASSERT(buffer->GetAuxiliaryData() == nullptr);
136707 // The old buffer might be relying on the auxiliary data, keep it alive
136708 buffer->MoveAuxiliaryData(*old_buffer);
136709 }
136710 data = buffer->GetData();
136711 vector_type = VectorType::FLAT_VECTOR;
136712 if (is_null && GetType().InternalType() != PhysicalType::ARRAY) {
136713 // constant NULL, set nullmask
136714 validity.EnsureWritable();
136715 validity.SetAllInvalid(count);
136716 if (GetType().InternalType() != PhysicalType::STRUCT) {
136717 // for structs we still need to flatten the child vectors as well
136718 return;
136719 }
136720 }
136721 // non-null constant: have to repeat the constant
136722 switch (GetType().InternalType()) {
136723 case PhysicalType::BOOL:
136724 TemplatedFlattenConstantVector<bool>(data, old_data, count);
136725 break;
136726 case PhysicalType::INT8:
136727 TemplatedFlattenConstantVector<int8_t>(data, old_data, count);
136728 break;
136729 case PhysicalType::INT16:
136730 TemplatedFlattenConstantVector<int16_t>(data, old_data, count);
136731 break;
136732 case PhysicalType::INT32:
136733 TemplatedFlattenConstantVector<int32_t>(data, old_data, count);
136734 break;
136735 case PhysicalType::INT64:
136736 TemplatedFlattenConstantVector<int64_t>(data, old_data, count);
136737 break;
136738 case PhysicalType::UINT8:
136739 TemplatedFlattenConstantVector<uint8_t>(data, old_data, count);
136740 break;
136742 TemplatedFlattenConstantVector<uint16_t>(data, old_data, count);
136743 break;
136745 TemplatedFlattenConstantVector<uint32_t>(data, old_data, count);
136746 break;
136748 TemplatedFlattenConstantVector<uint64_t>(data, old_data, count);
136749 break;
136750 case PhysicalType::INT128:
136751 TemplatedFlattenConstantVector<hugeint_t>(data, old_data, count);
136752 break;
136753 case PhysicalType::UINT128:
136754 TemplatedFlattenConstantVector<uhugeint_t>(data, old_data, count);
136755 break;
136756 case PhysicalType::FLOAT:
136757 TemplatedFlattenConstantVector<float>(data, old_data, count);
136758 break;
136760 TemplatedFlattenConstantVector<double>(data, old_data, count);
136761 break;
136763 TemplatedFlattenConstantVector<interval_t>(data, old_data, count);
136764 break;
136766 TemplatedFlattenConstantVector<string_t>(data, old_data, count);
136767 break;
136768 case PhysicalType::LIST: {
136769 TemplatedFlattenConstantVector<list_entry_t>(data, old_data, count);
136770 break;
136771 }
136772 case PhysicalType::ARRAY: {
136773 auto &original_child = ArrayVector::GetEntry(*this);
136774 auto array_size = ArrayType::GetSize(GetType());
136775 auto flattened_buffer = make_uniq<VectorArrayBuffer>(GetType(), count);
136776 auto &new_child = flattened_buffer->GetChild();
136777
136778 // Fast path: The array is a constant null
136779 if (is_null) {
136780 // Invalidate the parent array
136781 validity.SetAllInvalid(count);
136782 // Also invalidate the new child array
136783 new_child.validity.SetAllInvalid(count * array_size);
136784 // Recurse
136785 new_child.Flatten(count * array_size);
136786 // TODO: the fast path should exit here, but the part below it is somehow required for correctness
136787 // Attach the flattened buffer and return
136788 // auxiliary = shared_ptr<VectorBuffer>(flattened_buffer.release());
136789 // return;
136790 }
136791
136792 // Now we need to "unpack" the child vector.
136793 // Basically, do this:
136794 //
136795 // | a1 | | 1 | | a1 | | 1 |
136796 // | 2 | | a2 | | 2 |
136797 // => .. | 1 |
136798 // | 2 |
136799 // ...
136800
136801 auto child_vec = make_uniq<Vector>(original_child);
136802 child_vec->Flatten(count * array_size);
136803
136804 // Create a selection vector
136805 SelectionVector sel(count * array_size);
136806 for (idx_t array_idx = 0; array_idx < count; array_idx++) {
136807 for (idx_t elem_idx = 0; elem_idx < array_size; elem_idx++) {
136808 auto position = array_idx * array_size + elem_idx;
136809 // Broadcast the validity
136810 if (FlatVector::IsNull(*child_vec, elem_idx)) {
136811 FlatVector::SetNull(new_child, position, true);
136812 }
136813 sel.set_index(position, elem_idx);
136814 }
136815 }
136816
136817 // Copy over the data to the new buffer
136818 VectorOperations::Copy(*child_vec, new_child, sel, count * array_size, 0, 0);
136819 auxiliary = shared_ptr<VectorBuffer>(flattened_buffer.release());
136820
136821 break;
136822 }
136823 case PhysicalType::STRUCT: {
136824 auto normalified_buffer = make_uniq<VectorStructBuffer>();
136825
136826 auto &new_children = normalified_buffer->GetChildren();
136827
136828 auto &child_entries = StructVector::GetEntries(*this);
136829 for (auto &child : child_entries) {
136830 D_ASSERT(child->GetVectorType() == VectorType::CONSTANT_VECTOR);
136831 auto vector = make_uniq<Vector>(*child);
136832 vector->Flatten(count);
136833 new_children.push_back(std::move(vector));
136834 }
136835 auxiliary = shared_ptr<VectorBuffer>(normalified_buffer.release());
136836 break;
136837 }
136838 default:
136839 throw InternalException("Unimplemented type for VectorOperations::Flatten");
136840 }
136841 break;
136842 }
136843 case VectorType::SEQUENCE_VECTOR: {
136844 int64_t start, increment, sequence_count;
136845 SequenceVector::GetSequence(*this, start, increment, sequence_count);
136846 auto seq_count = NumericCast<idx_t>(sequence_count);
136847
136848 buffer = VectorBuffer::CreateStandardVector(GetType(), MaxValue<idx_t>(STANDARD_VECTOR_SIZE, seq_count));
136849 data = buffer->GetData();
136850 VectorOperations::GenerateSequence(*this, seq_count, start, increment);
136851 break;
136852 }
136853 default:
136854 throw InternalException("Unimplemented type for normalify");
136855 }
136856}
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ INTERVAL
YEAR_MONTH or DAY_TIME interval in SQL style.
Definition duckdb.hpp:2806
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ UINT64
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ INT8
Signed 8-bit little-endian integer.
Definition duckdb.hpp:2749
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776
static DUCKDB_API idx_t GetTotalSize(const Vector &vector)
Gets the total size of the underlying child-vector of an array.
Definition duckdb.cpp:138582
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 idx_t GetListSize(const Vector &vector)
Gets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138221
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Flatten() [2/2]

void duckdb::Vector::Flatten ( const SelectionVector & sel,
idx_t count )
136858 {
136859 switch (GetVectorType()) {
136860 case VectorType::FLAT_VECTOR:
136861 // already a flat vector
136862 break;
136863 case VectorType::FSST_VECTOR: {
136864 // create a new flat vector of this type
136865 Vector other(GetType(), count);
136866 // copy the data of this vector to the other vector, removing compression and selection vector in the process
136867 VectorOperations::Copy(*this, other, sel, count, 0, 0);
136868 // create a reference to the data in the other vector
136869 this->Reference(other);
136870 break;
136871 }
136872 case VectorType::SEQUENCE_VECTOR: {
136873 int64_t start, increment;
136874 SequenceVector::GetSequence(*this, start, increment);
136875
136876 buffer = VectorBuffer::CreateStandardVector(GetType());
136877 data = buffer->GetData();
136878 VectorOperations::GenerateSequence(*this, count, sel, start, increment);
136879 break;
136880 }
136881 default:
136882 throw InternalException("Unimplemented type for normalify with selection vector");
136883 }
136884}

◆ ToUnifiedFormat()

void duckdb::Vector::ToUnifiedFormat ( idx_t count,
UnifiedVectorFormat & data )

Creates a UnifiedVectorFormat of a vector The UnifiedVectorFormat allows efficient reading of vectors regardless of their vector type It contains (1) a data pointer, (2) a validity mask, and (3) a selection vector Access to the individual vector elements can be performed through data_pointer[sel_idx[i]]/validity[sel_idx[i]] The most common vector types (flat, constant & dictionary) can be converted to the canonical format "for free" ToUnifiedFormat was originally called Orrify, as a tribute to Orri Erling who came up with it

136886 {
136887 format.physical_type = GetType().InternalType();
136888 switch (GetVectorType()) {
136889 case VectorType::DICTIONARY_VECTOR: {
136890 auto &sel = DictionaryVector::SelVector(*this);
136891 format.owned_sel.Initialize(sel);
136892 format.sel = &format.owned_sel;
136893
136894 auto &child = DictionaryVector::Child(*this);
136895 if (child.GetVectorType() == VectorType::FLAT_VECTOR) {
136896 format.data = FlatVector::GetData(child);
136897 format.validity = FlatVector::Validity(child);
136898 } else {
136899 // dictionary with non-flat child: create a new reference to the child and flatten it
136900 Vector child_vector(child);
136901 child_vector.Flatten(sel, count);
136902 auto new_aux = make_buffer<VectorChildBuffer>(std::move(child_vector));
136903
136904 format.data = FlatVector::GetData(new_aux->data);
136905 format.validity = FlatVector::Validity(new_aux->data);
136906 this->auxiliary = std::move(new_aux);
136907 }
136908 break;
136909 }
136910 case VectorType::CONSTANT_VECTOR:
136911 format.sel = ConstantVector::ZeroSelectionVector(count, format.owned_sel);
136912 format.data = ConstantVector::GetData(*this);
136913 format.validity = ConstantVector::Validity(*this);
136914 break;
136915 default:
136916 Flatten(count);
136917 format.sel = FlatVector::IncrementalSelectionVector();
136918 format.data = FlatVector::GetData(*this);
136919 format.validity = FlatVector::Validity(*this);
136920 break;
136921 }
136922}
std::basic_string< Char > format(const S &format_str, Args &&... args)
Definition duckdb.cpp:16295
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecursiveToUnifiedFormat()

void duckdb::Vector::RecursiveToUnifiedFormat ( Vector & input,
idx_t count,
RecursiveUnifiedVectorFormat & data )
static

Recursively calls UnifiedVectorFormat on a vector and its child vectors (for nested types).

136924 {
136925 input.ToUnifiedFormat(count, data.unified);
136926 data.logical_type = input.GetType();
136927
136928 if (input.GetType().InternalType() == PhysicalType::LIST) {
136929 auto &child = ListVector::GetEntry(input);
136930 auto child_count = ListVector::GetListSize(input);
136931 data.children.emplace_back();
136932 Vector::RecursiveToUnifiedFormat(child, child_count, data.children.back());
136933
136934 } else if (input.GetType().InternalType() == PhysicalType::ARRAY) {
136935 auto &child = ArrayVector::GetEntry(input);
136936 auto array_size = ArrayType::GetSize(input.GetType());
136937 auto child_count = count * array_size;
136938 data.children.emplace_back();
136939 Vector::RecursiveToUnifiedFormat(child, child_count, data.children.back());
136940
136941 } else if (input.GetType().InternalType() == PhysicalType::STRUCT) {
136942 auto &children = StructVector::GetEntries(input);
136943 for (idx_t i = 0; i < children.size(); i++) {
136944 data.children.emplace_back();
136945 }
136946 for (idx_t i = 0; i < children.size(); i++) {
136947 Vector::RecursiveToUnifiedFormat(*children[i], count, data.children[i]);
136948 }
136949 }
136950}
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sequence()

void duckdb::Vector::Sequence ( int64_t start,
int64_t increment,
idx_t count )

Turn the vector into a sequence vector.

136952 {
136953 this->vector_type = VectorType::SEQUENCE_VECTOR;
136954 this->buffer = make_buffer<VectorBuffer>(sizeof(int64_t) * 3);
136955 auto data = reinterpret_cast<int64_t *>(buffer->GetData());
136956 data[0] = start;
136957 data[1] = increment;
136958 data[2] = int64_t(count);
136959 validity.Reset();
136960 auxiliary.reset();
136961}

◆ Verify() [1/2]

void duckdb::Vector::Verify ( idx_t count)

Verify that the Vector is in a consistent, not corrupt state. DEBUG FUNCTION ONLY!

137589 {
137590 auto flat_sel = FlatVector::IncrementalSelectionVector();
137591 Verify(*this, *flat_sel, count);
137592}
DUCKDB_API void Verify(idx_t count)
Definition duckdb.cpp:137589
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VerifyMap()

void duckdb::Vector::VerifyMap ( Vector & map,
const SelectionVector & sel,
idx_t count )
static

Asserts that the CheckMapValidity returns MapInvalidReason::VALID.

137320 {
137321#ifdef DEBUG
137322 D_ASSERT(vector_p.GetType().id() == LogicalTypeId::MAP);
137323 auto &child = ListType::GetChildType(vector_p.GetType());
137324 D_ASSERT(StructType::GetChildCount(child) == 2);
137325 D_ASSERT(StructType::GetChildName(child, 0) == "key");
137326 D_ASSERT(StructType::GetChildName(child, 1) == "value");
137327
137328 auto valid_check = MapVector::CheckMapValidity(vector_p, count, sel_p);
137329 D_ASSERT(valid_check == MapInvalidReason::VALID);
137330#endif // DEBUG
137331}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VerifyUnion()

void duckdb::Vector::VerifyUnion ( Vector & map,
const SelectionVector & sel,
idx_t count )
static
137333 {
137334#ifdef DEBUG
137335
137336 D_ASSERT(vector_p.GetType().id() == LogicalTypeId::UNION);
137337 auto valid_check = UnionVector::CheckUnionValidity(vector_p, count, sel_p);
137338 if (valid_check != UnionInvalidReason::VALID) {
137339 throw InternalException("Union not valid, reason: %s", EnumUtil::ToString(valid_check));
137340 }
137341#endif // DEBUG
137342}
static DUCKDB_API UnionInvalidReason CheckUnionValidity(Vector &vector, idx_t count, const SelectionVector &sel= *FlatVector::IncrementalSelectionVector())
Raw selection vector passed in (not merged with any other selection vectors).
Definition duckdb.cpp:138482

◆ VerifyVariant()

void duckdb::Vector::VerifyVariant ( Vector & map,
const SelectionVector & sel,
idx_t count )
static
137344 {
137345#ifdef DEBUG
137346
137347 D_ASSERT(vector_p.GetType().id() == LogicalTypeId::VARIANT);
137348 if (!VariantUtils::Verify(vector_p, sel_p, count)) {
137349 throw InternalException("Variant not valid");
137350 }
137351#endif // DEBUG
137352}
static DUCKDB_API bool Verify(Vector &variant, const SelectionVector &sel_p, idx_t count)
Definition duckdb.cpp:238660

◆ Verify() [2/2]

void duckdb::Vector::Verify ( Vector & vector,
const SelectionVector & sel,
idx_t count )
static
137354 {
137355#ifdef DEBUG
137356 if (count == 0) {
137357 return;
137358 }
137359 Vector *vector = &vector_p;
137360 const SelectionVector *sel = &sel_p;
137361 SelectionVector owned_sel;
137362 auto &type = vector->GetType();
137363 auto vtype = vector->GetVectorType();
137364 if (vector->GetVectorType() == VectorType::DICTIONARY_VECTOR) {
137365 auto &child = DictionaryVector::Child(*vector);
137366 D_ASSERT(child.GetVectorType() != VectorType::DICTIONARY_VECTOR);
137367 auto &dict_sel = DictionaryVector::SelVector(*vector);
137368 // merge the selection vectors and verify the child
137369 auto new_buffer = dict_sel.Slice(*sel, count);
137370 owned_sel.Initialize(new_buffer);
137371 sel = &owned_sel;
137372 vector = &child;
137373 vtype = vector->GetVectorType();
137374 }
137375 if (TypeIsConstantSize(type.InternalType()) &&
137376 (vtype == VectorType::CONSTANT_VECTOR || vtype == VectorType::FLAT_VECTOR)) {
137377 D_ASSERT(!vector->auxiliary);
137378 }
137379 if (type.id() == LogicalTypeId::VARCHAR) {
137380 // verify that the string is correct unicode
137381 switch (vtype) {
137382 case VectorType::FLAT_VECTOR: {
137383 auto &validity = FlatVector::Validity(*vector);
137384 auto strings = FlatVector::GetData<string_t>(*vector);
137385 for (idx_t i = 0; i < count; i++) {
137386 auto oidx = sel->get_index(i);
137387 if (validity.RowIsValid(oidx)) {
137388 strings[oidx].Verify();
137389 }
137390 }
137391 break;
137392 }
137393 default:
137394 break;
137395 }
137396 }
137397
137398 if (type.id() == LogicalTypeId::BIGNUM) {
137399 switch (vtype) {
137400 case VectorType::FLAT_VECTOR: {
137401 auto &validity = FlatVector::Validity(*vector);
137402 auto strings = FlatVector::GetData<string_t>(*vector);
137403 for (idx_t i = 0; i < count; i++) {
137404 auto oidx = sel->get_index(i);
137405 if (validity.RowIsValid(oidx)) {
137406 Bignum::Verify(static_cast<bignum_t>(strings[oidx]));
137407 }
137408 }
137409 } break;
137410 default:
137411 break;
137412 }
137413 }
137414
137415 if (type.id() == LogicalTypeId::BIT) {
137416 switch (vtype) {
137417 case VectorType::FLAT_VECTOR: {
137418 auto &validity = FlatVector::Validity(*vector);
137419 auto strings = FlatVector::GetData<string_t>(*vector);
137420 for (idx_t i = 0; i < count; i++) {
137421 auto oidx = sel->get_index(i);
137422 if (validity.RowIsValid(oidx)) {
137423 auto buf = strings[oidx].GetData();
137424 D_ASSERT(idx_t(*buf) < 8);
137425 Bit::Verify(strings[oidx]);
137426 }
137427 }
137428 break;
137429 }
137430 default:
137431 break;
137432 }
137433 }
137434
137435 if (type.InternalType() == PhysicalType::ARRAY) {
137436 // Arrays have the following invariants
137437 // 1. if the array vector is a CONSTANT_VECTOR
137438 // 1.1 The child vector is a FLAT_VECTOR with count = array_size
137439 // 1.2 OR The child vector is a CONSTANT_VECTOR and must be NULL
137440 // 1.3 OR The child vector is a CONSTANT_VECTOR and array_size = 1
137441 // 2. if the array vector is a FLAT_VECTOR, the child vector is a FLAT_VECTOR
137442 // 2.2 the count of the child vector is array_size * (parent)count
137443
137444 auto &child = ArrayVector::GetEntry(*vector);
137445 auto array_size = ArrayType::GetSize(type);
137446
137447 if (child.GetVectorType() == VectorType::CONSTANT_VECTOR) {
137448 D_ASSERT(ConstantVector::IsNull(child));
137449 } else {
137450 D_ASSERT(child.GetVectorType() == VectorType::FLAT_VECTOR);
137451 }
137452
137453 if (vtype == VectorType::CONSTANT_VECTOR) {
137454 if (!ConstantVector::IsNull(*vector)) {
137455 child.Verify(array_size);
137456 }
137457 } else if (vtype == VectorType::FLAT_VECTOR) {
137458 // Flat vector case
137459 auto &validity = FlatVector::Validity(*vector);
137460 idx_t selected_child_count = 0;
137461 for (idx_t i = 0; i < count; i++) {
137462 auto oidx = sel->get_index(i);
137463 if (validity.RowIsValid(oidx)) {
137464 selected_child_count += array_size;
137465 }
137466 }
137467
137468 SelectionVector child_sel(selected_child_count);
137469 idx_t child_count = 0;
137470 for (idx_t i = 0; i < count; i++) {
137471 auto oidx = sel->get_index(i);
137472 if (validity.RowIsValid(oidx)) {
137473 for (idx_t j = 0; j < array_size; j++) {
137474 child_sel.set_index(child_count++, oidx * array_size + j);
137475 }
137476 }
137477 }
137478 Vector::Verify(child, child_sel, child_count);
137479 }
137480 }
137481
137482 if (type.InternalType() == PhysicalType::STRUCT) {
137483 auto &child_types = StructType::GetChildTypes(type);
137484 D_ASSERT(!child_types.empty());
137485
137486 // create a selection vector of the non-null entries of the struct vector
137487 auto &children = StructVector::GetEntries(*vector);
137488 D_ASSERT(child_types.size() == children.size());
137489 for (idx_t child_idx = 0; child_idx < children.size(); child_idx++) {
137490 D_ASSERT(children[child_idx]->GetType() == child_types[child_idx].second);
137491 Vector::Verify(*children[child_idx], sel_p, count);
137492 if (vtype == VectorType::CONSTANT_VECTOR) {
137493 D_ASSERT(children[child_idx]->GetVectorType() == VectorType::CONSTANT_VECTOR);
137494 if (ConstantVector::IsNull(*vector)) {
137495 D_ASSERT(ConstantVector::IsNull(*children[child_idx]));
137496 }
137497 }
137498 if (vtype != VectorType::FLAT_VECTOR) {
137499 continue;
137500 }
137501 optional_ptr<ValidityMask> child_validity;
137502 SelectionVector owned_child_sel;
137503 const SelectionVector *child_sel = &owned_child_sel;
137504 if (children[child_idx]->GetVectorType() == VectorType::FLAT_VECTOR) {
137505 child_sel = FlatVector::IncrementalSelectionVector();
137506 child_validity = &FlatVector::Validity(*children[child_idx]);
137507 } else if (children[child_idx]->GetVectorType() == VectorType::DICTIONARY_VECTOR) {
137508 auto &child = DictionaryVector::Child(*children[child_idx]);
137509 if (child.GetVectorType() != VectorType::FLAT_VECTOR) {
137510 continue;
137511 }
137512 child_validity = &FlatVector::Validity(child);
137513 child_sel = &DictionaryVector::SelVector(*children[child_idx]);
137514 } else if (children[child_idx]->GetVectorType() == VectorType::CONSTANT_VECTOR) {
137515 child_sel = ConstantVector::ZeroSelectionVector(count, owned_child_sel);
137516 child_validity = &ConstantVector::Validity(*children[child_idx]);
137517 } else {
137518 continue;
137519 }
137520 // for any NULL entry in the struct, the child should be NULL as well
137521 auto &validity = FlatVector::Validity(*vector);
137522 for (idx_t i = 0; i < count; i++) {
137523 auto index = sel->get_index(i);
137524 if (!validity.RowIsValid(index)) {
137525 auto child_index = child_sel->get_index(sel_p.get_index(i));
137526 D_ASSERT(!child_validity->RowIsValid(child_index));
137527 }
137528 }
137529 }
137530
137531 if (vector->GetType().id() == LogicalTypeId::UNION) {
137532 // Pass in raw vector
137533 VerifyUnion(vector_p, sel_p, count);
137534 }
137535 if (vector->GetType().id() == LogicalTypeId::VARIANT) {
137536 VerifyVariant(vector_p, sel_p, count);
137537 }
137538 }
137539
137540 if (type.InternalType() == PhysicalType::LIST) {
137541 if (vtype == VectorType::CONSTANT_VECTOR) {
137542 if (!ConstantVector::IsNull(*vector)) {
137543 auto &child = ListVector::GetEntry(*vector);
137544 SelectionVector child_sel(ListVector::GetListSize(*vector));
137545 idx_t child_count = 0;
137546 auto le = ConstantVector::GetData<list_entry_t>(*vector);
137547 D_ASSERT(le->offset + le->length <= ListVector::GetListSize(*vector));
137548 for (idx_t k = 0; k < le->length; k++) {
137549 child_sel.set_index(child_count++, le->offset + k);
137550 }
137551 Vector::Verify(child, child_sel, child_count);
137552 }
137553 } else if (vtype == VectorType::FLAT_VECTOR) {
137554 auto &validity = FlatVector::Validity(*vector);
137555 auto &child = ListVector::GetEntry(*vector);
137556 auto child_size = ListVector::GetListSize(*vector);
137557 auto list_data = FlatVector::GetData<list_entry_t>(*vector);
137558 idx_t total_size = 0;
137559 for (idx_t i = 0; i < count; i++) {
137560 auto idx = sel->get_index(i);
137561 auto &le = list_data[idx];
137562 if (validity.RowIsValid(idx)) {
137563 D_ASSERT(le.offset + le.length <= child_size);
137564 total_size += le.length;
137565 }
137566 }
137567 SelectionVector child_sel(total_size);
137568 idx_t child_count = 0;
137569 for (idx_t i = 0; i < count; i++) {
137570 auto idx = sel->get_index(i);
137571 auto &le = list_data[idx];
137572 if (validity.RowIsValid(idx)) {
137573 D_ASSERT(le.offset + le.length <= child_size);
137574 for (idx_t k = 0; k < le.length; k++) {
137575 child_sel.set_index(child_count++, le.offset + k);
137576 }
137577 }
137578 }
137579 Vector::Verify(child, child_sel, child_count);
137580 }
137581
137582 if (vector->GetType().id() == LogicalTypeId::MAP) {
137583 VerifyMap(*vector, *sel, count);
137584 }
137585 }
137586#endif
137587}
static DUCKDB_API void Verify(const bignum_t &input)
Definition duckdb.cpp:112334
static DUCKDB_API void VerifyMap(Vector &map, const SelectionVector &sel, idx_t count)
Asserts that the CheckMapValidity returns MapInvalidReason::VALID.
Definition duckdb.cpp:137320
index

◆ UTFVerify() [1/2]

void duckdb::Vector::UTFVerify ( idx_t count)
137314 {
137315 auto flat_sel = FlatVector::IncrementalSelectionVector();
137316
137317 UTFVerify(*flat_sel, count);
137318}

◆ UTFVerify() [2/2]

void duckdb::Vector::UTFVerify ( const SelectionVector & sel,
idx_t count )
137281 {
137282#ifdef DEBUG
137283 if (count == 0) {
137284 return;
137285 }
137286 if (GetType().InternalType() == PhysicalType::VARCHAR) {
137287 // we just touch all the strings and let the sanitizer figure out if any
137288 // of them are deallocated/corrupt
137289 switch (GetVectorType()) {
137290 case VectorType::CONSTANT_VECTOR: {
137291 auto string = ConstantVector::GetData<string_t>(*this);
137292 if (!ConstantVector::IsNull(*this)) {
137293 string->Verify();
137294 }
137295 break;
137296 }
137297 case VectorType::FLAT_VECTOR: {
137298 auto strings = FlatVector::GetData<string_t>(*this);
137299 for (idx_t i = 0; i < count; i++) {
137300 auto oidx = sel.get_index(i);
137301 if (validity.RowIsValid(oidx)) {
137302 strings[oidx].Verify();
137303 }
137304 }
137305 break;
137306 }
137307 default:
137308 break;
137309 }
137310 }
137311#endif
137312}

◆ GetValue() [1/2]

Value duckdb::Vector::GetValue ( idx_t index) const

Returns the [index] element of the Vector as a Value.

136515 {
136516 return GetValue(*this, index);
136517}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetValue()

void duckdb::Vector::SetValue ( idx_t index,
const Value & val )

Sets the [index] element of the Vector to the specified Value.

now set the pointer

136134 {
136135 if (GetVectorType() == VectorType::DICTIONARY_VECTOR) {
136136 // dictionary: apply dictionary and forward to child
136137 auto &sel_vector = DictionaryVector::SelVector(*this);
136138 auto &child = DictionaryVector::Child(*this);
136139 return child.SetValue(sel_vector.get_index(index), val);
136140 }
136141 if (!val.IsNull() && val.type() != GetType()) {
136142 SetValue(index, val.DefaultCastAs(GetType()));
136143 return;
136144 }
136145 D_ASSERT(val.IsNull() || (val.type().InternalType() == GetType().InternalType()));
136146
136147 validity.Set(index, !val.IsNull());
136148 auto physical_type = GetType().InternalType();
136149 if (val.IsNull() && !IsStructOrArrayRecursive(GetType())) {
136150 // for structs and arrays we still need to set the child-entries to NULL
136151 // so we do not bail out yet
136152 return;
136153 }
136154
136155 switch (physical_type) {
136156 case PhysicalType::BOOL:
136157 reinterpret_cast<bool *>(data)[index] = val.GetValueUnsafe<bool>();
136158 break;
136159 case PhysicalType::INT8:
136160 reinterpret_cast<int8_t *>(data)[index] = val.GetValueUnsafe<int8_t>();
136161 break;
136162 case PhysicalType::INT16:
136163 reinterpret_cast<int16_t *>(data)[index] = val.GetValueUnsafe<int16_t>();
136164 break;
136165 case PhysicalType::INT32:
136166 reinterpret_cast<int32_t *>(data)[index] = val.GetValueUnsafe<int32_t>();
136167 break;
136168 case PhysicalType::INT64:
136169 reinterpret_cast<int64_t *>(data)[index] = val.GetValueUnsafe<int64_t>();
136170 break;
136171 case PhysicalType::INT128:
136172 reinterpret_cast<hugeint_t *>(data)[index] = val.GetValueUnsafe<hugeint_t>();
136173 break;
136174 case PhysicalType::UINT8:
136175 reinterpret_cast<uint8_t *>(data)[index] = val.GetValueUnsafe<uint8_t>();
136176 break;
136178 reinterpret_cast<uint16_t *>(data)[index] = val.GetValueUnsafe<uint16_t>();
136179 break;
136181 reinterpret_cast<uint32_t *>(data)[index] = val.GetValueUnsafe<uint32_t>();
136182 break;
136184 reinterpret_cast<uint64_t *>(data)[index] = val.GetValueUnsafe<uint64_t>();
136185 break;
136186 case PhysicalType::UINT128:
136187 reinterpret_cast<uhugeint_t *>(data)[index] = val.GetValueUnsafe<uhugeint_t>();
136188 break;
136189 case PhysicalType::FLOAT:
136190 reinterpret_cast<float *>(data)[index] = val.GetValueUnsafe<float>();
136191 break;
136193 reinterpret_cast<double *>(data)[index] = val.GetValueUnsafe<double>();
136194 break;
136196 reinterpret_cast<interval_t *>(data)[index] = val.GetValueUnsafe<interval_t>();
136197 break;
136198 case PhysicalType::VARCHAR: {
136199 if (!val.IsNull()) {
136200 reinterpret_cast<string_t *>(data)[index] = StringVector::AddStringOrBlob(*this, StringValue::Get(val));
136201 }
136202 break;
136203 }
136204 case PhysicalType::STRUCT: {
136205 D_ASSERT(GetVectorType() == VectorType::CONSTANT_VECTOR || GetVectorType() == VectorType::FLAT_VECTOR);
136206
136207 auto &children = StructVector::GetEntries(*this);
136208 if (val.IsNull()) {
136209 for (size_t i = 0; i < children.size(); i++) {
136210 auto &vec_child = children[i];
136211 vec_child->SetValue(index, Value());
136212 }
136213 } else {
136214 auto &val_children = StructValue::GetChildren(val);
136215 D_ASSERT(children.size() == val_children.size());
136216 for (size_t i = 0; i < children.size(); i++) {
136217 auto &vec_child = children[i];
136218 auto &struct_child = val_children[i];
136219 vec_child->SetValue(index, struct_child);
136220 }
136221 }
136222 break;
136223 }
136224 case PhysicalType::LIST: {
136225 auto offset = ListVector::GetListSize(*this);
136226 if (val.IsNull()) {
136227 auto &entry = reinterpret_cast<list_entry_t *>(data)[index];
136228 ListVector::PushBack(*this, Value());
136229 entry.length = 1;
136230 entry.offset = offset;
136231 } else {
136232 auto &val_children = ListValue::GetChildren(val);
136233 if (!val_children.empty()) {
136234 for (idx_t i = 0; i < val_children.size(); i++) {
136235 ListVector::PushBack(*this, val_children[i]);
136236 }
136237 }
136239 auto &entry = reinterpret_cast<list_entry_t *>(data)[index];
136240 entry.length = val_children.size();
136241 entry.offset = offset;
136242 }
136243 break;
136244 }
136245 case PhysicalType::ARRAY: {
136246 auto array_size = ArrayType::GetSize(GetType());
136247 auto &child = ArrayVector::GetEntry(*this);
136248 if (val.IsNull()) {
136249 for (idx_t i = 0; i < array_size; i++) {
136250 child.SetValue(index * array_size + i, Value());
136251 }
136252 } else {
136253 auto &val_children = ArrayValue::GetChildren(val);
136254 for (idx_t i = 0; i < array_size; i++) {
136255 child.SetValue(index * array_size + i, val_children[i]);
136256 }
136257 }
136258 break;
136259 }
136260 default:
136261 throw InternalException("Unimplemented type for Vector::SetValue");
136262 }
136263}
::int8_t int8_t
::uint32_t uint32_t
::uint8_t uint8_t
::uint16_t uint16_t
::int32_t int32_t
::int16_t int16_t
static DUCKDB_API string_t AddStringOrBlob(Vector &vector, const char *data, idx_t len)
Definition duckdb.cpp:137893
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAuxiliary()

void duckdb::Vector::SetAuxiliary ( buffer_ptr< VectorBuffer > new_buffer)
inline
10708 {
10709 auxiliary = std::move(new_buffer);
10710 };

◆ CopyBuffer()

void duckdb::Vector::CopyBuffer ( Vector & other)
inline
10712 {
10713 buffer = other.buffer;
10714 data = other.data;
10715 }

◆ Resize()

void duckdb::Vector::Resize ( idx_t cur_size,
idx_t new_size )

Resizes the vector.

136086 {
136087 // The vector does not contain any data.
136088 if (!buffer) {
136089 buffer = make_buffer<VectorBuffer>(0);
136090 }
136091
136092 // Obtain the resize information for each (nested) vector.
136093 vector<ResizeInfo> resize_infos;
136094 FindResizeInfos(resize_infos, 1);
136095
136096 for (auto &resize_info_entry : resize_infos) {
136097 // Resize the validity mask.
136098 auto new_validity_size = new_size * resize_info_entry.multiplier;
136099 resize_info_entry.vec.validity.Resize(new_validity_size);
136100
136101 // For nested data types, we only need to resize the validity mask.
136102 if (!resize_info_entry.data) {
136103 continue;
136104 }
136105
136106 auto type_size = GetTypeIdSize(resize_info_entry.vec.GetType().InternalType());
136107 auto old_size = current_size * type_size * resize_info_entry.multiplier * sizeof(data_t);
136108 auto target_size = new_size * type_size * resize_info_entry.multiplier * sizeof(data_t);
136109
136110 // We have an upper limit of 128GB for a single vector.
136111 if (target_size > DConstants::MAX_VECTOR_SIZE) {
136112 throw OutOfRangeException("Cannot resize vector to %s: maximum allowed vector size is %s",
136115 }
136116
136117 // Copy the data buffer to a resized buffer.
136118 auto stored_allocator = resize_info_entry.buffer->GetAllocator();
136119 auto new_data = stored_allocator ? stored_allocator->Allocate(target_size)
136120 : Allocator::DefaultAllocator().Allocate(target_size);
136121 memcpy(new_data.get(), resize_info_entry.data, old_size);
136122 resize_info_entry.buffer->SetData(std::move(new_data));
136123 resize_info_entry.vec.data = resize_info_entry.buffer->GetData();
136124 }
136125}
static DUCKDB_API string BytesToHumanReadableString(idx_t bytes, idx_t multiplier=1024)
Return a string that formats the give number of bytes.
Definition duckdb.cpp:109517
DUCKDB_API void FindResizeInfos(vector< ResizeInfo > &resize_infos, const idx_t multiplier)
Returns a vector of ResizeInfo containing each (nested) vector to resize.
Definition duckdb.cpp:136047
uint8_t data_t
data pointers
Definition duckdb.hpp:246
static constexpr const idx_t MAX_VECTOR_SIZE
The total maximum vector size (128GB).
Definition duckdb.hpp:1119
Here is the call graph for this function:

◆ FindResizeInfos()

void duckdb::Vector::FindResizeInfos ( vector< ResizeInfo > & resize_infos,
const idx_t multiplier )

Returns a vector of ResizeInfo containing each (nested) vector to resize.

136047 {
136048 ResizeInfo resize_info(*this, data, buffer.get(), multiplier);
136049 resize_infos.emplace_back(resize_info);
136050
136051 // Base case.
136052 if (data) {
136053 return;
136054 }
136055
136056 D_ASSERT(auxiliary);
136057 switch (GetAuxiliary()->GetBufferType()) {
136058 case VectorBufferType::LIST_BUFFER: {
136059 auto &vector_list_buffer = auxiliary->Cast<VectorListBuffer>();
136060 auto &child = vector_list_buffer.GetChild();
136061 child.FindResizeInfos(resize_infos, multiplier);
136062 break;
136063 }
136064 case VectorBufferType::STRUCT_BUFFER: {
136065 auto &vector_struct_buffer = auxiliary->Cast<VectorStructBuffer>();
136066 auto &children = vector_struct_buffer.GetChildren();
136067 for (auto &child : children) {
136068 child->FindResizeInfos(resize_infos, multiplier);
136069 }
136070 break;
136071 }
136072 case VectorBufferType::ARRAY_BUFFER: {
136073 // We need to multiply the multiplier by the array size because
136074 // the child vectors of ARRAY types are always child_count * array_size.
136075 auto &vector_array_buffer = auxiliary->Cast<VectorArrayBuffer>();
136076 auto new_multiplier = vector_array_buffer.GetArraySize() * multiplier;
136077 auto &child = vector_array_buffer.GetChild();
136078 child.FindResizeInfos(resize_infos, new_multiplier);
136079 break;
136080 }
136081 default:
136082 break;
136083 }
136084}
Here is the caller graph for this function:

◆ Serialize()

void duckdb::Vector::Serialize ( Serializer & serializer,
idx_t count,
bool compressed_serialization = true )
136964 {
136965 auto &logical_type = GetType();
136966
136967 UnifiedVectorFormat vdata;
136968
136969 // serialize compressed vectors to save space, but skip this if serializing into older versions
136970 if (!serializer.ShouldSerialize(5)) {
136971 compressed_serialization = false;
136972 }
136973 if (compressed_serialization) {
136974 auto vtype = GetVectorType();
136975 if (vtype == VectorType::DICTIONARY_VECTOR && DictionaryVector::DictionarySize(*this).IsValid()) {
136976 auto dict = DictionaryVector::Child(*this);
136977 if (dict.GetVectorType() == VectorType::FLAT_VECTOR) {
136978 idx_t dict_count = DictionaryVector::DictionarySize(*this).GetIndex();
136979 auto old_sel = DictionaryVector::SelVector(*this);
136980 SelectionVector new_sel(count), used_sel(count), map_sel(dict_count);
136981
136982 // dictionaries may be large (row-group level). A vector may use only a small part.
136983 // So, restrict dict to the used_sel subset & remap old_sel into new_sel to the new dict positions
136984 sel_t CODE_UNSEEN = static_cast<sel_t>(dict_count);
136985 for (sel_t i = 0; i < dict_count; ++i) {
136986 map_sel[i] = CODE_UNSEEN; // initialize with unused marker
136987 }
136988 idx_t used_count = 0;
136989 for (idx_t i = 0; i < count; ++i) {
136990 auto pos = old_sel[i];
136991 if (map_sel[pos] == CODE_UNSEEN) {
136992 map_sel[pos] = static_cast<sel_t>(used_count);
136993 used_sel[used_count++] = pos;
136994 }
136995 new_sel[i] = map_sel[pos];
136996 }
136997 if (used_count * 2 < count) { // only serialize as a dict vector if that makes things smaller
136998 auto sel_data = reinterpret_cast<data_ptr_t>(new_sel.data());
136999 dict.Slice(used_sel, used_count);
137000 serializer.WriteProperty(90, "vector_type", VectorType::DICTIONARY_VECTOR);
137001 serializer.WriteProperty(91, "sel_vector", sel_data, sizeof(sel_t) * count);
137002 serializer.WriteProperty(92, "dict_count", used_count);
137003 return dict.Serialize(serializer, used_count, false);
137004 }
137005 }
137006 } else if (vtype == VectorType::CONSTANT_VECTOR && count >= 1) {
137007 serializer.WriteProperty(90, "vector_type", VectorType::CONSTANT_VECTOR);
137008 return Vector::Serialize(serializer, 1, false); // just serialize one value
137009 } else if (vtype == VectorType::SEQUENCE_VECTOR) {
137010 serializer.WriteProperty(90, "vector_type", VectorType::SEQUENCE_VECTOR);
137011 auto data = reinterpret_cast<int64_t *>(buffer->GetData());
137012 serializer.WriteProperty(91, "seq_start", data[0]);
137013 serializer.WriteProperty(92, "seq_increment", data[1]);
137014 return; // for sequence vectors we do not serialize anything else
137015 } else {
137016 // TODO: other compressed vector types (FSST)
137017 }
137018 }
137019 ToUnifiedFormat(count, vdata);
137020
137021 if (logical_type.id() == LogicalTypeId::GEOMETRY && serializer.ShouldSerialize(Geometry::VERSION_ADDED)) {
137022 serializer.WriteProperty<GeometryStorageType>(99, "geometry_format", GeometryStorageType::WKB);
137023 }
137024
137025 const bool has_validity_mask = (count > 0) && !vdata.validity.AllValid();
137026 serializer.WriteProperty(100, "has_validity_mask", has_validity_mask);
137027 if (has_validity_mask) {
137028 ValidityMask flat_mask(count);
137029 flat_mask.Initialize();
137030 for (idx_t i = 0; i < count; ++i) {
137031 auto row_idx = vdata.sel->get_index(i);
137032 flat_mask.Set(i, vdata.validity.RowIsValid(row_idx));
137033 }
137034 serializer.WriteProperty(101, "validity", const_data_ptr_cast(flat_mask.GetData()),
137035 flat_mask.ValidityMaskSize(count));
137036 }
137037 if (TypeIsConstantSize(logical_type.InternalType())) {
137038 // constant size type: simple copy
137039 idx_t write_size = GetTypeIdSize(logical_type.InternalType()) * count;
137040 auto ptr = make_unsafe_uniq_array_uninitialized<data_t>(write_size);
137041 VectorOperations::WriteToStorage(*this, count, ptr.get());
137042 serializer.WriteProperty(102, "data", ptr.get(), write_size);
137043 } else if (logical_type.id() == LogicalTypeId::GEOMETRY) {
137044 auto geoms = UnifiedVectorFormat::GetData<string_t>(vdata);
137045
137046 // Are we targeting an older serialization version?
137047 if (!serializer.ShouldSerialize(7)) {
137048 // Serialize data as old-style SPATIAL format
137049 string blob;
137050 serializer.WriteList(102, "data", count, [&](Serializer::List &list, idx_t i) {
137051 auto idx = vdata.sel->get_index(i);
137052 if (!vdata.validity.RowIsValid(idx)) {
137053 list.WriteElement(NullValue<string_t>());
137054 } else {
137055 Geometry::ToSpatialGeometry(geoms[idx], blob);
137056 list.WriteElement(blob);
137057 }
137058 });
137059 } else {
137060 // Serialize as WKB format
137061 serializer.WriteList(102, "data", count, [&](Serializer::List &list, idx_t i) {
137062 auto idx = vdata.sel->get_index(i);
137063 auto wkb = !vdata.validity.RowIsValid(idx) ? NullValue<string_t>() : geoms[idx];
137064 list.WriteElement(wkb);
137065 });
137066 }
137067 } else {
137068 switch (logical_type.InternalType()) {
137069 case PhysicalType::VARCHAR: {
137070 auto strings = UnifiedVectorFormat::GetData<string_t>(vdata);
137071
137072 // Serialize data as a list
137073 serializer.WriteList(102, "data", count, [&](Serializer::List &list, idx_t i) {
137074 auto idx = vdata.sel->get_index(i);
137075 auto str = !vdata.validity.RowIsValid(idx) ? NullValue<string_t>() : strings[idx];
137076 list.WriteElement(str);
137077 });
137078 break;
137079 }
137080 case PhysicalType::STRUCT: {
137081 auto &entries = StructVector::GetEntries(*this);
137082
137083 // Serialize entries as a list
137084 serializer.WriteList(103, "children", entries.size(), [&](Serializer::List &list, idx_t i) {
137085 list.WriteObject(
137086 [&](Serializer &object) { entries[i]->Serialize(object, count, compressed_serialization); });
137087 });
137088 break;
137089 }
137090 case PhysicalType::LIST: {
137091 auto &child = ListVector::GetEntry(*this);
137092 auto list_size = ListVector::GetListSize(*this);
137093
137094 // serialize the list entries in a flat array
137095 auto entries = make_unsafe_uniq_array_uninitialized<list_entry_t>(count);
137096 auto source_array = UnifiedVectorFormat::GetData<list_entry_t>(vdata);
137097 for (idx_t i = 0; i < count; i++) {
137098 auto idx = vdata.sel->get_index(i);
137099 auto source = source_array[idx];
137100 if (vdata.validity.RowIsValid(idx)) {
137101 entries[i].offset = source.offset;
137102 entries[i].length = source.length;
137103 } else {
137104 entries[i].offset = 0;
137105 entries[i].length = 0;
137106 }
137107 }
137108 serializer.WriteProperty(104, "list_size", list_size);
137109 serializer.WriteList(105, "entries", count, [&](Serializer::List &list, idx_t i) {
137110 list.WriteObject([&](Serializer &object) {
137111 object.WriteProperty(100, "offset", entries[i].offset);
137112 object.WriteProperty(101, "length", entries[i].length);
137113 });
137114 });
137115 serializer.WriteObject(106, "child", [&](Serializer &object) {
137116 child.Serialize(object, list_size, compressed_serialization);
137117 });
137118 break;
137119 }
137120 case PhysicalType::ARRAY: {
137121 Vector serialized_vector(*this);
137122 serialized_vector.Flatten(count);
137123
137124 auto &child = ArrayVector::GetEntry(serialized_vector);
137125 auto array_size = ArrayType::GetSize(serialized_vector.GetType());
137126 auto child_size = array_size * count;
137127 serializer.WriteProperty<uint64_t>(103, "array_size", array_size);
137128 serializer.WriteObject(104, "child", [&](Serializer &object) {
137129 child.Serialize(object, child_size, compressed_serialization);
137130 });
137131 break;
137132 }
137133 default:
137134 throw InternalException("Unimplemented variable width type for Vector::Serialize!");
137135 }
137136 }
137137}
DUCKDB_API void ToUnifiedFormat(idx_t count, UnifiedVectorFormat &data)
Definition duckdb.cpp:136886
T NullValue()
Placeholder to insert in Vectors or to use for hashing NULLs.
Definition duckdb.cpp:30953
uint32_t sel_t
Type used for the selection vector.
Definition duckdb.hpp:251

◆ Deserialize()

void duckdb::Vector::Deserialize ( Deserializer & deserializer,
idx_t count )
137139 {
137140 auto &logical_type = GetType();
137141
137142 const auto vtype = // older versions that only supported flat vectors did not serialize vector_type,
137143 deserializer.ReadPropertyWithExplicitDefault<VectorType>(90, "vector_type", VectorType::FLAT_VECTOR);
137144
137145 // first handle deserialization of compressed vector types
137146 if (vtype == VectorType::CONSTANT_VECTOR) {
137147 Vector::Deserialize(deserializer, 1); // read a vector of size 1
137148 Vector::SetVectorType(VectorType::CONSTANT_VECTOR);
137149 return;
137150 } else if (vtype == VectorType::DICTIONARY_VECTOR) {
137151 SelectionVector sel(count);
137152 deserializer.ReadProperty(91, "sel_vector", reinterpret_cast<data_ptr_t>(sel.data()), sizeof(sel_t) * count);
137153 const auto dict_count = deserializer.ReadProperty<idx_t>(92, "dict_count");
137154 Vector::Deserialize(deserializer, dict_count); // deserialize the dictionary in this vector
137155 Vector::Slice(sel, count); // will create a dictionary vector
137156 return;
137157 } else if (vtype == VectorType::SEQUENCE_VECTOR) {
137158 const int64_t seq_start = deserializer.ReadProperty<int64_t>(91, "seq_start");
137159 const int64_t seq_increment = deserializer.ReadProperty<int64_t>(92, "seq_increment");
137160 Vector::Sequence(seq_start, seq_increment, count);
137161 return;
137162 }
137163
137164 auto geometry_format = GeometryStorageType::WKB;
137165 if (logical_type.id() == LogicalTypeId::GEOMETRY) {
137166 // Try to read the geometry format, but default to the old SPATIAL format for older versions that did not
137167 // serialize this property
137168 geometry_format = deserializer.ReadPropertyWithExplicitDefault<GeometryStorageType>(
137169 99, "geometry_format", GeometryStorageType::SPATIAL);
137170 }
137171
137172 auto &validity = FlatVector::Validity(*this);
137173 auto validity_count = MaxValue<idx_t>(count, STANDARD_VECTOR_SIZE);
137174 validity.Reset(validity_count);
137175 const auto has_validity_mask = deserializer.ReadProperty<bool>(100, "has_validity_mask");
137176 if (has_validity_mask) {
137177 validity.Initialize(validity_count);
137178 deserializer.ReadProperty(101, "validity", data_ptr_cast(validity.GetData()), validity.ValidityMaskSize(count));
137179 }
137180
137181 if (TypeIsConstantSize(logical_type.InternalType())) {
137182 // constant size type: read fixed amount of data
137183 auto column_size = GetTypeIdSize(logical_type.InternalType()) * count;
137184 auto ptr = make_unsafe_uniq_array_uninitialized<data_t>(column_size);
137185 deserializer.ReadProperty(102, "data", ptr.get(), column_size);
137186
137187 VectorOperations::ReadFromStorage(ptr.get(), count, *this);
137188 } else if (logical_type.id() == LogicalTypeId::GEOMETRY) {
137189 auto blobs = FlatVector::GetData<string_t>(*this);
137190
137191 if (geometry_format == GeometryStorageType::WKB) {
137192 deserializer.ReadList(102, "data", [&](Deserializer::List &list, idx_t i) {
137193 auto geom = list.ReadElement<string>();
137194 if (validity.RowIsValid(i)) {
137195 blobs[i] = StringVector::AddStringOrBlob(*this, geom);
137196 }
137197 });
137198 } else if (geometry_format == GeometryStorageType::SPATIAL) {
137199 // Try to read old SPATIAL format and convert to new GEOMETRY format
137200 deserializer.ReadList(102, "data", [&](Deserializer::List &list, idx_t i) {
137201 auto blob = list.ReadElement<string>();
137202 if (validity.RowIsValid(i)) {
137203 Geometry::FromSpatialGeometry(blob, blobs[i], *this);
137204 }
137205 });
137206 } else {
137207 throw InternalException("Unsupported geometry format in vector serialization");
137208 }
137209
137210 } else {
137211 switch (logical_type.InternalType()) {
137212 case PhysicalType::VARCHAR: {
137213 auto strings = FlatVector::GetData<string_t>(*this);
137214 deserializer.ReadList(102, "data", [&](Deserializer::List &list, idx_t i) {
137215 auto str = list.ReadElement<string>();
137216 if (validity.RowIsValid(i)) {
137217 strings[i] = StringVector::AddStringOrBlob(*this, str);
137218 }
137219 });
137220 break;
137221 }
137222 case PhysicalType::STRUCT: {
137223 auto &entries = StructVector::GetEntries(*this);
137224 // Deserialize entries as a list
137225 deserializer.ReadList(103, "children", [&](Deserializer::List &list, idx_t i) {
137226 list.ReadObject([&](Deserializer &obj) { entries[i]->Deserialize(obj, count); });
137227 });
137228 break;
137229 }
137230 case PhysicalType::LIST: {
137231 // Read the list size
137232 auto list_size = deserializer.ReadProperty<uint64_t>(104, "list_size");
137233 ListVector::Reserve(*this, list_size);
137234 ListVector::SetListSize(*this, list_size);
137235
137236 // Read the entries
137237 auto list_entries = FlatVector::GetData<list_entry_t>(*this);
137238 deserializer.ReadList(105, "entries", [&](Deserializer::List &list, idx_t i) {
137239 list.ReadObject([&](Deserializer &obj) {
137240 list_entries[i].offset = obj.ReadProperty<uint64_t>(100, "offset");
137241 list_entries[i].length = obj.ReadProperty<uint64_t>(101, "length");
137242 });
137243 });
137244
137245 // Read the child vector
137246 deserializer.ReadObject(106, "child", [&](Deserializer &obj) {
137247 auto &child = ListVector::GetEntry(*this);
137248 child.Deserialize(obj, list_size);
137249 });
137250 break;
137251 }
137252 case PhysicalType::ARRAY: {
137253 auto array_size = deserializer.ReadProperty<uint64_t>(103, "array_size");
137254 deserializer.ReadObject(104, "child", [&](Deserializer &obj) {
137255 auto &child = ArrayVector::GetEntry(*this);
137256 child.Deserialize(obj, array_size * count);
137257 });
137258 break;
137259 }
137260 default:
137261 throw InternalException("Unimplemented variable width type for Vector::Deserialize!");
137262 }
137263 }
137264}
DUCKDB_API void Sequence(int64_t start, int64_t increment, idx_t count)
Turn the vector into a sequence vector.
Definition duckdb.cpp:136952
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

◆ GetAllocationSize()

idx_t duckdb::Vector::GetAllocationSize ( idx_t cardinality) const
136582 {
136583 if (!type.IsNested()) {
136584 auto physical_size = GetTypeIdSize(type.InternalType());
136585 return cardinality * physical_size;
136586 }
136587 auto internal_type = type.InternalType();
136588 switch (internal_type) {
136589 case PhysicalType::LIST: {
136590 auto physical_size = GetTypeIdSize(type.InternalType());
136591 auto total_size = physical_size * cardinality;
136592
136593 auto child_cardinality = ListVector::GetListCapacity(*this);
136594 auto &child_entry = ListVector::GetEntry(*this);
136595 total_size += (child_entry.GetAllocationSize(child_cardinality));
136596 return total_size;
136597 }
136598 case PhysicalType::ARRAY: {
136599 auto child_cardinality = ArrayVector::GetTotalSize(*this);
136600
136601 auto &child_entry = ArrayVector::GetEntry(*this);
136602 auto total_size = (child_entry.GetAllocationSize(child_cardinality));
136603 return total_size;
136604 }
136605 case PhysicalType::STRUCT: {
136606 idx_t total_size = 0;
136607 auto &children = StructVector::GetEntries(*this);
136608 for (auto &child : children) {
136609 total_size += child->GetAllocationSize(cardinality);
136610 }
136611 return total_size;
136612 }
136613 default:
136614 throw NotImplementedException("Vector::GetAllocationSize not implemented for type: %s", type.ToString());
136615 }
136616}
static DUCKDB_API idx_t GetListCapacity(const Vector &vector)
Gets the total capacity of the underlying child-vector of a list.
Definition duckdb.cpp:138230

◆ GetVectorType()

VectorType duckdb::Vector::GetVectorType ( ) const
inline
10728 {
10729 return vector_type;
10730 }

◆ GetType()

const LogicalType & duckdb::Vector::GetType ( ) const
inline
10731 {
10732 return type;
10733 }

◆ GetData()

data_ptr_t duckdb::Vector::GetData ( ) const
inline
10734 {
10735 return data;
10736 }

◆ GetAuxiliary()

buffer_ptr< VectorBuffer > duckdb::Vector::GetAuxiliary ( )
inline
10738 {
10739 return auxiliary;
10740 }

◆ GetBuffer()

buffer_ptr< VectorBuffer > duckdb::Vector::GetBuffer ( )
inline
10742 {
10743 return buffer;
10744 }

◆ SetVectorType()

void duckdb::Vector::SetVectorType ( VectorType vector_type)
137266 {
137267 vector_type = vector_type_p;
137268 auto physical_type = GetType().InternalType();
137269 auto flat_or_const = GetVectorType() == VectorType::CONSTANT_VECTOR || GetVectorType() == VectorType::FLAT_VECTOR;
137270 if (TypeIsConstantSize(physical_type) && flat_or_const) {
137271 auxiliary.reset();
137272 }
137273 if (vector_type == VectorType::CONSTANT_VECTOR && physical_type == PhysicalType::STRUCT) {
137274 auto &entries = StructVector::GetEntries(*this);
137275 for (auto &entry : entries) {
137276 entry->SetVectorType(vector_type);
137277 }
137278 }
137279}

◆ DebugTransformToDictionary()

void duckdb::Vector::DebugTransformToDictionary ( Vector & vector,
idx_t count )
static
137594 {
137595 if (vector.GetVectorType() != VectorType::FLAT_VECTOR) {
137596 // only supported for flat vectors currently
137597 return;
137598 }
137599 // convert vector to dictionary vector
137600 // first create an inverted vector of twice the size with NULL values every other value
137601 // i.e. [1, 2, 3] is converted into [NULL, 3, NULL, 2, NULL, 1]
137602 idx_t verify_count = count * 2;
137603 SelectionVector inverted_sel(verify_count);
137604 idx_t offset = 0;
137605 for (idx_t i = 0; i < count; i++) {
137606 idx_t current_index = count - i - 1;
137607 inverted_sel.set_index(offset++, current_index);
137608 inverted_sel.set_index(offset++, current_index);
137609 }
137610 auto reusable_dict = DictionaryVector::CreateReusableDictionary(vector.type, verify_count);
137611 auto &inverted_vector = reusable_dict->data;
137612 inverted_vector.Slice(vector, inverted_sel, verify_count);
137613 inverted_vector.Flatten(verify_count);
137614 // now insert the NULL values at every other position
137615 for (idx_t i = 0; i < count; i++) {
137616 FlatVector::SetNull(inverted_vector, i * 2, true);
137617 }
137618 // construct the selection vector pointing towards the original values
137619 // we start at the back, (verify_count - 1) and move backwards
137620 SelectionVector original_sel(count);
137621 offset = 0;
137622 for (idx_t i = 0; i < count; i++) {
137623 original_sel.set_index(offset++, verify_count - 1 - i * 2);
137624 }
137625 // now slice the inverted vector with the inverted selection vector
137626 if (vector.GetType().InternalType() == PhysicalType::STRUCT) {
137627 // Reusable dictionary API does not work for STRUCT
137628 vector.Dictionary(inverted_vector, verify_count, original_sel, count);
137629 vector.buffer->Cast<DictionaryBuffer>().SetDictionaryId(reusable_dict->id);
137630 } else {
137631 vector.Dictionary(reusable_dict, original_sel);
137632 }
137633 vector.Verify(count);
137634}

◆ DebugShuffleNestedVector()

void duckdb::Vector::DebugShuffleNestedVector ( Vector & vector,
idx_t count )
static
137636 {
137637 switch (vector.GetType().id()) {
137638 case LogicalTypeId::STRUCT: {
137639 auto &entries = StructVector::GetEntries(vector);
137640 // recurse into child elements
137641 for (auto &entry : entries) {
137642 Vector::DebugShuffleNestedVector(*entry, count);
137643 }
137644 break;
137645 }
137646 case LogicalTypeId::LIST: {
137647 if (vector.GetVectorType() != VectorType::FLAT_VECTOR) {
137648 break;
137649 }
137650 auto list_entries = FlatVector::GetData<list_entry_t>(vector);
137651 idx_t child_count = 0;
137652 for (idx_t r = 0; r < count; r++) {
137653 if (FlatVector::IsNull(vector, r)) {
137654 continue;
137655 }
137656 child_count += list_entries[r].length;
137657 }
137658 if (child_count == 0) {
137659 break;
137660 }
137661 auto &child_vector = ListVector::GetEntry(vector);
137662 // reverse the order of all lists
137663 SelectionVector child_sel(child_count);
137664 idx_t position = child_count;
137665 for (idx_t r = 0; r < count; r++) {
137666 if (FlatVector::IsNull(vector, r)) {
137667 continue;
137668 }
137669 // move this list to the back
137670 position -= list_entries[r].length;
137671 for (idx_t k = 0; k < list_entries[r].length; k++) {
137672 child_sel.set_index(position + k, list_entries[r].offset + k);
137673 }
137674 // adjust the offset to this new position
137675 list_entries[r].offset = position;
137676 }
137677 child_vector.Slice(child_sel, child_count);
137678 child_vector.Flatten(child_count);
137679 ListVector::SetListSize(vector, child_count);
137680
137681 // recurse into child elements
137682 Vector::DebugShuffleNestedVector(child_vector, child_count);
137683 break;
137684 }
137685 default:
137686 break;
137687 }
137688}

◆ GetValue() [2/2]

Value duckdb::Vector::GetValue ( const Vector & v,
idx_t index )
staticprivate

Returns the [index] element of the Vector as a Value.

136503 {
136504 auto value = GetValueInternal(v_p, index_p);
136505 // set the alias of the type to the correct value, if there is a type alias
136506 if (v_p.GetType().HasAlias()) {
136507 value.GetTypeMutable().CopyAuxInfo(v_p.GetType());
136508 }
136509 if (v_p.GetType().id() != LogicalTypeId::AGGREGATE_STATE && value.type().id() != LogicalTypeId::AGGREGATE_STATE) {
136510 D_ASSERT(v_p.GetType() == value.type());
136511 }
136512 return value;
136513}
static Value GetValueInternal(const Vector &v, idx_t index)
Returns the [index] element of the Vector as a Value.
Definition duckdb.cpp:136265
Here is the call graph for this function:

◆ GetValueInternal()

Value duckdb::Vector::GetValueInternal ( const Vector & v,
idx_t index )
staticprivate

Returns the [index] element of the Vector as a Value.

136265 {
136266 const Vector *vector = &v_p;
136267 idx_t index = index_p;
136268 bool finished = false;
136269 while (!finished) {
136270 switch (vector->GetVectorType()) {
136271 case VectorType::CONSTANT_VECTOR:
136272 index = 0;
136273 finished = true;
136274 break;
136275 case VectorType::FLAT_VECTOR:
136276 finished = true;
136277 break;
136278 case VectorType::FSST_VECTOR:
136279 finished = true;
136280 break;
136281 // dictionary: apply dictionary and forward to child
136282 case VectorType::DICTIONARY_VECTOR: {
136283 auto &sel_vector = DictionaryVector::SelVector(*vector);
136284 auto &child = DictionaryVector::Child(*vector);
136285 vector = &child;
136286 index = sel_vector.get_index(index);
136287 break;
136288 }
136289 case VectorType::SEQUENCE_VECTOR: {
136290 int64_t start, increment;
136291 SequenceVector::GetSequence(*vector, start, increment);
136292 return Value::Numeric(vector->GetType(),
136293 start + static_cast<int64_t>(static_cast<uint64_t>(increment) * index));
136294 }
136295 default:
136296 throw InternalException("Unimplemented vector type for Vector::GetValue");
136297 }
136298 }
136299 auto data = vector->data;
136300 auto &validity = vector->validity;
136301 auto &type = vector->GetType();
136302
136303 if (!validity.RowIsValid(index)) {
136304 return Value(vector->GetType());
136305 }
136306
136307 if (vector->GetVectorType() == VectorType::FSST_VECTOR) {
136308 if (vector->GetType().InternalType() != PhysicalType::VARCHAR) {
136309 throw InternalException("FSST Vector with non-string datatype found!");
136310 }
136311 auto str_compressed = reinterpret_cast<string_t *>(data)[index];
136312 auto decoder = FSSTVector::GetDecoder(*vector);
136313 auto &decompress_buffer = FSSTVector::GetDecompressBuffer(*vector);
136314 auto string_val = FSSTPrimitives::DecompressValue(decoder, str_compressed.GetData(), str_compressed.GetSize(),
136315 decompress_buffer);
136316 switch (vector->GetType().id()) {
136317 case LogicalTypeId::VARCHAR:
136318 return Value(std::move(string_val));
136319 case LogicalTypeId::BLOB:
136320 return Value::BLOB_RAW(string_val);
136321 default:
136322 throw InternalException("Unsupported vector type for FSST vector");
136323 }
136324 }
136325
136326 switch (vector->GetType().id()) {
136327 case LogicalTypeId::BOOLEAN:
136328 return Value::BOOLEAN(reinterpret_cast<bool *>(data)[index]);
136329 case LogicalTypeId::TINYINT:
136330 return Value::TINYINT(reinterpret_cast<int8_t *>(data)[index]);
136331 case LogicalTypeId::SMALLINT:
136332 return Value::SMALLINT(reinterpret_cast<int16_t *>(data)[index]);
136333 case LogicalTypeId::INTEGER:
136334 return Value::INTEGER(reinterpret_cast<int32_t *>(data)[index]);
136335 case LogicalTypeId::DATE:
136336 return Value::DATE(reinterpret_cast<date_t *>(data)[index]);
136337 case LogicalTypeId::TIME:
136338 return Value::TIME(reinterpret_cast<dtime_t *>(data)[index]);
136339 case LogicalTypeId::TIME_NS:
136340 return Value::TIME_NS(reinterpret_cast<dtime_ns_t *>(data)[index]);
136341 case LogicalTypeId::TIME_TZ:
136342 return Value::TIMETZ(reinterpret_cast<dtime_tz_t *>(data)[index]);
136343 case LogicalTypeId::BIGINT:
136344 return Value::BIGINT(reinterpret_cast<int64_t *>(data)[index]);
136345 case LogicalTypeId::UTINYINT:
136346 return Value::UTINYINT(reinterpret_cast<uint8_t *>(data)[index]);
136347 case LogicalTypeId::USMALLINT:
136348 return Value::USMALLINT(reinterpret_cast<uint16_t *>(data)[index]);
136349 case LogicalTypeId::UINTEGER:
136350 return Value::UINTEGER(reinterpret_cast<uint32_t *>(data)[index]);
136351 case LogicalTypeId::UBIGINT:
136352 return Value::UBIGINT(reinterpret_cast<uint64_t *>(data)[index]);
136353 case LogicalTypeId::TIMESTAMP:
136354 return Value::TIMESTAMP(reinterpret_cast<timestamp_t *>(data)[index]);
136356 return Value::TIMESTAMPNS(reinterpret_cast<timestamp_ns_t *>(data)[index]);
136357 case LogicalTypeId::TIMESTAMP_MS:
136358 return Value::TIMESTAMPMS(reinterpret_cast<timestamp_ms_t *>(data)[index]);
136359 case LogicalTypeId::TIMESTAMP_SEC:
136360 return Value::TIMESTAMPSEC(reinterpret_cast<timestamp_sec_t *>(data)[index]);
136361 case LogicalTypeId::TIMESTAMP_TZ:
136362 return Value::TIMESTAMPTZ(reinterpret_cast<timestamp_tz_t *>(data)[index]);
136363 case LogicalTypeId::HUGEINT:
136364 return Value::HUGEINT(reinterpret_cast<hugeint_t *>(data)[index]);
136365 case LogicalTypeId::UHUGEINT:
136366 return Value::UHUGEINT(reinterpret_cast<uhugeint_t *>(data)[index]);
136367 case LogicalTypeId::UUID:
136368 return Value::UUID(reinterpret_cast<hugeint_t *>(data)[index]);
136369 case LogicalTypeId::DECIMAL: {
136370 auto width = DecimalType::GetWidth(type);
136371 auto scale = DecimalType::GetScale(type);
136372 switch (type.InternalType()) {
136373 case PhysicalType::INT16:
136374 return Value::DECIMAL(reinterpret_cast<int16_t *>(data)[index], width, scale);
136375 case PhysicalType::INT32:
136376 return Value::DECIMAL(reinterpret_cast<int32_t *>(data)[index], width, scale);
136377 case PhysicalType::INT64:
136378 return Value::DECIMAL(reinterpret_cast<int64_t *>(data)[index], width, scale);
136379 case PhysicalType::INT128:
136380 return Value::DECIMAL(reinterpret_cast<hugeint_t *>(data)[index], width, scale);
136381 default:
136382 throw InternalException("Physical type '%s' has a width bigger than 38, which is not supported",
136383 TypeIdToString(type.InternalType()));
136384 }
136385 }
136386 case LogicalTypeId::ENUM: {
136387 switch (type.InternalType()) {
136388 case PhysicalType::UINT8:
136389 return Value::ENUM(reinterpret_cast<uint8_t *>(data)[index], type);
136391 return Value::ENUM(reinterpret_cast<uint16_t *>(data)[index], type);
136393 return Value::ENUM(reinterpret_cast<uint32_t *>(data)[index], type);
136394 default:
136395 throw InternalException("ENUM can only have unsigned integers as physical types");
136396 }
136397 }
136398 case LogicalTypeId::POINTER:
136399 return Value::POINTER(reinterpret_cast<uintptr_t *>(data)[index]);
136400 case LogicalTypeId::FLOAT:
136401 return Value::FLOAT(reinterpret_cast<float *>(data)[index]);
136402 case LogicalTypeId::DOUBLE:
136403 return Value::DOUBLE(reinterpret_cast<double *>(data)[index]);
136404 case LogicalTypeId::INTERVAL:
136405 return Value::INTERVAL(reinterpret_cast<interval_t *>(data)[index]);
136406 case LogicalTypeId::VARCHAR: {
136407 auto str = reinterpret_cast<string_t *>(data)[index];
136408 return Value(str.GetString());
136409 }
136410 case LogicalTypeId::BLOB: {
136411 auto str = reinterpret_cast<string_t *>(data)[index];
136412 return Value::BLOB(const_data_ptr_cast(str.GetData()), str.GetSize());
136413 }
136414 case LogicalTypeId::BIGNUM: {
136415 auto str = reinterpret_cast<bignum_t *>(data)[index];
136416 return Value::BIGNUM(const_data_ptr_cast(str.data.GetData()), str.data.GetSize());
136417 }
136418 case LogicalTypeId::GEOMETRY: {
136419 auto str = reinterpret_cast<string_t *>(data)[index];
136420 if (GeoType::HasCRS(type)) {
136421 return Value::GEOMETRY(const_data_ptr_cast(str.GetData()), str.GetSize(), GeoType::GetCRS(type));
136422 }
136423 return Value::GEOMETRY(const_data_ptr_cast(str.GetData()), str.GetSize());
136424 }
136425 case LogicalTypeId::AGGREGATE_STATE: {
136426 auto str = reinterpret_cast<string_t *>(data)[index];
136427 return Value::AGGREGATE_STATE(vector->GetType(), const_data_ptr_cast(str.GetData()), str.GetSize());
136428 }
136429 case LogicalTypeId::BIT: {
136430 auto str = reinterpret_cast<string_t *>(data)[index];
136431 return Value::BIT(const_data_ptr_cast(str.GetData()), str.GetSize());
136432 }
136433 case LogicalTypeId::SQLNULL: {
136434 return Value();
136435 }
136436 case LogicalTypeId::MAP: {
136437 auto offlen = reinterpret_cast<list_entry_t *>(data)[index];
136438 auto &child_vec = ListVector::GetEntry(*vector);
136439 duckdb::vector<Value> children;
136440 for (idx_t i = offlen.offset; i < offlen.offset + offlen.length; i++) {
136441 children.push_back(child_vec.GetValue(i));
136442 }
136443 return Value::MAP(ListType::GetChildType(type), std::move(children));
136444 }
136445 case LogicalTypeId::UNION: {
136446 // Remember to pass the original index_p here so we dont slice twice when looking up the tag
136447 // in case this is a dictionary vector
136448 union_tag_t tag;
136449 if (UnionVector::TryGetTag(*vector, index_p, tag)) {
136450 auto value = UnionVector::GetMember(*vector, tag).GetValue(index_p);
136451 auto members = UnionType::CopyMemberTypes(type);
136452 return Value::UNION(members, tag, std::move(value));
136453 } else {
136454 return Value(vector->GetType());
136455 }
136456 }
136457 case LogicalTypeId::VARIANT: {
136458 duckdb::vector<Value> children;
136459 children.emplace_back(VariantVector::GetKeys(*vector).GetValue(index_p));
136460 children.emplace_back(VariantVector::GetChildren(*vector).GetValue(index_p));
136461 children.emplace_back(VariantVector::GetValues(*vector).GetValue(index_p));
136462 children.emplace_back(VariantVector::GetData(*vector).GetValue(index_p));
136463 return Value::VARIANT(children);
136464 }
136465 case LogicalTypeId::STRUCT: {
136466 // we can derive the value schema from the vector schema
136467 auto &child_entries = StructVector::GetEntries(*vector);
136468 duckdb::vector<Value> children;
136469 for (idx_t child_idx = 0; child_idx < child_entries.size(); child_idx++) {
136470 auto &struct_child = child_entries[child_idx];
136471 children.push_back(struct_child->GetValue(index_p));
136472 }
136473 return Value::STRUCT(type, std::move(children));
136474 }
136475 case LogicalTypeId::LIST: {
136476 auto offlen = reinterpret_cast<list_entry_t *>(data)[index];
136477 auto &child_vec = ListVector::GetEntry(*vector);
136478 duckdb::vector<Value> children;
136479 for (idx_t i = offlen.offset; i < offlen.offset + offlen.length; i++) {
136480 children.push_back(child_vec.GetValue(i));
136481 }
136482 return Value::LIST(ListType::GetChildType(type), std::move(children));
136483 }
136484 case LogicalTypeId::ARRAY: {
136485 auto stride = ArrayType::GetSize(type);
136486 auto offset = index * stride;
136487 auto &child_vec = ArrayVector::GetEntry(*vector);
136488 duckdb::vector<Value> children;
136489 for (idx_t i = offset; i < offset + stride; i++) {
136490 children.push_back(child_vec.GetValue(i));
136491 }
136492 return Value::ARRAY(ArrayType::GetChildType(type), std::move(children));
136493 }
136494 case LogicalTypeId::TYPE: {
136495 auto blob = reinterpret_cast<string_t *>(data)[index];
136496 return Value::TYPE(blob);
136497 }
136498 default:
136499 throw InternalException("Unimplemented type for value access");
136500 }
136501}
static DUCKDB_API Value UNION(child_list_t< LogicalType > members, uint8_t tag, Value value)
Create a union value from a selected value and a tag from a set of alternatives.
Definition duckdb.cpp:132530
static DUCKDB_API Value INTEGER(int32_t value)
Create an integer Value from a specified value.
Definition duckdb.cpp:132139
static DUCKDB_API Value HUGEINT(hugeint_t value)
Create a hugeint Value from a specified value.
Definition duckdb.cpp:132153
static DUCKDB_API Value SMALLINT(int16_t value)
Create a smallint Value from a specified value.
Definition duckdb.cpp:132132
static DUCKDB_API Value BLOB(const_data_ptr_t data, idx_t len)
Create a blob Value from a data pointer and a length: no bytes are interpreted.
Definition duckdb.cpp:132586
static DUCKDB_API Value AGGREGATE_STATE(const LogicalType &type, const_data_ptr_t data, idx_t len)
Creates an aggregate state.
Definition duckdb.cpp:132648
static DUCKDB_API Value MAP(const LogicalType &child_type, vector< Value > values)
Create a map value with the given entries.
Definition duckdb.cpp:132466
static DUCKDB_API Value BOOLEAN(bool value)
Create a boolean Value from a specified value.
Definition duckdb.cpp:132118
static DUCKDB_API Value TIME(dtime_t time)
Create a time Value from a specified time.
Definition duckdb.cpp:132349
static DUCKDB_API Value TIMESTAMPNS(timestamp_ns_t timestamp)
Create a timestamp_ns Value from a specified value.
Definition duckdb.cpp:132395
static DUCKDB_API Value TIMESTAMP(date_t date, dtime_t time)
Create a timestamp Value from a specified date/time combination.
Definition duckdb.cpp:132409
static DUCKDB_API Value BIGINT(int64_t value)
Create a bigint Value from a specified value.
Definition duckdb.cpp:132146
static DUCKDB_API Value DOUBLE(double value)
Create a double Value from a specified value.
Definition duckdb.cpp:132317
static DUCKDB_API Value UHUGEINT(uhugeint_t value)
Create a uhugeint Value from a specified value.
Definition duckdb.cpp:132160
static DUCKDB_API Value POINTER(uintptr_t value)
Create a pointer Value from a specified value.
Definition duckdb.cpp:132331
static DUCKDB_API Value VARIANT(vector< Value > children)
Create a variant value with given list of internal variant data (keys/children/values/data).
Definition duckdb.cpp:132444
static DUCKDB_API Value USMALLINT(uint16_t value)
Create an unsigned smallint Value from a specified value.
Definition duckdb.cpp:132188
static DUCKDB_API Value UINTEGER(uint32_t value)
Create an unsigned integer Value from a specified value.
Definition duckdb.cpp:132195
static DUCKDB_API Value Numeric(const LogicalType &type, int64_t value)
Create a Numeric value of the specified type with the specified value.
Definition duckdb.cpp:133053
static DUCKDB_API Value BIT(const_data_ptr_t data, idx_t len)
Creates a bitstring by casting a specified string to a bitstring.
Definition duckdb.cpp:132655
static DUCKDB_API Value TIMESTAMPTZ(timestamp_tz_t timestamp)
Create a timestamp_tz Value from a specified value.
Definition duckdb.cpp:132402
static DUCKDB_API Value LIST(const LogicalType &child_type, vector< Value > values)
Create a list value with the given entries.
Definition duckdb.cpp:132555
static DUCKDB_API Value STRUCT(child_list_t< Value > values)
Create a struct value with given list of entries.
Definition duckdb.cpp:132434
static DUCKDB_API Value TIMESTAMPMS(timestamp_ms_t timestamp)
Create a timestamp_ms Value from a specified value.
Definition duckdb.cpp:132388
static DUCKDB_API Value UTINYINT(uint8_t value)
Create an unsigned tinyint Value from a specified value.
Definition duckdb.cpp:132181
static DUCKDB_API Value FLOAT(float value)
Create a float Value from a specified value.
Definition duckdb.cpp:132310
static DUCKDB_API Value TIMESTAMPSEC(timestamp_sec_t timestamp)
Create a timestamp_s Value from a specified value.
Definition duckdb.cpp:132381
static DUCKDB_API Value UUID(const string &value)
Create a uuid Value from a specified value.
Definition duckdb.cpp:132174
static DUCKDB_API Value DATE(date_t date)
Create a date Value from a specified date.
Definition duckdb.cpp:132338
static DUCKDB_API Value TINYINT(int8_t value)
Create a tinyint Value from a specified value.
Definition duckdb.cpp:132125
static DUCKDB_API Value UBIGINT(uint64_t value)
Create an unsigned bigint Value from a specified value.
Definition duckdb.cpp:132202
void scale(cv::Mat &mat, const cv::Mat &range, const T min, const T max)
@ TIMESTAMP_NS
us
Definition duckdb.hpp:2886
static DUCKDB_API bool TryGetTag(const Vector &vector, idx_t index, union_tag_t &tag)
Definition duckdb.cpp:138451
static DUCKDB_API const Vector & GetMember(const Vector &vector, idx_t member_index)
Get the member vector of a union vector by index.
Definition duckdb.cpp:138372
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:

Member Data Documentation

◆ vector_type

VectorType duckdb::Vector::vector_type
protected

The vector type specifies how the data of the vector is physically stored (i.e. if it is a single repeated constant, if it is compressed)

◆ auxiliary

buffer_ptr<VectorBuffer> duckdb::Vector::auxiliary
protected

The buffer holding auxiliary data of the vector e.g. a string vector uses this to store strings


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