When we're shredding an object, the top-level struct of it should always be valid
For some of the rows the field is missing, adjust the selection vector to exclude these rows.
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);
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
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
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