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

Static Public Member Functions

static void SetValidityMask (Vector &vector, ArrowArray &array, idx_t chunk_offset, idx_t size, int64_t parent_offset, int64_t nested_offset, bool add_null=false)
static void ColumnArrowToDuckDBRunEndEncoded (Vector &vector, const ArrowArray &array, idx_t chunk_offset, ArrowArrayScanState &array_state, idx_t size, const ArrowType &arrow_type, int64_t nested_offset=-1, ValidityMask *parent_mask=nullptr, uint64_t parent_offset=0)
static void ColumnArrowToDuckDB (Vector &vector, ArrowArray &array, idx_t chunk_offset, ArrowArrayScanState &array_state, idx_t size, const ArrowType &arrow_type, int64_t nested_offset=-1, ValidityMask *parent_mask=nullptr, uint64_t parent_offset=0, bool ignore_extensions=false)
static void ColumnArrowToDuckDBDictionary (Vector &vector, ArrowArray &array, idx_t chunk_offset, ArrowArrayScanState &array_state, idx_t size, const ArrowType &arrow_type, int64_t nested_offset=-1, const ValidityMask *parent_mask=nullptr, uint64_t parent_offset=0)

Member Function Documentation

◆ SetValidityMask()

void duckdb::ArrowToDuckDBConversion::SetValidityMask ( Vector & vector,
ArrowArray & array,
idx_t chunk_offset,
idx_t size,
int64_t parent_offset,
int64_t nested_offset,
bool add_null = false )
static
240092 {
240093 D_ASSERT(vector.GetVectorType() == VectorType::FLAT_VECTOR);
240094 auto &mask = FlatVector::Validity(vector);
240095 GetValidityMask(mask, array, chunk_offset, size, parent_offset, nested_offset, add_null);
240096}
GMat mask(const GMat &src, const GMat &mask)
static void GetValidityMask(ValidityMask &mask, ArrowArray &array, idx_t chunk_offset, idx_t size, int64_t parent_offset, int64_t nested_offset=-1, bool add_null=false)
Definition duckdb.cpp:240044

◆ ColumnArrowToDuckDBRunEndEncoded()

void duckdb::ArrowToDuckDBConversion::ColumnArrowToDuckDBRunEndEncoded ( Vector & vector,
const ArrowArray & array,
idx_t chunk_offset,
ArrowArrayScanState & array_state,
idx_t size,
const ArrowType & arrow_type,
int64_t nested_offset = -1,
ValidityMask * parent_mask = nullptr,
uint64_t parent_offset = 0 )
static
240692 {
240693 // Scan the 'run_ends' array
240694 D_ASSERT(array.n_children == 2);
240695 auto &run_ends_array = *array.children[0];
240696 auto &values_array = *array.children[1];
240697
240698 auto &struct_info = arrow_type.GetTypeInfo<ArrowStructInfo>();
240699 auto &run_ends_type = struct_info.GetChild(0);
240700 auto &values_type = struct_info.GetChild(1);
240701 D_ASSERT(vector.GetType() == values_type.GetDuckType());
240702
240703 if (vector.GetBuffer()) {
240704 vector.GetBuffer()->SetAuxiliaryData(make_uniq<ArrowAuxiliaryData>(array_state.owned_data));
240705 }
240706
240707 D_ASSERT(run_ends_array.length == values_array.length);
240708 auto compressed_size = NumericCast<idx_t>(run_ends_array.length);
240709 // Create a vector for the run ends and the values
240710 auto &run_end_encoding = array_state.RunEndEncoding();
240711 if (!run_end_encoding.run_ends) {
240712 // The run ends and values have not been scanned yet for this array
240713 D_ASSERT(!run_end_encoding.values);
240714 run_end_encoding.run_ends = make_uniq<Vector>(run_ends_type.GetDuckType(), compressed_size);
240715 run_end_encoding.values = make_uniq<Vector>(values_type.GetDuckType(), compressed_size);
240716
240717 ArrowToDuckDBConversion::ColumnArrowToDuckDB(*run_end_encoding.run_ends, run_ends_array, chunk_offset,
240718 array_state, compressed_size, run_ends_type);
240719 auto &values = *run_end_encoding.values;
240720 ArrowToDuckDBConversion::SetValidityMask(values, values_array, chunk_offset, compressed_size,
240721 NumericCast<int64_t>(parent_offset), nested_offset);
240722 ArrowToDuckDBConversion::ColumnArrowToDuckDB(values, values_array, chunk_offset, array_state, compressed_size,
240723 values_type);
240724 }
240725
240726 idx_t scan_offset = GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
240727 auto physical_type = run_ends_type.GetDuckType().InternalType();
240728 switch (physical_type) {
240729 case PhysicalType::INT16:
240730 FlattenRunEndsSwitch<int16_t>(vector, run_end_encoding, compressed_size, scan_offset, size);
240731 break;
240732 case PhysicalType::INT32:
240733 FlattenRunEndsSwitch<int32_t>(vector, run_end_encoding, compressed_size, scan_offset, size);
240734 break;
240735 case PhysicalType::INT64:
240736 FlattenRunEndsSwitch<int64_t>(vector, run_end_encoding, compressed_size, scan_offset, size);
240737 break;
240738 default:
240739 throw NotImplementedException("Type '%s' not implemented for RunEndEncoding", TypeIdToString(physical_type));
240740 }
240741}
@ 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_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static void ColumnArrowToDuckDB(Vector &vector, ArrowArray &array, idx_t chunk_offset, ArrowArrayScanState &array_state, idx_t size, const ArrowType &arrow_type, int64_t nested_offset=-1, ValidityMask *parent_mask=nullptr, uint64_t parent_offset=0, bool ignore_extensions=false)
Definition duckdb.cpp:240819

◆ ColumnArrowToDuckDB()

void duckdb::ArrowToDuckDBConversion::ColumnArrowToDuckDB ( Vector & vector,
ArrowArray & array,
idx_t chunk_offset,
ArrowArrayScanState & array_state,
idx_t size,
const ArrowType & arrow_type,
int64_t nested_offset = -1,
ValidityMask * parent_mask = nullptr,
uint64_t parent_offset = 0,
bool ignore_extensions = false )
static

Arrow bit-packs boolean values Lets first figure out where we are in the source array

convert date from nanoseconds to days

Fill the children

240823 {
240824 D_ASSERT(!array.dictionary);
240825 if (!ignore_extensions && arrow_type.HasExtension()) {
240826 if (arrow_type.extension_data->arrow_to_duckdb) {
240827 // Convert the storage and then call the cast function
240828 Vector input_data(arrow_type.extension_data->GetInternalType());
240829 ColumnArrowToDuckDB(input_data, array, chunk_offset, array_state, size, arrow_type, nested_offset,
240830 parent_mask, parent_offset, /*ignore_extensions*/ true);
240831 arrow_type.extension_data->arrow_to_duckdb(array_state.context, input_data, vector, size);
240832 return;
240833 }
240834 }
240835
240836 if (vector.GetBuffer()) {
240837 vector.GetBuffer()->SetAuxiliaryData(make_uniq<ArrowAuxiliaryData>(array_state.owned_data));
240838 }
240839 switch (vector.GetType().id()) {
240840 case LogicalTypeId::SQLNULL:
240841 vector.Reference(Value());
240842 break;
240843 case LogicalTypeId::BOOLEAN: {
240846 auto effective_offset =
240847 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
240848 auto src_ptr = ArrowBufferData<uint8_t>(array, 1) + effective_offset / 8;
240849 auto tgt_ptr = (uint8_t *)FlatVector::GetData(vector);
240850 int src_pos = 0;
240851 idx_t cur_bit = effective_offset % 8;
240852 for (idx_t row = 0; row < size; row++) {
240853 if ((src_ptr[src_pos] & (1 << cur_bit)) == 0) {
240854 tgt_ptr[row] = 0;
240855 } else {
240856 tgt_ptr[row] = 1;
240857 }
240858 cur_bit++;
240859 if (cur_bit == 8) {
240860 src_pos++;
240861 cur_bit = 0;
240862 }
240863 }
240864 break;
240865 }
240866 case LogicalTypeId::TINYINT:
240867 case LogicalTypeId::SMALLINT:
240868 case LogicalTypeId::INTEGER:
240869 case LogicalTypeId::FLOAT:
240870 case LogicalTypeId::DOUBLE:
240871 case LogicalTypeId::UTINYINT:
240872 case LogicalTypeId::USMALLINT:
240873 case LogicalTypeId::UINTEGER:
240874 case LogicalTypeId::UBIGINT:
240875 case LogicalTypeId::BIGINT:
240876 case LogicalTypeId::HUGEINT:
240877 case LogicalTypeId::UHUGEINT:
240878 case LogicalTypeId::TIMESTAMP:
240879 case LogicalTypeId::TIMESTAMP_SEC:
240880 case LogicalTypeId::TIMESTAMP_MS:
240882 case LogicalTypeId::TIME_TZ: {
240883 DirectConversion(vector, array, chunk_offset, nested_offset, parent_offset);
240884 break;
240885 }
240886 case LogicalTypeId::UUID:
240887 UUIDConversion(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset), size);
240888 break;
240889 case LogicalTypeId::BLOB:
240890 case LogicalTypeId::BIT:
240891 case LogicalTypeId::BIGNUM:
240892 case LogicalTypeId::VARCHAR: {
240893 auto &string_info = arrow_type.GetTypeInfo<ArrowStringInfo>();
240894 auto size_type = string_info.GetSizeType();
240895 switch (size_type) {
240896 case ArrowVariableSizeType::SUPER_SIZE: {
240897 auto cdata = ArrowBufferData<char>(array, 2);
240898 auto offsets = ArrowBufferData<uint64_t>(array, 1) +
240899 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
240900 SetVectorString(vector, size, cdata, offsets);
240901 break;
240902 }
240903 case ArrowVariableSizeType::NORMAL: {
240904 auto cdata = ArrowBufferData<char>(array, 2);
240905 auto offsets = ArrowBufferData<uint32_t>(array, 1) +
240906 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
240907 SetVectorString(vector, size, cdata, offsets);
240908 break;
240909 }
240910 case ArrowVariableSizeType::VIEW: {
240911 SetVectorStringView(
240912 vector, size, array,
240913 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset));
240914 break;
240915 }
240916 case ArrowVariableSizeType::FIXED_SIZE: {
240917 SetValidityMask(vector, array, chunk_offset, size, NumericCast<int64_t>(parent_offset), nested_offset);
240918 auto fixed_size = string_info.FixedSize();
240919 // Have to check validity mask before setting this up
240920 idx_t offset = GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset) *
240921 fixed_size;
240922 auto cdata = ArrowBufferData<char>(array, 1);
240923 auto blob_len = fixed_size;
240924 auto result = FlatVector::GetData<string_t>(vector);
240925 for (idx_t row_idx = 0; row_idx < size; row_idx++) {
240926 if (FlatVector::IsNull(vector, row_idx)) {
240927 offset += blob_len;
240928 continue;
240929 }
240930 auto bptr = cdata + offset;
240931 result[row_idx] = StringVector::AddStringOrBlob(vector, bptr, blob_len);
240932 offset += blob_len;
240933 }
240934 }
240935 }
240936 break;
240937 }
240938 case LogicalTypeId::DATE: {
240939 auto &datetime_info = arrow_type.GetTypeInfo<ArrowDateTimeInfo>();
240940 auto precision = datetime_info.GetDateTimeType();
240941 switch (precision) {
240942 case ArrowDateTimeType::DAYS: {
240943 DirectConversion(vector, array, chunk_offset, nested_offset, parent_offset);
240944 break;
240945 }
240946 case ArrowDateTimeType::MILLISECONDS: {
240948 auto src_ptr = ArrowBufferData<uint64_t>(array, 1) +
240949 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
240950 auto tgt_ptr = FlatVector::GetData<date_t>(vector);
240951 for (idx_t row = 0; row < size; row++) {
240952 tgt_ptr[row] = date_t(UnsafeNumericCast<int32_t>(static_cast<int64_t>(src_ptr[row]) /
240953 static_cast<int64_t>(1000 * 60 * 60 * 24)));
240954 }
240955 break;
240956 }
240957 default:
240958 throw NotImplementedException("Unsupported precision for Date Type ");
240959 }
240960 break;
240961 }
240962 case LogicalTypeId::TIME: {
240963 auto &datetime_info = arrow_type.GetTypeInfo<ArrowDateTimeInfo>();
240964 auto precision = datetime_info.GetDateTimeType();
240965 switch (precision) {
240966 case ArrowDateTimeType::SECONDS: {
240967 TimeConversion<int32_t>(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
240968 size, 1000000);
240969 break;
240970 }
240971 case ArrowDateTimeType::MILLISECONDS: {
240972 TimeConversion<int32_t>(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
240973 size, 1000);
240974 break;
240975 }
240976 case ArrowDateTimeType::MICROSECONDS: {
240977 TimeConversion<int64_t>(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
240978 size, 1);
240979 break;
240980 }
240981 case ArrowDateTimeType::NANOSECONDS: {
240982 auto tgt_ptr = FlatVector::GetData<dtime_t>(vector);
240983 auto src_ptr = ArrowBufferData<int64_t>(array, 1) +
240984 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
240985 for (idx_t row = 0; row < size; row++) {
240986 tgt_ptr[row].micros = src_ptr[row] / 1000;
240987 }
240988 break;
240989 }
240990 default:
240991 throw NotImplementedException("Unsupported precision for Time Type ");
240992 }
240993 break;
240994 }
240995 case LogicalTypeId::TIME_NS: {
240996 auto &datetime_info = arrow_type.GetTypeInfo<ArrowDateTimeInfo>();
240997 auto precision = datetime_info.GetDateTimeType();
240998 switch (precision) {
240999 case ArrowDateTimeType::SECONDS: {
241000 TimeNSConversion<int32_t>(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
241001 size, 1000000000);
241002 break;
241003 }
241004 case ArrowDateTimeType::MILLISECONDS: {
241005 TimeNSConversion<int32_t>(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
241006 size, 1000000);
241007 break;
241008 }
241009 case ArrowDateTimeType::MICROSECONDS: {
241010 TimeNSConversion<int64_t>(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
241011 size, 1000);
241012 break;
241013 }
241014 case ArrowDateTimeType::NANOSECONDS: {
241015 TimeNSConversion<int64_t>(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
241016 size, 1);
241017 break;
241018 }
241019 default:
241020 throw NotImplementedException("Unsupported precision for TimeNS Type ");
241021 }
241022 break;
241023 }
241024 case LogicalTypeId::TIMESTAMP_TZ: {
241025 auto &datetime_info = arrow_type.GetTypeInfo<ArrowDateTimeInfo>();
241026 auto precision = datetime_info.GetDateTimeType();
241027 switch (precision) {
241028 case ArrowDateTimeType::SECONDS: {
241029 TimestampTZConversion(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset), size,
241030 1000000);
241031 break;
241032 }
241033 case ArrowDateTimeType::MILLISECONDS: {
241034 TimestampTZConversion(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset), size,
241035 1000);
241036 break;
241037 }
241038 case ArrowDateTimeType::MICROSECONDS: {
241039 DirectConversion(vector, array, chunk_offset, nested_offset, parent_offset);
241040 break;
241041 }
241042 case ArrowDateTimeType::NANOSECONDS: {
241043 auto tgt_ptr = FlatVector::GetData<timestamp_t>(vector);
241044 auto src_ptr = ArrowBufferData<int64_t>(array, 1) +
241045 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
241046 for (idx_t row = 0; row < size; row++) {
241047 tgt_ptr[row].value = src_ptr[row] / 1000;
241048 }
241049 break;
241050 }
241051 default:
241052 throw NotImplementedException("Unsupported precision for TimestampTZ Type ");
241053 }
241054 break;
241055 }
241056 case LogicalTypeId::INTERVAL: {
241057 auto &datetime_info = arrow_type.GetTypeInfo<ArrowDateTimeInfo>();
241058 auto precision = datetime_info.GetDateTimeType();
241059 switch (precision) {
241060 case ArrowDateTimeType::SECONDS: {
241061 IntervalConversionUs(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset), size,
241062 1000000);
241063 break;
241064 }
241065 case ArrowDateTimeType::DAYS:
241066 case ArrowDateTimeType::MILLISECONDS: {
241067 IntervalConversionUs(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset), size,
241068 1000);
241069 break;
241070 }
241071 case ArrowDateTimeType::MICROSECONDS: {
241072 IntervalConversionUs(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset), size,
241073 1);
241074 break;
241075 }
241076 case ArrowDateTimeType::NANOSECONDS: {
241077 auto tgt_ptr = FlatVector::GetData<interval_t>(vector);
241078 auto src_ptr = ArrowBufferData<int64_t>(array, 1) +
241079 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
241080 for (idx_t row = 0; row < size; row++) {
241081 tgt_ptr[row].micros = src_ptr[row] / 1000;
241082 tgt_ptr[row].days = 0;
241083 tgt_ptr[row].months = 0;
241084 }
241085 break;
241086 }
241087 case ArrowDateTimeType::MONTHS: {
241088 IntervalConversionMonths(vector, array, chunk_offset, nested_offset, NumericCast<int64_t>(parent_offset),
241089 size);
241090 break;
241091 }
241092 case ArrowDateTimeType::MONTH_DAY_NANO: {
241093 IntervalConversionMonthDayNanos(vector, array, chunk_offset, nested_offset,
241094 NumericCast<int64_t>(parent_offset), size);
241095 break;
241096 }
241097 default:
241098 throw NotImplementedException("Unsupported precision for Interval/Duration Type ");
241099 }
241100 break;
241101 }
241102 case LogicalTypeId::DECIMAL: {
241103 auto val_mask = FlatVector::Validity(vector);
241104 auto &datetime_info = arrow_type.GetTypeInfo<ArrowDecimalInfo>();
241105 auto bit_width = datetime_info.GetBitWidth();
241106
241107 switch (bit_width) {
241108 case DecimalBitWidth::DECIMAL_32: {
241109 auto src_ptr = ArrowBufferData<int32_t>(array, 1) +
241110 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
241111 ConvertDecimal(src_ptr, vector, array, size, nested_offset, parent_offset, chunk_offset, val_mask,
241112 bit_width);
241113 break;
241114 }
241115
241116 case DecimalBitWidth::DECIMAL_64: {
241117 auto src_ptr = ArrowBufferData<int64_t>(array, 1) +
241118 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
241119 ConvertDecimal(src_ptr, vector, array, size, nested_offset, parent_offset, chunk_offset, val_mask,
241120 bit_width);
241121 break;
241122 }
241123
241124 case DecimalBitWidth::DECIMAL_128: {
241125 auto src_ptr = ArrowBufferData<hugeint_t>(array, 1) +
241126 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
241127 ConvertDecimal(src_ptr, vector, array, size, nested_offset, parent_offset, chunk_offset, val_mask,
241128 bit_width);
241129 break;
241130 }
241131 default:
241132 throw NotImplementedException("Unsupported precision for Arrow Decimal Type.");
241133 }
241134 break;
241135 }
241136 case LogicalTypeId::LIST: {
241137 ArrowToDuckDBList(vector, array, chunk_offset, array_state, size, arrow_type, nested_offset, parent_mask,
241138 NumericCast<int64_t>(parent_offset));
241139 break;
241140 }
241141 case LogicalTypeId::ARRAY: {
241142 ArrowToDuckDBArray(vector, array, chunk_offset, array_state, size, arrow_type, nested_offset, parent_mask,
241143 NumericCast<int64_t>(parent_offset));
241144 break;
241145 }
241146 case LogicalTypeId::MAP: {
241147 ArrowToDuckDBList(vector, array, chunk_offset, array_state, size, arrow_type, nested_offset, parent_mask,
241148 NumericCast<int64_t>(parent_offset));
241149 ArrowToDuckDBMapVerify(vector, size);
241150 break;
241151 }
241152 case LogicalTypeId::STRUCT: {
241154 auto &struct_info = arrow_type.GetTypeInfo<ArrowStructInfo>();
241155 auto &child_entries = StructVector::GetEntries(vector);
241156 auto &struct_validity_mask = FlatVector::Validity(vector);
241157 for (idx_t child_idx = 0; child_idx < NumericCast<idx_t>(array.n_children); child_idx++) {
241158 auto &child_entry = *child_entries[child_idx];
241159 auto &child_array = *array.children[child_idx];
241160 auto &child_type = struct_info.GetChild(child_idx);
241161 auto &child_state = array_state.GetChild(child_idx);
241162
241163 ArrowToDuckDBConversion::SetValidityMask(child_entry, child_array, chunk_offset, size, array.offset,
241164 nested_offset);
241165 if (!struct_validity_mask.AllValid()) {
241166 auto &child_validity_mark = FlatVector::Validity(child_entry);
241167 for (idx_t i = 0; i < size; i++) {
241168 if (!struct_validity_mask.RowIsValid(i)) {
241169 child_validity_mark.SetInvalid(i);
241170 }
241171 }
241172 }
241173
241174 auto array_physical_type = child_type.GetPhysicalType();
241175 switch (array_physical_type) {
241176 case ArrowArrayPhysicalType::DICTIONARY_ENCODED:
241178 child_entry, child_array, chunk_offset, child_state, size, child_type, nested_offset,
241179 &struct_validity_mask, NumericCast<uint64_t>(array.offset));
241180 break;
241181 case ArrowArrayPhysicalType::RUN_END_ENCODED:
241182 ColumnArrowToDuckDBRunEndEncoded(child_entry, child_array, chunk_offset, child_state, size, child_type,
241183 nested_offset, &struct_validity_mask,
241184 NumericCast<uint64_t>(array.offset));
241185 break;
241186 case ArrowArrayPhysicalType::DEFAULT:
241187 ColumnArrowToDuckDB(child_entry, child_array, chunk_offset, child_state, size, child_type,
241188 nested_offset, &struct_validity_mask, NumericCast<uint64_t>(array.offset), false);
241189 break;
241190 default:
241191 throw NotImplementedException("ArrowArrayPhysicalType not recognized");
241192 }
241193 }
241194 break;
241195 }
241196 case LogicalTypeId::UNION: {
241197 auto type_ids_buffer_idx = array.n_buffers == 1 ? 0 : 1;
241198 auto effective_offset =
241199 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
241200 auto type_ids = ArrowBufferData<int8_t>(array, type_ids_buffer_idx) + effective_offset;
241201 D_ASSERT(type_ids);
241202 auto members = UnionType::CopyMemberTypes(vector.GetType());
241203
241204 auto &validity_mask = FlatVector::Validity(vector);
241205 auto &union_info = arrow_type.GetTypeInfo<ArrowStructInfo>();
241206 duckdb::vector<Vector> children;
241207 for (idx_t child_idx = 0; child_idx < NumericCast<idx_t>(array.n_children); child_idx++) {
241208 Vector child(members[child_idx].second, size);
241209 auto &child_array = *array.children[child_idx];
241210 auto &child_state = array_state.GetChild(child_idx);
241211 auto &child_type = union_info.GetChild(child_idx);
241212
241213 ArrowToDuckDBConversion::SetValidityMask(child, child_array, chunk_offset, size,
241214 NumericCast<int64_t>(parent_offset), nested_offset);
241215 auto array_physical_type = child_type.GetPhysicalType();
241216
241217 switch (array_physical_type) {
241218 case ArrowArrayPhysicalType::DICTIONARY_ENCODED:
241219 ArrowToDuckDBConversion::ColumnArrowToDuckDBDictionary(child, child_array, chunk_offset, child_state,
241220 size, child_type);
241221 break;
241222 case ArrowArrayPhysicalType::RUN_END_ENCODED:
241223 ArrowToDuckDBConversion::ColumnArrowToDuckDBRunEndEncoded(child, child_array, chunk_offset, child_state,
241224 size, child_type);
241225 break;
241226 case ArrowArrayPhysicalType::DEFAULT:
241227 ArrowToDuckDBConversion::ColumnArrowToDuckDB(child, child_array, chunk_offset, child_state, size,
241228 child_type, nested_offset, &validity_mask, false);
241229 break;
241230 default:
241231 throw NotImplementedException("ArrowArrayPhysicalType not recognized");
241232 }
241233
241234 children.push_back(std::move(child));
241235 }
241236
241237 for (idx_t row_idx = 0; row_idx < size; row_idx++) {
241238 auto tag = NumericCast<uint8_t>(type_ids[row_idx]);
241239
241240 auto out_of_range = tag >= array.n_children;
241241 if (out_of_range) {
241242 throw InvalidInputException("Arrow union tag out of range: %d", tag);
241243 }
241244
241245 const Value &value = children[tag].GetValue(row_idx);
241246 vector.SetValue(row_idx, value.IsNull() ? Value() : Value::UNION(members, tag, value));
241247 }
241248
241249 break;
241250 }
241251 default:
241252 throw NotImplementedException("Unsupported type for arrow conversion: %s", vector.GetType().ToString());
241253 }
241254}
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
GOpaque< Size > size(const GMat &src)
::int64_t int64_t
::uint8_t uint8_t
@ TIMESTAMP_NS
us
Definition duckdb.hpp:2886
static void ArrowToDuckDBList(Vector &vector, ArrowArray &array, idx_t chunk_offset, ArrowArrayScanState &array_state, idx_t size, const ArrowType &arrow_type, int64_t nested_offset, const ValidityMask *parent_mask, int64_t parent_offset)
Definition duckdb.cpp:240194
static void ArrowToDuckDBArray(Vector &vector, ArrowArray &array, idx_t chunk_offset, ArrowArrayScanState &array_state, idx_t size, const ArrowType &arrow_type, int64_t nested_offset, const ValidityMask *parent_mask, int64_t parent_offset)
Definition duckdb.cpp:240254
static void ColumnArrowToDuckDBDictionary(Vector &vector, ArrowArray &array, idx_t chunk_offset, ArrowArrayScanState &array_state, idx_t size, const ArrowType &arrow_type, int64_t nested_offset=-1, const ValidityMask *parent_mask=nullptr, uint64_t parent_offset=0)
Definition duckdb.cpp:241388
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:

◆ ColumnArrowToDuckDBDictionary()

void duckdb::ArrowToDuckDBConversion::ColumnArrowToDuckDBDictionary ( Vector & vector,
ArrowArray & array,
idx_t chunk_offset,
ArrowArrayScanState & array_state,
idx_t size,
const ArrowType & arrow_type,
int64_t nested_offset = -1,
const ValidityMask * parent_mask = nullptr,
uint64_t parent_offset = 0 )
static

We need to set the dictionary data for this column Allocate one extra entry beyond dictionary length for the NULL sentinel. SetMaskedSelectionVectorLoop points NULL indices at last_element_pos (= dictionary->length), so the buffer must be large enough and that entry must be marked invalid.

Get Pointer to Indices of Dictionary

241391 {
241392 if (vector.GetBuffer()) {
241393 vector.GetBuffer()->SetAuxiliaryData(make_uniq<ArrowAuxiliaryData>(array_state.owned_data));
241394 }
241395 D_ASSERT(arrow_type.HasDictionary());
241396 const bool has_nulls = CanContainNull(array, parent_mask);
241397 if (array_state.CacheOutdated(array.dictionary)) {
241402 auto dict_length = NumericCast<idx_t>(array.dictionary->length);
241403 auto base_vector = make_uniq<Vector>(vector.GetType(), dict_length + 1);
241404 ArrowToDuckDBConversion::SetValidityMask(*base_vector, *array.dictionary, chunk_offset, dict_length, 0, 0,
241405 has_nulls);
241406 FlatVector::Validity(*base_vector).SetInvalid(dict_length);
241407 auto &dictionary_type = arrow_type.GetDictionary();
241408 auto arrow_physical_type = dictionary_type.GetPhysicalType();
241409 ;
241410 switch (arrow_physical_type) {
241411 case ArrowArrayPhysicalType::DICTIONARY_ENCODED:
241412 ColumnArrowToDuckDBDictionary(*base_vector, *array.dictionary, chunk_offset, array_state,
241413 NumericCast<idx_t>(array.dictionary->length), dictionary_type);
241414 break;
241415 case ArrowArrayPhysicalType::RUN_END_ENCODED:
241416 ColumnArrowToDuckDBRunEndEncoded(*base_vector, *array.dictionary, chunk_offset, array_state,
241417 NumericCast<idx_t>(array.dictionary->length), dictionary_type);
241418 break;
241419 case ArrowArrayPhysicalType::DEFAULT:
241420 ColumnArrowToDuckDB(*base_vector, *array.dictionary, chunk_offset, array_state,
241421 NumericCast<idx_t>(array.dictionary->length), dictionary_type);
241422 break;
241423 default:
241424 throw NotImplementedException("ArrowArrayPhysicalType not recognized");
241425 };
241426 array_state.AddDictionary(std::move(base_vector), array.dictionary);
241427 }
241428 auto offset_type = arrow_type.GetDuckType();
241430 auto indices = ArrowBufferData<data_t>(array, 1) +
241431 GetTypeIdSize(offset_type.InternalType()) *
241432 GetEffectiveOffset(array, NumericCast<int64_t>(parent_offset), chunk_offset, nested_offset);
241433
241434 SelectionVector sel;
241435 if (has_nulls) {
241436 ValidityMask indices_validity;
241437 GetValidityMask(indices_validity, array, chunk_offset, size, NumericCast<int64_t>(parent_offset));
241438 if (parent_mask && !parent_mask->AllValid()) {
241439 auto &struct_validity_mask = *parent_mask;
241440 for (idx_t i = 0; i < size; i++) {
241441 if (!struct_validity_mask.RowIsValid(i)) {
241442 indices_validity.SetInvalid(i);
241443 }
241444 }
241445 }
241446 SetSelectionVector(sel, indices, offset_type, size, &indices_validity,
241447 NumericCast<idx_t>(array.dictionary->length));
241448 } else {
241449 SetSelectionVector(sel, indices, offset_type, size);
241450 }
241451 vector.Slice(array_state.GetDictionary(), sel, size);
241452 vector.Verify(size);
241453}
static void SetSelectionVector(SelectionVector &sel, data_ptr_t indices_p, const LogicalType &logical_type, idx_t size, ValidityMask *mask=nullptr, idx_t last_element_pos=0)
Definition duckdb.cpp:241289
int64_t length
Array data description.
Definition duckdb.hpp:11289
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 file: