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::UnionVector Struct Reference

Static Public Member Functions

static DUCKDB_API const Vector & GetTags (const Vector &v)
 Get the tag vector of a union vector.
static DUCKDB_API Vector & GetTags (Vector &v)
static DUCKDB_API bool TryGetTag (const Vector &vector, idx_t index, union_tag_t &tag)
static DUCKDB_API const Vector & GetMember (const Vector &vector, idx_t member_index)
 Get the member vector of a union vector by index.
static DUCKDB_API Vector & GetMember (Vector &vector, idx_t member_index)
static DUCKDB_API void SetToMember (Vector &vector, union_tag_t tag, Vector &member_vector, idx_t count, bool keep_tags_for_null)
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).

Member Function Documentation

◆ GetTags() [1/2]

const Vector & duckdb::UnionVector::GetTags ( const Vector & v)
static

Get the tag vector of a union vector.

138384 {
138385 // the tag vector is always the first struct child.
138386 return *StructVector::GetEntries(vector)[0];
138387}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTags() [2/2]

Vector & duckdb::UnionVector::GetTags ( Vector & v)
static
138389 {
138390 // the tag vector is always the first struct child.
138391 return *StructVector::GetEntries(vector)[0];
138392}

◆ TryGetTag()

bool duckdb::UnionVector::TryGetTag ( const Vector & vector,
idx_t index,
union_tag_t & tag )
static

Try to get the tag at the specific flat index of the union vector. Returns false if the tag is NULL. This will handle and map the index properly for constant and dictionary vectors internally.

138451 {
138452 // the tag vector is always the first struct child.
138453 auto &tag_vector = *StructVector::GetEntries(vector)[0];
138454 if (tag_vector.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
138455 auto &child = DictionaryVector::Child(tag_vector);
138456 auto &dict_sel = DictionaryVector::SelVector(tag_vector);
138457 auto mapped_idx = dict_sel.get_index(index);
138458 if (FlatVector::IsNull(child, mapped_idx)) {
138459 return false;
138460 } else {
138461 result = FlatVector::GetData<union_tag_t>(child)[mapped_idx];
138462 return true;
138463 }
138464 }
138465 if (tag_vector.GetVectorType() == VectorType::CONSTANT_VECTOR) {
138466 if (ConstantVector::IsNull(tag_vector)) {
138467 return false;
138468 } else {
138469 result = ConstantVector::GetData<union_tag_t>(tag_vector)[0];
138470 return true;
138471 }
138472 }
138473 if (FlatVector::IsNull(tag_vector, index)) {
138474 return false;
138475 } else {
138476 result = FlatVector::GetData<union_tag_t>(tag_vector)[index];
138477 return true;
138478 }
138479}
index
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMember() [1/2]

const Vector & duckdb::UnionVector::GetMember ( const Vector & vector,
idx_t member_index )
static

Get the member vector of a union vector by index.

138372 {
138373 D_ASSERT(member_index < UnionType::GetMemberCount(vector.GetType()));
138374 auto &entries = StructVector::GetEntries(vector);
138375 return *entries[member_index + 1]; // skip the "tag" entry
138376}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMember() [2/2]

Vector & duckdb::UnionVector::GetMember ( Vector & vector,
idx_t member_index )
static
138378 {
138379 D_ASSERT(member_index < UnionType::GetMemberCount(vector.GetType()));
138380 auto &entries = StructVector::GetEntries(vector);
138381 return *entries[member_index + 1]; // skip the "tag" entry
138382}

◆ SetToMember()

void duckdb::UnionVector::SetToMember ( Vector & vector,
union_tag_t tag,
Vector & member_vector,
idx_t count,
bool keep_tags_for_null )
static

Set every entry in the UnionVector to a specific member. This is useful to set the entire vector to a single member, e.g. when "creating" a union to return in a function, when you only have one alternative to return. if 'keep_tags_for_null' is false, the tags will be set to NULL where the member is NULL. (the validity of the tag vector will match the selected member vector) otherwise, they are all set to the 'tag'. This will also handle invalidation of the non-selected members

138395 {
138396 D_ASSERT(union_vector.GetType().id() == LogicalTypeId::UNION);
138397 D_ASSERT(tag < UnionType::GetMemberCount(union_vector.GetType()));
138398
138399 // Set the union member to the specified vector
138400 UnionVector::GetMember(union_vector, tag).Reference(member_vector);
138401 auto &tag_vector = UnionVector::GetTags(union_vector);
138402
138403 if (member_vector.GetVectorType() == VectorType::CONSTANT_VECTOR) {
138404 // if the member vector is constant, we can set the union to constant as well
138405 union_vector.SetVectorType(VectorType::CONSTANT_VECTOR);
138406 ConstantVector::GetData<union_tag_t>(tag_vector)[0] = tag;
138407 if (keep_tags_for_null) {
138408 ConstantVector::SetNull(union_vector, false);
138409 ConstantVector::SetNull(tag_vector, false);
138410 } else {
138411 ConstantVector::SetNull(union_vector, ConstantVector::IsNull(member_vector));
138412 ConstantVector::SetNull(tag_vector, ConstantVector::IsNull(member_vector));
138413 }
138414
138415 } else {
138416 // otherwise flatten and set to flatvector
138417 member_vector.Flatten(count);
138418 union_vector.SetVectorType(VectorType::FLAT_VECTOR);
138419
138420 if (member_vector.validity.AllValid()) {
138421 // if the member vector is all valid, we can set the tag to constant
138422 tag_vector.SetVectorType(VectorType::CONSTANT_VECTOR);
138423 auto tag_data = ConstantVector::GetData<union_tag_t>(tag_vector);
138424 *tag_data = tag;
138425 } else {
138426 tag_vector.SetVectorType(VectorType::FLAT_VECTOR);
138427 if (keep_tags_for_null) {
138428 FlatVector::Validity(tag_vector).SetAllValid(count);
138429 FlatVector::Validity(union_vector).SetAllValid(count);
138430 } else {
138431 // ensure the tags have the same validity as the member
138432 FlatVector::Validity(union_vector) = FlatVector::Validity(member_vector);
138433 FlatVector::Validity(tag_vector) = FlatVector::Validity(member_vector);
138434 }
138435
138436 auto tag_data = FlatVector::GetData<union_tag_t>(tag_vector);
138437 memset(tag_data, tag, count);
138438 }
138439 }
138440
138441 // Set the non-selected members to constant null vectors
138442 for (idx_t i = 0; i < UnionType::GetMemberCount(union_vector.GetType()); i++) {
138443 if (i != tag) {
138444 auto &member = UnionVector::GetMember(union_vector, i);
138445 member.SetVectorType(VectorType::CONSTANT_VECTOR);
138446 ConstantVector::SetNull(member, true);
138447 }
138448 }
138449}
DUCKDB_API void Reference(const Value &value)
Create a vector that references the specified value.
Definition duckdb.cpp:135784
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API const Vector & GetTags(const Vector &v)
Get the tag vector of a union vector.
Definition duckdb.cpp:138384
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckUnionValidity()

UnionInvalidReason duckdb::UnionVector::CheckUnionValidity ( Vector & vector,
idx_t count,
const SelectionVector & sel = *FlatVector::IncrementalSelectionVector() )
static

Raw selection vector passed in (not merged with any other selection vectors).

138482 {
138483 D_ASSERT(vector_p.GetType().id() == LogicalTypeId::UNION);
138484
138485 // Will contain the (possibly) merged selection vector
138486 const SelectionVector *sel = &sel_p;
138487 SelectionVector owned_sel;
138488 Vector *vector = &vector_p;
138489 if (vector->GetVectorType() == VectorType::DICTIONARY_VECTOR) {
138490 // In the case of a dictionary vector, unwrap the Vector, and merge the selection vectors.
138491 auto &child = DictionaryVector::Child(*vector);
138492 D_ASSERT(child.GetVectorType() != VectorType::DICTIONARY_VECTOR);
138493 auto &dict_sel = DictionaryVector::SelVector(*vector);
138494 // merge the selection vectors and verify the child
138495 auto new_buffer = dict_sel.Slice(*sel, count);
138496 owned_sel.Initialize(new_buffer);
138497 sel = &owned_sel;
138498 vector = &child;
138499 } else if (vector->GetVectorType() == VectorType::CONSTANT_VECTOR) {
138500 sel = ConstantVector::ZeroSelectionVector(count, owned_sel);
138501 }
138502
138503 auto member_count = UnionType::GetMemberCount(vector_p.GetType());
138504 if (member_count == 0) {
138505 return UnionInvalidReason::NO_MEMBERS;
138506 }
138507
138508 UnifiedVectorFormat vector_vdata;
138509 vector_p.ToUnifiedFormat(count, vector_vdata);
138510
138511 auto &entries = StructVector::GetEntries(vector_p);
138512 duckdb::vector<UnifiedVectorFormat> child_vdata(entries.size());
138513 for (idx_t entry_idx = 0; entry_idx < entries.size(); entry_idx++) {
138514 auto &child = *entries[entry_idx];
138515 child.ToUnifiedFormat(count, child_vdata[entry_idx]);
138516 }
138517
138518 auto &tag_vdata = child_vdata[0];
138519
138520 for (idx_t row_idx = 0; row_idx < count; row_idx++) {
138521 auto mapped_idx = sel->get_index(row_idx);
138522
138523 if (!vector_vdata.validity.RowIsValid(mapped_idx)) {
138524 continue;
138525 }
138526
138527 auto tag_idx = tag_vdata.sel->get_index(sel_p.get_index(row_idx));
138528 if (!tag_vdata.validity.RowIsValid(tag_idx)) {
138529 // we can't have NULL tags!
138530 return UnionInvalidReason::NULL_TAG;
138531 }
138532 auto tag = UnifiedVectorFormat::GetData<union_tag_t>(tag_vdata)[tag_idx];
138533 if (tag >= member_count) {
138534 return UnionInvalidReason::TAG_OUT_OF_RANGE;
138535 }
138536
138537 bool found_valid = false;
138538 for (idx_t i = 0; i < member_count; i++) {
138539 auto &member_vdata = child_vdata[1 + i]; // skip the tag
138540 idx_t member_idx = member_vdata.sel->get_index(sel_p.get_index(row_idx));
138541 if (!member_vdata.validity.RowIsValid(member_idx)) {
138542 continue;
138543 }
138544 if (found_valid) {
138545 return UnionInvalidReason::VALIDITY_OVERLAP;
138546 }
138547 found_valid = true;
138548 if (tag != static_cast<union_tag_t>(i)) {
138549 return UnionInvalidReason::TAG_MISMATCH;
138550 }
138551 }
138552 }
138553
138554 return UnionInvalidReason::VALID;
138555}
Here is the call graph for this function:
Here is the caller graph for this function:

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