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::VariantShredding Struct Referenceabstract

Public Member Functions

virtual void WriteVariantValues (UnifiedVariantVectorData &variant, Vector &result, optional_ptr< const SelectionVector > sel, optional_ptr< const SelectionVector > value_index_sel, optional_ptr< const SelectionVector > result_sel, idx_t count)=0

Static Public Member Functions

static LogicalType GetUnshreddedType ()

Protected Member Functions

void WriteTypedValues (UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel, const SelectionVector &value_index_sel, const SelectionVector &result_sel, idx_t count)
virtual void WriteMissingField (Vector &vector, idx_t index)

Protected Attributes

idx_t typed_value_index = VariantStats::TYPED_VALUE_INDEX
idx_t untyped_value_index = VariantStats::UNTYPED_VALUE_INDEX

Private Member Functions

void WriteTypedObjectValues (UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel, const SelectionVector &value_index_sel, const SelectionVector &result_sel, idx_t count)
void WriteTypedArrayValues (UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel, const SelectionVector &value_index_sel, const SelectionVector &result_sel, idx_t count)
void WriteTypedPrimitiveValues (UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel, const SelectionVector &value_index_sel, const SelectionVector &result_sel, idx_t count)

Constructor & Destructor Documentation

◆ VariantShredding()

duckdb::VariantShredding::VariantShredding ( )
inline
252589 {
252590 }

Member Function Documentation

◆ GetUnshreddedType()

LogicalType duckdb::VariantShredding::GetUnshreddedType ( )
inlinestatic
252594 {
252595 return LogicalType::STRUCT(StructType::GetChildTypes(LogicalType::VARIANT()));
252596 }
static DUCKDB_API LogicalType VARIANT()
Definition duckdb.cpp:140950

◆ WriteTypedValues()

void duckdb::VariantShredding::WriteTypedValues ( UnifiedVariantVectorData & variant,
Vector & result,
const SelectionVector & sel,
const SelectionVector & value_index_sel,
const SelectionVector & result_sel,
idx_t count )
protected

Shredded OBJECT

Shredded ARRAY

Primitive types

252961 {
252962 auto &type = result.GetType();
252963
252964 if (type.id() == LogicalTypeId::STRUCT) {
252966 WriteTypedObjectValues(variant, result, sel, value_index_sel, result_sel, count);
252967 } else if (type.id() == LogicalTypeId::LIST) {
252969 WriteTypedArrayValues(variant, result, sel, value_index_sel, result_sel, count);
252970 } else {
252972 WriteTypedPrimitiveValues(variant, result, sel, value_index_sel, result_sel, count);
252973 }
252974}
void WriteTypedObjectValues(UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel, const SelectionVector &value_index_sel, const SelectionVector &result_sel, idx_t count)
Definition duckdb.cpp:252811
void WriteTypedPrimitiveValues(UnifiedVariantVectorData &variant, Vector &result, const SelectionVector &sel, const SelectionVector &value_index_sel, const SelectionVector &result_sel, idx_t count)
Definition duckdb.cpp:252734
Here is the call graph for this function:

◆ WriteMissingField()

void duckdb::VariantShredding::WriteMissingField ( Vector & vector,
idx_t index )
protectedvirtual
252807 {
252808 FlatVector::GetData<uint32_t>(vector)[index] = 0;
252809}
index

◆ WriteTypedObjectValues()

void duckdb::VariantShredding::WriteTypedObjectValues ( UnifiedVariantVectorData & variant,
Vector & result,
const SelectionVector & sel,
const SelectionVector & value_index_sel,
const SelectionVector & result_sel,
idx_t count )
private

Collect the nested data for the objects

When we're shredding an object, the top-level struct of it should always be valid

Prepare the path component to perform the lookup for

For some of the rows the field is missing, adjust the selection vector to exclude these rows.

The field is missing, set the untyped value index to 0

If not all rows are missing this field, write the values for it

252813 {
252814 auto &type = result.GetType();
252815 D_ASSERT(type.id() == LogicalTypeId::STRUCT);
252816
252817 auto &validity = FlatVector::Validity(result);
252818 (void)validity;
252819
252821 auto nested_data = make_unsafe_uniq_array_uninitialized<VariantNestedData>(count);
252822 for (idx_t i = 0; i < count; i++) {
252823 auto row = sel[i];
252825 D_ASSERT(validity.RowIsValid(result_sel[i]));
252826 auto value_index = value_index_sel[i];
252827 D_ASSERT(variant.GetTypeId(row, value_index) == VariantLogicalType::OBJECT);
252828 nested_data[i] = VariantUtils::DecodeNestedData(variant, row, value_index);
252829 }
252830
252831 auto &shredded_types = StructType::GetChildTypes(type);
252832 auto &shredded_fields = StructVector::GetEntries(result);
252833 D_ASSERT(shredded_types.size() == shredded_fields.size());
252834
252835 SelectionVector child_values_indexes;
252836 SelectionVector child_row_sel;
252837 SelectionVector child_result_sel;
252838 child_values_indexes.Initialize(count);
252839 child_row_sel.Initialize(count);
252840 child_result_sel.Initialize(count);
252841
252842 for (idx_t child_idx = 0; child_idx < shredded_types.size(); child_idx++) {
252843 auto &child_vec = *shredded_fields[child_idx];
252844 D_ASSERT(child_vec.GetType() == shredded_types[child_idx].second);
252845
252847 auto &key = shredded_types[child_idx].first;
252848 VariantPathComponent path_component;
252849 path_component.lookup_mode = VariantChildLookupMode::BY_KEY;
252850 path_component.key = key;
252851
252852 ValidityMask lookup_validity(count);
252853 ValidityMask all_valid_validity(count);
252854 VariantUtils::FindChildValues(variant, path_component, sel, child_values_indexes, lookup_validity,
252855 nested_data.get(), all_valid_validity, count);
252856
252857 if (!lookup_validity.AllValid()) {
252858 optional_ptr<Vector> typed_value_vector;
252859 optional_ptr<Vector> untyped_value_vector;
252860 if (child_vec.GetType().id() == LogicalTypeId::STRUCT) {
252861 // this is a STRUCT(typed_value .., [untyped_value UINT])
252862 auto &child_variant_vectors = StructVector::GetEntries(child_vec);
252863 if (typed_value_index < child_variant_vectors.size()) {
252864 typed_value_vector = child_variant_vectors[typed_value_index];
252865 }
252866 if (untyped_value_index < child_variant_vectors.size()) {
252867 untyped_value_vector = child_variant_vectors[untyped_value_index];
252868 }
252869 } else {
252870 // this is a primitive type
252871 typed_value_vector = child_vec;
252872 }
252873
252875 idx_t child_count = 0;
252876 for (idx_t i = 0; i < count; i++) {
252877 if (!lookup_validity.RowIsValid(i)) {
252879 if (typed_value_vector) {
252880 FlatVector::SetNull(*typed_value_vector, result_sel[i], true);
252881 }
252882 if (!untyped_value_vector) {
252883 throw InternalException("Field is missing but untyped_value_index is not set");
252884 }
252885 WriteMissingField(*untyped_value_vector, result_sel[i]);
252886 continue;
252887 }
252888
252889 child_row_sel[child_count] = sel[i];
252890 child_values_indexes[child_count] = child_values_indexes[i];
252891 child_result_sel[child_count] = result_sel[i];
252892 child_count++;
252893 }
252894
252895 if (child_count) {
252897 WriteVariantValues(variant, child_vec, child_row_sel, child_values_indexes, child_result_sel,
252898 child_count);
252899 }
252900 } else {
252901 WriteVariantValues(variant, child_vec, &sel, child_values_indexes, result_sel, count);
252902 }
252903 }
252904}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API void FindChildValues(const UnifiedVariantVectorData &variant, const VariantPathComponent &component, optional_ptr< const SelectionVector > sel, SelectionVector &res, ValidityMask &res_validity, const VariantNestedData *nested_data, const ValidityMask &validity, idx_t count)
Definition duckdb.cpp:238520
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteTypedArrayValues()

void duckdb::VariantShredding::WriteTypedArrayValues ( UnifiedVariantVectorData & variant,
Vector & result,
const SelectionVector & sel,
const SelectionVector & value_index_sel,
const SelectionVector & result_sel,
idx_t count )
private
252908 {
252909 auto list_data = FlatVector::GetData<list_entry_t>(result);
252910
252911 auto nested_data = make_unsafe_uniq_array_uninitialized<VariantNestedData>(count);
252912
252913 idx_t total_offset = 0;
252914 for (idx_t i = 0; i < count; i++) {
252915 auto row = sel[i];
252916 auto value_index = value_index_sel[i];
252917 auto result_row = result_sel[i];
252918
252919 D_ASSERT(variant.GetTypeId(row, value_index) == VariantLogicalType::ARRAY);
252920 nested_data[i] = VariantUtils::DecodeNestedData(variant, row, value_index);
252921
252922 list_entry_t list_entry;
252923 list_entry.length = nested_data[i].child_count;
252924 list_entry.offset = total_offset;
252925 list_data[result_row] = list_entry;
252926
252927 total_offset += nested_data[i].child_count;
252928 }
252929 ListVector::Reserve(result, total_offset);
252930 ListVector::SetListSize(result, total_offset);
252931
252932 SelectionVector child_sel;
252933 child_sel.Initialize(total_offset);
252934
252935 SelectionVector child_value_index_sel;
252936 child_value_index_sel.Initialize(total_offset);
252937
252938 SelectionVector child_result_sel;
252939 child_result_sel.Initialize(total_offset);
252940
252941 for (idx_t i = 0; i < count; i++) {
252942 auto row = sel[i];
252943 auto result_row = result_sel[i];
252944
252945 auto &array_data = nested_data[i];
252946 auto &entry = list_data[result_row];
252947 for (idx_t j = 0; j < entry.length; j++) {
252948 auto offset = entry.offset + j;
252949 child_sel[offset] = row;
252950 child_value_index_sel[offset] = variant.GetValuesIndex(row, array_data.children_idx + j);
252951 child_result_sel[offset] = NumericCast<uint32_t>(offset);
252952 }
252953 }
252954
252955 auto &child_vector = ListVector::GetEntry(result);
252956 WriteVariantValues(variant, child_vector, child_sel, child_value_index_sel, child_result_sel, total_offset);
252957}
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of a list.
Definition duckdb.cpp:138203
static DUCKDB_API void SetListSize(Vector &vec, idx_t size)
Sets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138248
static DUCKDB_API void Reserve(Vector &vec, idx_t required_capacity)
Sets the total capacity of the underlying child-vector of a list.
Definition duckdb.cpp:138211

◆ WriteTypedPrimitiveValues()

void duckdb::VariantShredding::WriteTypedPrimitiveValues ( UnifiedVariantVectorData & variant,
Vector & result,
const SelectionVector & sel,
const SelectionVector & value_index_sel,
const SelectionVector & result_sel,
idx_t count )
private

DECIMAL2 (doesn't exist in Parquet for some reason)

DECIMAL4

DECIMAL8

DECIMAL16

252736 {
252737 auto &type = result.GetType();
252738 D_ASSERT(!type.IsNested());
252739 switch (type.id()) {
252740 case LogicalTypeId::TINYINT:
252741 case LogicalTypeId::SMALLINT:
252742 case LogicalTypeId::INTEGER:
252743 case LogicalTypeId::BIGINT:
252744 case LogicalTypeId::HUGEINT:
252745 case LogicalTypeId::UTINYINT:
252746 case LogicalTypeId::USMALLINT:
252747 case LogicalTypeId::UINTEGER:
252748 case LogicalTypeId::UBIGINT:
252749 case LogicalTypeId::UHUGEINT:
252750 case LogicalTypeId::FLOAT:
252751 case LogicalTypeId::DOUBLE:
252752 case LogicalTypeId::DATE:
252753 case LogicalTypeId::TIME:
252754 case LogicalTypeId::TIME_NS:
252755 case LogicalTypeId::TIME_TZ:
252756 case LogicalTypeId::TIMESTAMP_TZ:
252757 case LogicalTypeId::TIMESTAMP:
252758 case LogicalTypeId::TIMESTAMP_SEC:
252759 case LogicalTypeId::TIMESTAMP_MS:
252761 case LogicalTypeId::INTERVAL:
252762 case LogicalTypeId::UUID: {
252763 const auto physical_type = type.InternalType();
252764 WriteShreddedPrimitive(variant, result, sel, value_index_sel, result_sel, count, GetTypeIdSize(physical_type));
252765 break;
252766 }
252767 case LogicalTypeId::DECIMAL: {
252768 const auto physical_type = type.InternalType();
252769 switch (physical_type) {
252771 case PhysicalType::INT16:
252772 WriteShreddedDecimal<int16_t>(variant, result, sel, value_index_sel, result_sel, count);
252773 break;
252775 case PhysicalType::INT32:
252776 WriteShreddedDecimal<int32_t>(variant, result, sel, value_index_sel, result_sel, count);
252777 break;
252779 case PhysicalType::INT64:
252780 WriteShreddedDecimal<int64_t>(variant, result, sel, value_index_sel, result_sel, count);
252781 break;
252783 case PhysicalType::INT128:
252784 WriteShreddedDecimal<hugeint_t>(variant, result, sel, value_index_sel, result_sel, count);
252785 break;
252786 default:
252787 throw InvalidInputException("Can't shred on column of type '%s'", type.ToString());
252788 }
252789 break;
252790 }
252791 case LogicalTypeId::BLOB:
252792 case LogicalTypeId::BIGNUM:
252793 case LogicalTypeId::GEOMETRY:
252794 case LogicalTypeId::BIT:
252795 case LogicalTypeId::VARCHAR: {
252796 WriteShreddedString(variant, result, sel, value_index_sel, result_sel, count);
252797 break;
252798 }
252799 case LogicalTypeId::BOOLEAN:
252800 WriteShreddedBoolean(variant, result, sel, value_index_sel, result_sel, count);
252801 break;
252802 default:
252803 throw InvalidInputException("Can't shred on type: %s", type.ToString());
252804 }
252805}
@ TIMESTAMP_NS
us
Definition duckdb.hpp:2886
@ 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
Here is the caller graph for this function:

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