440760 {
440761 if (parent_count.IsValid() && column.total_count > parent_count.GetIndex()) {
440762 throw InternalException("Column count is larger than parent count - this should not be possible");
440763 }
440764 auto total_value_count = parent_count.IsValid() ? parent_count.GetIndex() : column.total_count;
440765 const auto null_count = column.type_counts[0];
440766 if (null_count == column.total_count) {
440768 auto fully_consistent = null_count == total_value_count;
440769 out_type = SetShreddedType(LogicalTypeId::INTEGER, fully_consistent);
440770 return true;
440771 }
440772
440773 idx_t max_count = 0;
440776 for (uint8_t i = 1; i < static_cast<uint8_t>(VariantLogicalType::ENUM_SIZE); i++) {
440777 if (i ==
static_cast<uint8_t>(VariantLogicalType::DECIMAL) && !column.decimal_consistent) {
440779 continue;
440780 }
440781 idx_t count = column.type_counts[i] + null_count;
440782 if (!max_count || count > max_count) {
440783 max_count = count;
440784 type_index = i;
440785 }
440786 }
440787
440788 if (!max_count) {
440789 return false;
440790 }
440791
440792 bool fully_consistent = max_count == total_value_count;
440793 if (type_index ==
static_cast<uint8_t>(VariantLogicalType::OBJECT)) {
440794 child_list_t<LogicalType> child_types;
440795 for (auto &entry : column.field_stats) {
440796 auto &child_column = GetColumnStats(entry.second);
440797 LogicalType child_type;
440799 child_types.emplace_back(entry.first, child_type);
440800 }
440801 }
440802 if (child_types.empty()) {
440803 return false;
440804 }
440805
440806 fully_consistent = false;
440807 auto shredded_type = LogicalType::STRUCT(child_types);
440808 out_type = SetShreddedType(shredded_type, fully_consistent);
440809 return true;
440810 }
440811 if (type_index ==
static_cast<uint8_t>(VariantLogicalType::ARRAY)) {
440813 auto &element_column = GetColumnStats(column.element_stats);
440814 LogicalType element_type;
440816 return false;
440817 }
440818 auto shredded_type = LogicalType::LIST(element_type);
440819 out_type = SetShreddedType(shredded_type, fully_consistent);
440820 return true;
440821 }
440822 if (type_index ==
static_cast<uint8_t>(VariantLogicalType::DECIMAL)) {
440823 auto shredded_type = LogicalType::DECIMAL(
static_cast<uint8_t>(column.decimal_width),
440824 static_cast<uint8_t>(column.decimal_scale));
440825 out_type = SetShreddedType(shredded_type, fully_consistent);
440826 return true;
440827 }
440828 auto type_id = static_cast<VariantLogicalType>(type_index);
440829
440830 auto shredded_type = ProduceShreddedType(type_id);
440831 out_type = SetShreddedType(shredded_type, fully_consistent);
440832 return true;
440833}