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

Static Public Member Functions

static bool AllowImplicitCastFromStruct (const LogicalType &source, const LogicalType &target)
static bool Cast (Vector &source, Vector &result, idx_t count, CastParameters &parameters)
static unique_ptr< BoundCastData > BindData (BindCastInput &input, const LogicalType &source, const LogicalType &target)
static BoundCastInfo Bind (BindCastInput &input, const LogicalType &source, const LogicalType &target)

Member Function Documentation

◆ AllowImplicitCastFromStruct()

bool duckdb::StructToUnionCast::AllowImplicitCastFromStruct ( const LogicalType & source,
const LogicalType & target )
static
215785 {
215786 if (source.id() != LogicalTypeId::STRUCT) {
215787 return false;
215788 }
215789 auto target_fields = StructType::GetChildTypes(target);
215790 auto fields = StructType::GetChildTypes(source);
215791 if (target_fields.size() != fields.size()) {
215792 // Struct should have the same amount of fields as the union
215793 return false;
215794 }
215795 for (idx_t i = 0; i < target_fields.size(); i++) {
215796 auto &target_field = target_fields[i].second;
215797 auto &target_field_name = target_fields[i].first;
215798 auto &field = fields[i].second;
215799 auto &field_name = fields[i].first;
215800 if (i == 0) {
215801 // For the tag field we don't accept a type substitute as varchar
215802 if (target_field != field) {
215803 return false;
215804 }
215805 continue;
215806 }
215807 if (!StringUtil::CIEquals(target_field_name, field_name)) {
215808 return false;
215809 }
215810 if (target_field != field && field != LogicalType::VARCHAR) {
215811 // We allow the field to be VARCHAR, since unsupported types get cast to VARCHAR by EXPORT DATABASE (format
215812 // PARQUET) i.e UNION(a BIT) becomes STRUCT(a VARCHAR)
215813 return false;
215814 }
215815 }
215816 return true;
215817}
static DUCKDB_API bool CIEquals(const string &l1, const string &l2)
Case insensitive equals.
Definition duckdb.cpp:109696
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Cast()

bool duckdb::StructToUnionCast::Cast ( Vector & source,
Vector & result,
idx_t count,
CastParameters & parameters )
static
215821 {
215822 auto &cast_data = parameters.cast_data->Cast<StructBoundCastData>();
215823 auto &lstate = parameters.local_state->Cast<StructCastLocalState>();
215824
215825 D_ASSERT(source.GetType().id() == LogicalTypeId::STRUCT);
215826 D_ASSERT(result.GetType().id() == LogicalTypeId::UNION);
215827 D_ASSERT(cast_data.target.id() == LogicalTypeId::UNION);
215828
215829 auto &source_children = StructVector::GetEntries(source);
215830 auto &target_children = StructVector::GetEntries(result);
215831
215832 for (idx_t i = 0; i < source_children.size(); i++) {
215833 auto &result_child_vector = *target_children[i];
215834 auto &source_child_vector = *source_children[i];
215835 CastParameters child_parameters(parameters, cast_data.child_cast_info[i].cast_data, lstate.local_states[i]);
215836 auto converted =
215837 cast_data.child_cast_info[i].function(source_child_vector, result_child_vector, count, child_parameters);
215838 (void)converted;
215839 D_ASSERT(converted);
215840 // we flatten the child because we use FlatVector::SetNull below and we may get non-flat from source/cast
215841 result_child_vector.Flatten(count);
215842 }
215843
215844 if (source.GetVectorType() == VectorType::CONSTANT_VECTOR) {
215845 result.SetVectorType(VectorType::CONSTANT_VECTOR);
215846 ConstantVector::SetNull(result, ConstantVector::IsNull(source));
215847
215848 // if the tag is NULL, the union should be NULL
215849 auto &tag_vec = *target_children[0];
215850 ConstantVector::SetNull(result, ConstantVector::IsNull(tag_vec));
215851 } else {
215852 // if the tag is NULL, the union should be NULL
215853 auto &tag_vec = *target_children[0];
215854 UnifiedVectorFormat source_data, tag_data;
215855 source.ToUnifiedFormat(count, source_data);
215856 tag_vec.ToUnifiedFormat(count, tag_data);
215857
215858 for (idx_t i = 0; i < count; i++) {
215859 if (!source_data.validity.RowIsValid(source_data.sel->get_index(i)) ||
215860 !tag_data.validity.RowIsValid(tag_data.sel->get_index(i))) {
215861 FlatVector::SetNull(result, i, true);
215862 }
215863 }
215864 }
215865
215866 auto check_tags = UnionVector::CheckUnionValidity(result, count);
215867 switch (check_tags) {
215868 case UnionInvalidReason::TAG_OUT_OF_RANGE:
215869 throw ConversionException("One or more of the tags do not point to a valid union member");
215870 case UnionInvalidReason::VALIDITY_OVERLAP:
215871 throw ConversionException("One or more rows in the produced UNION have validity set for more than 1 member");
215872 case UnionInvalidReason::TAG_MISMATCH:
215873 throw ConversionException(
215874 "One or more rows in the produced UNION have tags that don't point to the valid member");
215875 case UnionInvalidReason::NULL_TAG:
215876 throw ConversionException("One or more rows in the produced UNION have a NULL tag");
215877 case UnionInvalidReason::VALID:
215878 break;
215879 default:
215880 throw InternalException("Struct to union cast failed for unknown reason");
215881 }
215882
215883 result.Verify(count);
215884 return true;
215885}
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

◆ BindData()

unique_ptr< BoundCastData > duckdb::StructToUnionCast::BindData ( BindCastInput & input,
const LogicalType & source,
const LogicalType & target )
static
215890 {
215891 vector<BoundCastInfo> child_cast_info;
215892 D_ASSERT(source.id() == LogicalTypeId::STRUCT);
215893 D_ASSERT(target.id() == LogicalTypeId::UNION);
215894
215895 auto result_child_count = StructType::GetChildCount(target);
215896 D_ASSERT(result_child_count == StructType::GetChildCount(source));
215897
215898 for (idx_t i = 0; i < result_child_count; i++) {
215899 auto &source_child = StructType::GetChildType(source, i);
215900 auto &target_child = StructType::GetChildType(target, i);
215901
215902 auto child_cast = input.GetCastFunction(source_child, target_child);
215903 child_cast_info.push_back(std::move(child_cast));
215904 }
215905 return make_uniq<StructBoundCastData>(std::move(child_cast_info), target);
215906}

◆ Bind()

BoundCastInfo duckdb::StructToUnionCast::Bind ( BindCastInput & input,
const LogicalType & source,
const LogicalType & target )
static
215908 {
215909 auto cast_data = StructToUnionCast::BindData(input, source, target);
215910 return BoundCastInfo(&StructToUnionCast::Cast, std::move(cast_data), StructBoundCastData::InitStructCastLocalState);
215911}

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