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

#include <duckdb.hpp>

Static Public Member Functions

static DUCKDB_API void Construct (BaseStatistics &stats)
static DUCKDB_API BaseStatistics CreateUnknown (LogicalType type)
static DUCKDB_API BaseStatistics CreateEmpty (LogicalType type)
static DUCKDB_API BaseStatistics CreateShredded (const LogicalType &shredded_type)
static DUCKDB_API void CreateUnshreddedStats (BaseStatistics &stats)
static DUCKDB_API const BaseStatistics & GetUnshreddedStats (const BaseStatistics &stats)
static DUCKDB_API BaseStatistics & GetUnshreddedStats (BaseStatistics &stats)
static DUCKDB_API const BaseStatistics & GetTypedStats (const BaseStatistics &stats)
 Returns the typed_value stats of a shredded stats entry.
static DUCKDB_API const BaseStatistics & GetTypedStats (const BaseStatistics &&stats)=delete
static DUCKDB_API optional_ptr< const BaseStatistics > GetUntypedStats (const BaseStatistics &stats)
 Returns the untyped_value_index stats of a shredded stats entry - if there is any.
static DUCKDB_API optional_ptr< const BaseStatistics > GetUntypedStats (const BaseStatistics &&stats)=delete
static DUCKDB_API void SetUnshreddedStats (BaseStatistics &stats, unique_ptr< BaseStatistics > new_stats)
static DUCKDB_API void SetUnshreddedStats (BaseStatistics &stats, const BaseStatistics &new_stats)
static DUCKDB_API void MarkAsNotShredded (BaseStatistics &stats)
static DUCKDB_API LogicalType GetShreddedStructuredType (const BaseStatistics &stats)
static DUCKDB_API void CreateShreddedStats (BaseStatistics &stats, const LogicalType &shredded_type)
static DUCKDB_API bool IsShredded (const BaseStatistics &stats)
static DUCKDB_API const BaseStatistics & GetShreddedStats (const BaseStatistics &stats)
static DUCKDB_API BaseStatistics & GetShreddedStats (BaseStatistics &stats)
static DUCKDB_API void SetShreddedStats (BaseStatistics &stats, unique_ptr< BaseStatistics > new_stats)
static DUCKDB_API void SetShreddedStats (BaseStatistics &stats, const BaseStatistics &new_stats)
static DUCKDB_API bool MergeShredding (const BaseStatistics &stats, const BaseStatistics &other, BaseStatistics &new_stats)
static DUCKDB_API unique_ptr< BaseStatistics > WrapExtractedFieldAsVariant (const BaseStatistics &base_variant, const BaseStatistics &extracted_field)
static DUCKDB_API void Serialize (const BaseStatistics &stats, Serializer &serializer)
static DUCKDB_API void Deserialize (Deserializer &deserializer, BaseStatistics &base)
static DUCKDB_API string ToString (const BaseStatistics &stats)
static DUCKDB_API void Merge (BaseStatistics &stats, const BaseStatistics &other)
static DUCKDB_API void Verify (const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count)
static DUCKDB_API void Copy (BaseStatistics &stats, const BaseStatistics &other)
static DUCKDB_API unique_ptr< BaseStatistics > PushdownExtract (const BaseStatistics &stats, const StorageIndex &index)

Static Public Attributes

static constexpr idx_t TYPED_VALUE_INDEX = 0
static constexpr idx_t UNTYPED_VALUE_INDEX = 1

Static Private Member Functions

static VariantStatsData & GetDataUnsafe (BaseStatistics &stats)
static const VariantStatsData & GetDataUnsafe (const BaseStatistics &stats)

Detailed Description

VARIANT as a type can hold arbitrarily typed values within the same column. In storage, we apply shredding to the VARIANT column, this means that we find the most common type among all these values. And for those values we store them separately from the rest of the values, in a structured way (like you would store any other column).

Member Function Documentation

◆ Construct()

void duckdb::VariantStats::Construct ( BaseStatistics & stats)
static
425014 {
425015 stats.child_stats = unsafe_unique_array<BaseStatistics>(new BaseStatistics[2]);
425016 GetDataUnsafe(stats).shredding_state = VariantStatsShreddingState::UNINITIALIZED;
425017 CreateUnshreddedStats(stats);
425018}
@ UNINITIALIZED
Uninitialized, not unshredded/shredded.
Definition duckdb.hpp:16155
static DUCKDB_API void CreateUnshreddedStats(BaseStatistics &stats)
Definition duckdb.cpp:425041

◆ CreateUnknown()

BaseStatistics duckdb::VariantStats::CreateUnknown ( LogicalType type)
static

Unknown - we have no clue what's in this

425020 {
425021 BaseStatistics result(std::move(type));
425022 result.InitializeUnknown();
425024 GetDataUnsafe(result).shredding_state = VariantStatsShreddingState::INCONSISTENT;
425025 result.child_stats[0].Copy(BaseStatistics::CreateUnknown(VariantShredding::GetUnshreddedType()));
425026 return result;
425027}
static BaseStatistics CreateUnknown(LogicalType type)
Definition duckdb.cpp:422865
@ INCONSISTENT
Result from combining incompatible shreddings.
Definition duckdb.hpp:16161
Here is the call graph for this function:

◆ CreateEmpty()

BaseStatistics duckdb::VariantStats::CreateEmpty ( LogicalType type)
static
425029 {
425030 BaseStatistics result(std::move(type));
425031 result.InitializeEmpty();
425032 GetDataUnsafe(result).shredding_state = VariantStatsShreddingState::UNINITIALIZED;
425033 result.child_stats[0].Copy(BaseStatistics::CreateEmpty(VariantShredding::GetUnshreddedType()));
425034 return result;
425035}
static BaseStatistics CreateEmpty(LogicalType type)
Definition duckdb.cpp:422871

◆ CreateShredded()

BaseStatistics duckdb::VariantStats::CreateShredded ( const LogicalType & shredded_type)
static
425261 {
425262 BaseStatistics result(LogicalType::VARIANT());
425263 result.InitializeEmpty();
425264
425265 CreateShreddedStats(result, shredded_type);
425266 result.child_stats[0].Copy(BaseStatistics::CreateEmpty(VariantShredding::GetUnshreddedType()));
425267 result.child_stats[1].Copy(BaseStatistics::CreateEmpty(shredded_type));
425268 return result;
425269}
static DUCKDB_API LogicalType VARIANT()
Definition duckdb.cpp:140950

◆ CreateUnshreddedStats()

void duckdb::VariantStats::CreateUnshreddedStats ( BaseStatistics & stats)
static

Stats related to the 'unshredded' column, which holds all data that doesn't fit in the structure of the shredded column (if IsShredded())

425041 {
425042 BaseStatistics::Construct(stats.child_stats[0], VariantShredding::GetUnshreddedType());
425043}

◆ GetUnshreddedStats() [1/2]

const BaseStatistics & duckdb::VariantStats::GetUnshreddedStats ( const BaseStatistics & stats)
static
425045 {
425046 AssertVariant(stats);
425047 return stats.child_stats[0];
425048}

◆ GetUnshreddedStats() [2/2]

BaseStatistics & duckdb::VariantStats::GetUnshreddedStats ( BaseStatistics & stats)
static
425050 {
425051 AssertVariant(stats);
425052 return stats.child_stats[0];
425053}

◆ GetTypedStats()

const BaseStatistics & duckdb::VariantStats::GetTypedStats ( const BaseStatistics & stats)
static

Returns the typed_value stats of a shredded stats entry.

425055 {
425056 if (stats.GetType().id() != LogicalTypeId::STRUCT) {
425057 // primitive stats - return the stats directly
425058 return stats;
425059 }
425060 // STRUCT(typed_value, (untyped_value)) - return the typed_value stats
425061 return StructStats::GetChildStats(stats, TYPED_VALUE_INDEX);
425062}
Here is the caller graph for this function:

◆ GetUntypedStats()

optional_ptr< const BaseStatistics > duckdb::VariantStats::GetUntypedStats ( const BaseStatistics & stats)
static

Returns the untyped_value_index stats of a shredded stats entry - if there is any.

425064 {
425065 if (stats.GetType().id() != LogicalTypeId::STRUCT) {
425066 // primitive stats - no untyped stats
425067 return nullptr;
425068 }
425069 // STRUCT(typed_value, (untyped_value)) - check if we have untyped stats
425070 if (StructType::GetChildCount(stats.GetType()) == 1) {
425071 // fully shredded and no untyped stats
425072 return nullptr;
425073 }
425074 return StructStats::GetChildStats(stats, UNTYPED_VALUE_INDEX);
425075}
Here is the caller graph for this function:

◆ SetUnshreddedStats() [1/2]

void duckdb::VariantStats::SetUnshreddedStats ( BaseStatistics & stats,
unique_ptr< BaseStatistics > new_stats )
static
425082 {
425083 AssertVariant(stats);
425084 if (!new_stats) {
425085 CreateUnshreddedStats(stats);
425086 } else {
425087 SetUnshreddedStats(stats, *new_stats);
425088 }
425089}

◆ SetUnshreddedStats() [2/2]

void duckdb::VariantStats::SetUnshreddedStats ( BaseStatistics & stats,
const BaseStatistics & new_stats )
static
425077 {
425078 AssertVariant(stats);
425079 stats.child_stats[0].Copy(new_stats);
425080}

◆ MarkAsNotShredded()

void duckdb::VariantStats::MarkAsNotShredded ( BaseStatistics & stats)
static

All Variant stats start off as UNINITIALIZED, to support merging This method marks the stats as being unshredded, so they produce INCONSISTENT when merged with SHREDDED stats

425091 {
425092 D_ASSERT(!IsShredded(stats));
425093 auto &data = GetDataUnsafe(stats);
425096 data.shredding_state = VariantStatsShreddingState::NOT_SHREDDED;
425097}
@ NOT_SHREDDED
No shredding applied yet.
Definition duckdb.hpp:16157
Here is the caller graph for this function:

◆ GetShreddedStructuredType()

LogicalType duckdb::VariantStats::GetShreddedStructuredType ( const BaseStatistics & stats)
static

Stats related to the 'shredded' column, which holds all structured data created during shredding Returns the LogicalType that represents the shredding as a single DuckDB LogicalType (i.e STRUCT(col1 VARCHAR))

425245 {
425246 D_ASSERT(IsShredded(stats));
425247 return ToStructuredType(GetShreddedStats(stats).GetType());
425248}

◆ CreateShreddedStats()

void duckdb::VariantStats::CreateShreddedStats ( BaseStatistics & stats,
const LogicalType & shredded_type )
static
425250 {
425251 BaseStatistics::Construct(stats.child_stats[1], shredded_type);
425252 auto &data = GetDataUnsafe(stats);
425253 data.shredding_state = VariantStatsShreddingState::SHREDDED;
425254}
@ SHREDDED
Shredded consistently.
Definition duckdb.hpp:16159

◆ IsShredded()

bool duckdb::VariantStats::IsShredded ( const BaseStatistics & stats)
static
425256 {
425257 auto &data = GetDataUnsafe(stats);
425258 return data.shredding_state == VariantStatsShreddingState::SHREDDED;
425259}

◆ GetShreddedStats() [1/2]

const BaseStatistics & duckdb::VariantStats::GetShreddedStats ( const BaseStatistics & stats)
static
425271 {
425272 AssertVariant(stats);
425273 D_ASSERT(IsShredded(stats));
425274 return stats.child_stats[1];
425275}

◆ GetShreddedStats() [2/2]

BaseStatistics & duckdb::VariantStats::GetShreddedStats ( BaseStatistics & stats)
static
425277 {
425278 AssertVariant(stats);
425279 D_ASSERT(IsShredded(stats));
425280 return stats.child_stats[1];
425281}

◆ SetShreddedStats() [1/2]

void duckdb::VariantStats::SetShreddedStats ( BaseStatistics & stats,
unique_ptr< BaseStatistics > new_stats )
static
425293 {
425294 AssertVariant(stats);
425295 D_ASSERT(new_stats);
425296 SetShreddedStats(stats, *new_stats);
425297}

◆ SetShreddedStats() [2/2]

void duckdb::VariantStats::SetShreddedStats ( BaseStatistics & stats,
const BaseStatistics & new_stats )
static
425283 {
425284 auto &data = GetDataUnsafe(stats);
425285 if (!IsShredded(stats)) {
425286 BaseStatistics::Construct(stats.child_stats[1], new_stats.GetType());
425287 D_ASSERT(data.shredding_state != VariantStatsShreddingState::INCONSISTENT);
425288 data.shredding_state = VariantStatsShreddingState::SHREDDED;
425289 }
425290 stats.child_stats[1].Copy(new_stats);
425291}

◆ MergeShredding()

bool duckdb::VariantStats::MergeShredding ( const BaseStatistics & stats,
const BaseStatistics & other,
BaseStatistics & new_stats )
static

shredded_type: <shredding> STRUCT(typed_value <shredding>) STRUCT(typed_value <shredding>, untyped_value_index UINTEGER)

shredding, 1 of:

  • <primitive type>
  • <shredded_type>
  • <shredded_type>[]

other is not an OBJECT, can't merge

Map field name to index, for 'other'

Attempt to merge all overlapping fields, only keep the fields that were able to be merged

TODO: perhaps we can keep the field but demote the type to unshredded somehow? Or even use MaxLogicalType and merge the stats into that ?

No fields remaining, demote to unshredded

Create new stats out of the remaining fields

other is not an ARRAY, can't merge

TODO: perhaps we can keep the LIST part of the stats, and only demote the child to unshredded?

other is not the same type, can't merge

425432 {
425437
425442
425443 auto &stats_typed_value = GetTypedStats(stats);
425444 auto &other_typed_value = GetTypedStats(other);
425445
425446 auto &stats_typed_value_type = stats_typed_value.GetType();
425447 auto &other_typed_value_type = other_typed_value.GetType();
425448
425449 auto untyped_value_stats = GetUntypedStats(stats);
425450 auto other_untyped_stats = GetUntypedStats(other);
425451
425452 // handle untyped value stats
425453 optional_ptr<BaseStatistics> new_untyped_value_stats;
425454 BaseStatistics owned_untyped_value_stats;
425455
425456 if (untyped_value_stats && other_untyped_stats) {
425457 // both entries have untyped value stats - merge them
425458 owned_untyped_value_stats = untyped_value_stats->Copy();
425459 owned_untyped_value_stats.Merge(*other_untyped_stats);
425460 new_untyped_value_stats = owned_untyped_value_stats;
425461 } else if (untyped_value_stats) {
425462 // only LHS has untyped value stats
425463 owned_untyped_value_stats = untyped_value_stats->Copy();
425464 new_untyped_value_stats = owned_untyped_value_stats;
425465 } else if (other_untyped_stats) {
425466 // only RHS has untyped value stats
425467 owned_untyped_value_stats = other_untyped_stats->Copy();
425468 new_untyped_value_stats = owned_untyped_value_stats;
425469 }
425470
425471 if (stats_typed_value_type.id() == LogicalTypeId::STRUCT) {
425472 if (stats_typed_value_type.id() != other_typed_value_type.id()) {
425474 return false;
425475 }
425476 auto &stats_object_children = StructType::GetChildTypes(stats_typed_value_type);
425477 auto &other_object_children = StructType::GetChildTypes(other_typed_value_type);
425478
425480 case_insensitive_map_t<idx_t> key_to_index;
425481 for (idx_t i = 0; i < other_object_children.size(); i++) {
425482 auto &other_object_child = other_object_children[i];
425483 key_to_index.emplace(other_object_child.first, i);
425484 }
425485
425487 child_list_t<LogicalType> new_children;
425488 vector<BaseStatistics> new_child_stats;
425489
425490 for (idx_t i = 0; i < stats_object_children.size(); i++) {
425491 auto &stats_object_child = stats_object_children[i];
425492 auto other_it = key_to_index.find(stats_object_child.first);
425493 if (other_it == key_to_index.end()) {
425494 continue;
425495 }
425496 auto &other_object_child = other_object_children[other_it->second];
425497 if (other_object_child.second.id() != stats_object_child.second.id()) {
425500 continue;
425501 }
425502
425503 auto &stats_child = StructStats::GetChildStats(stats_typed_value, i);
425504 auto &other_child = StructStats::GetChildStats(other_typed_value, other_it->second);
425505 BaseStatistics new_child;
425506 if (!MergeShredding(stats_child, other_child, new_child)) {
425507 continue;
425508 }
425509 new_children.emplace_back(stats_object_child.first, new_child.GetType());
425510 new_child_stats.emplace_back(std::move(new_child));
425511 }
425512 if (new_children.empty()) {
425514 return false;
425515 }
425516
425518 auto new_object_type = LogicalType::STRUCT(std::move(new_children));
425519 auto new_typed_value = BaseStatistics::CreateEmpty(new_object_type);
425520 for (idx_t i = 0; i < new_child_stats.size(); i++) {
425521 StructStats::SetChildStats(new_typed_value, i, new_child_stats[i]);
425522 }
425523 new_typed_value.CombineValidity(stats_typed_value, other_typed_value);
425524 new_stats = WrapTypedValue(new_typed_value, new_untyped_value_stats);
425525 return true;
425526 } else if (stats_typed_value_type.id() == LogicalTypeId::LIST) {
425527 if (stats_typed_value_type.id() != other_typed_value_type.id()) {
425529 return false;
425530 }
425531 auto &stats_child = ListStats::GetChildStats(stats_typed_value);
425532 auto &other_child = ListStats::GetChildStats(other_typed_value);
425533
425535 BaseStatistics new_child_stats;
425536 if (!MergeShredding(stats_child, other_child, new_child_stats)) {
425537 return false;
425538 }
425539 auto new_typed_value = BaseStatistics::CreateEmpty(LogicalType::LIST(new_child_stats.type));
425540 new_typed_value.CombineValidity(stats_typed_value, other_typed_value);
425541 ListStats::SetChildStats(new_typed_value, new_child_stats.ToUnique());
425542 new_stats = WrapTypedValue(new_typed_value, new_untyped_value_stats);
425543 return true;
425544 } else {
425545 D_ASSERT(!stats_typed_value_type.IsNested());
425546 if (stats_typed_value_type.id() != other_typed_value_type.id()) {
425548 return false;
425549 }
425550 auto new_typed_stats = stats_typed_value.Copy();
425551 new_typed_stats.Merge(other_typed_value);
425552 new_stats = WrapTypedValue(new_typed_stats, new_untyped_value_stats);
425553 return true;
425554 }
425555}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API bool MergeShredding(const BaseStatistics &stats, const BaseStatistics &other, BaseStatistics &new_stats)
Definition duckdb.cpp:425432
static DUCKDB_API optional_ptr< const BaseStatistics > GetUntypedStats(const BaseStatistics &stats)
Returns the untyped_value_index stats of a shredded stats entry - if there is any.
Definition duckdb.cpp:425064
static DUCKDB_API const BaseStatistics & GetTypedStats(const BaseStatistics &stats)
Returns the typed_value stats of a shredded stats entry.
Definition duckdb.cpp:425055
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WrapExtractedFieldAsVariant()

unique_ptr< BaseStatistics > duckdb::VariantStats::WrapExtractedFieldAsVariant ( const BaseStatistics & base_variant,
const BaseStatistics & extracted_field )
static
425421 {
425422 D_ASSERT(base_variant.type.id() == LogicalTypeId::VARIANT);
425423 AssertShreddedStats(extracted_field);
425424
425425 BaseStatistics copy = BaseStatistics::CreateUnknown(base_variant.GetType());
425426 copy.Copy(base_variant);
425427 copy.child_stats[1] = BaseStatistics::CreateUnknown(extracted_field.GetType());
425428 copy.child_stats[1].Copy(extracted_field);
425429 return copy.ToUnique();
425430}

◆ Serialize()

void duckdb::VariantStats::Serialize ( const BaseStatistics & stats,
Serializer & serializer )
static
425303 {
425304 auto &data = GetDataUnsafe(stats);
425305 auto &unshredded_stats = VariantStats::GetUnshreddedStats(stats);
425306
425307 serializer.WriteProperty(200, "shredding_state", data.shredding_state);
425308
425309 serializer.WriteProperty(225, "unshredded_stats", unshredded_stats);
425310 if (IsShredded(stats)) {
425311 auto &shredded_stats = VariantStats::GetShreddedStats(stats);
425312 serializer.WriteProperty(230, "shredded_type", shredded_stats.type);
425313 serializer.WriteProperty(235, "shredded_stats", shredded_stats);
425314 }
425315}

◆ Deserialize()

void duckdb::VariantStats::Deserialize ( Deserializer & deserializer,
BaseStatistics & base )
static

Read the 'unshredded_stats' child

Read the type of the 'shredded_stats'

Finally read the 'shredded_stats' themselves

425317 {
425318 D_ASSERT(base.GetType().InternalType() == PhysicalType::STRUCT);
425319 D_ASSERT(base.GetType().id() == LogicalTypeId::VARIANT);
425320 auto &data = GetDataUnsafe(base);
425321
425322 auto unshredded_type = VariantShredding::GetUnshreddedType();
425323 data.shredding_state = deserializer.ReadProperty<VariantStatsShreddingState>(200, "shredding_state");
425324
425325 {
425327 deserializer.Set<const LogicalType &>(unshredded_type);
425328 auto stat = deserializer.ReadProperty<BaseStatistics>(225, "unshredded_stats");
425329 base.child_stats[0].Copy(stat);
425330 deserializer.Unset<LogicalType>();
425331 }
425332
425333 if (!IsShredded(base)) {
425334 return;
425335 }
425337 auto shredded_type = deserializer.ReadProperty<LogicalType>(230, "shredded_type");
425338
425339 {
425341 deserializer.Set<const LogicalType &>(shredded_type);
425342 auto stat = deserializer.ReadProperty<BaseStatistics>(235, "shredded_stats");
425343 if (base.child_stats[1].type.id() == LogicalTypeId::INVALID) {
425344 base.child_stats[1] = BaseStatistics::CreateUnknown(shredded_type);
425345 }
425346 base.child_stats[1].Copy(stat);
425347 deserializer.Unset<LogicalType>();
425348 }
425349}
VariantStatsShreddingState
Definition duckdb.hpp:16153
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
LogicalType Copy() const
Copies the logical type, making a new ExtraTypeInfo.
Definition duckdb.cpp:140449
Here is the call graph for this function:

◆ ToString()

string duckdb::VariantStats::ToString ( const BaseStatistics & stats)
static
425386 {
425387 string result;
425388 bool is_shredded = IsShredded(stats);
425389 auto &data = GetDataUnsafe(stats);
425390 result = StringUtil::Format("shredding_state: %s", EnumUtil::ToString(data.shredding_state));
425391 if (is_shredded) {
425392 result += ", shredding: {";
425393 result += StringUtil::Format("typed_value_type: %s, ", ToStructuredType(stats.child_stats[1].type).ToString());
425394 result += StringUtil::Format("stats: {%s}", ToStringInternal(stats.child_stats[1]));
425395 result += "}";
425396 }
425397 return result;
425398}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002

◆ Merge()

void duckdb::VariantStats::Merge ( BaseStatistics & stats,
const BaseStatistics & other )
static

No need to merge

INCONSISTENT + ANY -> INCONSISTENT

UNINITIALIZED + ANY -> ANY

NOT_SHREDDED + !NOT_SHREDDED -> INCONSISTENT

SHREDDED(T1) + SHREDDED(T2) -> INCONSISTENT

SHREDDED(T1) + SHREDDED(T1) -> SHREDDED

SHREDDED + !SHREDDED -> INCONSISTENT

425557 {
425558 if (other.GetType().id() == LogicalTypeId::VALIDITY) {
425559 return;
425560 }
425561
425562 stats.child_stats[0].Merge(other.child_stats[0]);
425563 auto &data = GetDataUnsafe(stats);
425564 auto &other_data = GetDataUnsafe(other);
425565
425566 const auto other_shredding_state = other_data.shredding_state;
425567 const auto shredding_state = data.shredding_state;
425568
425569 if (other_shredding_state == VariantStatsShreddingState::UNINITIALIZED) {
425571 return;
425572 }
425573
425574 switch (shredding_state) {
425577 return;
425578 }
425580 switch (other_shredding_state) {
425582 stats.child_stats[1] = BaseStatistics::CreateUnknown(other.child_stats[1].GetType());
425583 stats.child_stats[1].Copy(other.child_stats[1]);
425584 break;
425585 default:
425586 break;
425587 }
425589 data.shredding_state = other_shredding_state;
425590 break;
425591 }
425593 if (other_shredding_state == VariantStatsShreddingState::NOT_SHREDDED) {
425594 return;
425595 }
425597 data.shredding_state = VariantStatsShreddingState::INCONSISTENT;
425598 stats.child_stats[1].type = LogicalType::INVALID;
425599 break;
425600 }
425602 switch (other_shredding_state) {
425604 BaseStatistics merged_shredding_stats;
425605 if (!MergeShredding(stats.child_stats[1], other.child_stats[1], merged_shredding_stats)) {
425607 data.shredding_state = VariantStatsShreddingState::INCONSISTENT;
425608 stats.child_stats[1].type = LogicalType::INVALID;
425609 } else {
425611 stats.child_stats[1] = BaseStatistics::CreateUnknown(merged_shredding_stats.GetType());
425612 stats.child_stats[1].Copy(merged_shredding_stats);
425613 }
425614 break;
425615 }
425616 default:
425618 data.shredding_state = VariantStatsShreddingState::INCONSISTENT;
425619 stats.child_stats[1].type = LogicalType::INVALID;
425620 break;
425621 }
425622 break;
425623 }
425624 }
425625}
Here is the call graph for this function:

◆ Verify()

void duckdb::VariantStats::Verify ( const BaseStatistics & stats,
Vector & vector,
const SelectionVector & sel,
idx_t count )
static
425644 {
425645 // TODO: Verify stats
425646}

◆ Copy()

void duckdb::VariantStats::Copy ( BaseStatistics & stats,
const BaseStatistics & other )
static

This is ensured by the CopyBase method of BaseStatistics

425627 {
425628 auto &other_data = VariantStats::GetDataUnsafe(other);
425629 auto &data = VariantStats::GetDataUnsafe(stats);
425630 (void)other_data;
425631 (void)data;
425632
425634 D_ASSERT(data.shredding_state == other_data.shredding_state);
425635 stats.child_stats[0].Copy(other.child_stats[0]);
425636 if (IsShredded(other)) {
425637 stats.child_stats[1] = BaseStatistics::CreateUnknown(other.child_stats[1].GetType());
425638 stats.child_stats[1].Copy(other.child_stats[1]);
425639 } else {
425640 stats.child_stats[1].type = LogicalType::INVALID;
425641 }
425642}
Here is the call graph for this function:

◆ PushdownExtract()

unique_ptr< BaseStatistics > duckdb::VariantStats::PushdownExtract ( const BaseStatistics & stats,
const StorageIndex & index )
static

Not shredded at all, no stats available

Not fully shredded, can't say anything meaningful about the stats

Not fully shredded, can't say anything meaningful about the stats

Return the variant stats, not the 'typed_value' (non-variant) stats, since there's no cast pushed down

Not all data is shredded, so there are values in the column that are not of the shredded type

FIXME: support try_cast

425662 {
425663 if (!VariantStats::IsShredded(stats)) {
425665 return nullptr;
425666 }
425667
425668 optional_ptr<const BaseStatistics> res(VariantStats::GetShreddedStats(stats));
425669 if (!CanUseShreddedStats(res)) {
425671 return nullptr;
425672 }
425673
425674 reference<const StorageIndex> index_iter(index);
425675 while (true) {
425676 auto &current = index_iter.get();
425677 D_ASSERT(!current.HasPrimaryIndex());
425678 auto &field_name = current.GetFieldName();
425679 VariantPathComponent path(field_name);
425680 res = VariantShreddedStats::FindChildStats(*res, path);
425681 if (!CanUseShreddedStats(res)) {
425683 return nullptr;
425684 }
425685 if (!index_iter.get().HasChildren()) {
425686 break;
425687 }
425688 }
425689 auto &shredded_child_stats = *res;
425690
425691 auto &typed_value_stats = GetTypedStats(shredded_child_stats);
425692 auto &last_index = index_iter.get();
425693 auto &child_type = typed_value_stats.type;
425694 if (!last_index.HasType() || last_index.GetType().id() == LogicalTypeId::VARIANT) {
425696 return WrapExtractedFieldAsVariant(stats, shredded_child_stats);
425697 }
425698 if (!VariantShreddedStats::IsFullyShredded(shredded_child_stats)) {
425700 return nullptr;
425701 }
425702
425703 auto &cast_type = last_index.GetType();
425704 if (child_type != cast_type) {
425706 return StatisticsPropagator::TryPropagateCast(typed_value_stats, child_type, cast_type);
425707 }
425708 auto result = typed_value_stats.ToUnique();
425709 return result;
425710}
static DUCKDB_API bool IsFullyShredded(const BaseStatistics &stats)
Definition duckdb.cpp:425169
Here is the call graph for this function:

◆ GetDataUnsafe() [1/2]

VariantStatsData & duckdb::VariantStats::GetDataUnsafe ( BaseStatistics & stats)
staticprivate
425653 {
425654 AssertVariant(stats);
425655 return stats.stats_union.variant_data;
425656}

◆ GetDataUnsafe() [2/2]

const VariantStatsData & duckdb::VariantStats::GetDataUnsafe ( const BaseStatistics & stats)
staticprivate
425648 {
425649 AssertVariant(stats);
425650 return stats.stats_union.variant_data;
425651}

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