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

Static Public Member Functions

static DUCKDB_API BaseStatistics CreateUnknown (LogicalType type)
 Unknown statistics - i.e. "has_unicode" is true, "max_string_length" is unknown, "min" is \0, max is \xFF.
static DUCKDB_API BaseStatistics CreateEmpty (LogicalType type)
 Empty statistics - i.e. "has_unicode" is false, "max_string_length" is 0, "min" is \xFF, max is \x00.
static DUCKDB_API bool HasMaxStringLength (const BaseStatistics &stats)
 Whether or not the statistics have a maximum string length defined.
static DUCKDB_API uint32_t MaxStringLength (const BaseStatistics &stats)
 Returns the maximum string length, or throws an exception if !HasMaxStringLength().
static DUCKDB_API bool CanContainUnicode (const BaseStatistics &stats)
 Whether or not the strings can contain unicode.
static DUCKDB_API string Min (const BaseStatistics &stats)
 Returns the min value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE).
static DUCKDB_API string Max (const BaseStatistics &stats)
 Returns the max value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE).
static DUCKDB_API void ResetMaxStringLength (BaseStatistics &stats)
 Resets the max string length so HasMaxStringLength() is false.
static DUCKDB_API void SetMaxStringLength (BaseStatistics &stats, uint32_t length)
 Sets the max string length.
static DUCKDB_API void SetContainsUnicode (BaseStatistics &stats)
 FIXME: make this part of Set on statistics.
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 FilterPropagateResult CheckZonemap (const BaseStatistics &stats, ExpressionType comparison_type, array_ptr< const Value > constants)
static DUCKDB_API FilterPropagateResult CheckZonemap (const_data_ptr_t min_data, idx_t min_len, const_data_ptr_t max_data, idx_t max_len, ExpressionType comparison_type, const string &value)
static DUCKDB_API void Update (BaseStatistics &stats, const string_t &value)
static DUCKDB_API void SetMin (BaseStatistics &stats, const string_t &value)
static DUCKDB_API void SetMax (BaseStatistics &stats, const string_t &value)
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 Private Member Functions

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

Member Function Documentation

◆ CreateUnknown()

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

Unknown statistics - i.e. "has_unicode" is true, "max_string_length" is unknown, "min" is \0, max is \xFF.

424515 {
424516 BaseStatistics result(std::move(type));
424517 result.InitializeUnknown();
424518 auto &string_data = StringStats::GetDataUnsafe(result);
424519 for (idx_t i = 0; i < StringStatsData::MAX_STRING_MINMAX_SIZE; i++) {
424520 string_data.min[i] = 0;
424521 string_data.max[i] = 0xFF;
424522 }
424523 string_data.max_string_length = 0;
424524 string_data.has_max_string_length = false;
424525 string_data.has_unicode = true;
424526 return result;
424527}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ CreateEmpty()

BaseStatistics duckdb::StringStats::CreateEmpty ( LogicalType type)
static

Empty statistics - i.e. "has_unicode" is false, "max_string_length" is 0, "min" is \xFF, max is \x00.

424529 {
424530 BaseStatistics result(std::move(type));
424531 result.InitializeEmpty();
424532 auto &string_data = StringStats::GetDataUnsafe(result);
424533 for (idx_t i = 0; i < StringStatsData::MAX_STRING_MINMAX_SIZE; i++) {
424534 string_data.min[i] = 0xFF;
424535 string_data.max[i] = 0;
424536 }
424537 string_data.max_string_length = 0;
424538 string_data.has_max_string_length = true;
424539 string_data.has_unicode = false;
424540 return result;
424541}

◆ HasMaxStringLength()

bool duckdb::StringStats::HasMaxStringLength ( const BaseStatistics & stats)
static

Whether or not the statistics have a maximum string length defined.

424553 {
424554 if (stats.GetType().id() == LogicalTypeId::SQLNULL) {
424555 return false;
424556 }
424557 return StringStats::GetDataUnsafe(stats).has_max_string_length;
424558}
Here is the caller graph for this function:

◆ MaxStringLength()

uint32_t duckdb::StringStats::MaxStringLength ( const BaseStatistics & stats)
static

Returns the maximum string length, or throws an exception if !HasMaxStringLength().

424560 {
424561 if (!HasMaxStringLength(stats)) {
424562 throw InternalException("MaxStringLength called on statistics that does not have a max string length");
424563 }
424564 return StringStats::GetDataUnsafe(stats).max_string_length;
424565}
static DUCKDB_API bool HasMaxStringLength(const BaseStatistics &stats)
Whether or not the statistics have a maximum string length defined.
Definition duckdb.cpp:424553
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CanContainUnicode()

bool duckdb::StringStats::CanContainUnicode ( const BaseStatistics & stats)
static

Whether or not the strings can contain unicode.

424567 {
424568 if (stats.GetType().id() == LogicalTypeId::SQLNULL) {
424569 return true;
424570 }
424571 return StringStats::GetDataUnsafe(stats).has_unicode;
424572}

◆ Min()

string duckdb::StringStats::Min ( const BaseStatistics & stats)
static

Returns the min value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE).

424584 {
424585 return GetStringMinMaxValue(StringStats::GetDataUnsafe(stats).min);
424586}
static softfloat min()

◆ Max()

string duckdb::StringStats::Max ( const BaseStatistics & stats)
static

Returns the max value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE).

424588 {
424589 return GetStringMinMaxValue(StringStats::GetDataUnsafe(stats).max);
424590}
static softfloat max()

◆ ResetMaxStringLength()

void duckdb::StringStats::ResetMaxStringLength ( BaseStatistics & stats)
static

Resets the max string length so HasMaxStringLength() is false.

424592 {
424593 StringStats::GetDataUnsafe(stats).has_max_string_length = false;
424594}

◆ SetMaxStringLength()

void duckdb::StringStats::SetMaxStringLength ( BaseStatistics & stats,
uint32_t length )
static

Sets the max string length.

424596 {
424597 auto &data = StringStats::GetDataUnsafe(stats);
424598 data.has_max_string_length = true;
424599 data.max_string_length = length;
424600}

◆ SetContainsUnicode()

void duckdb::StringStats::SetContainsUnicode ( BaseStatistics & stats)
static

FIXME: make this part of Set on statistics.

424602 {
424603 StringStats::GetDataUnsafe(stats).has_unicode = true;
424604}

◆ Serialize()

void duckdb::StringStats::Serialize ( const BaseStatistics & stats,
Serializer & serializer )
static
424606 {
424607 auto &string_data = StringStats::GetDataUnsafe(stats);
424608 serializer.WriteProperty(200, "min", string_data.min, StringStatsData::MAX_STRING_MINMAX_SIZE);
424609 serializer.WriteProperty(201, "max", string_data.max, StringStatsData::MAX_STRING_MINMAX_SIZE);
424610 serializer.WriteProperty(202, "has_unicode", string_data.has_unicode);
424611 serializer.WriteProperty(203, "has_max_string_length", string_data.has_max_string_length);
424612 serializer.WriteProperty(204, "max_string_length", string_data.max_string_length);
424613}

◆ Deserialize()

void duckdb::StringStats::Deserialize ( Deserializer & deserializer,
BaseStatistics & base )
static
424615 {
424616 auto &string_data = StringStats::GetDataUnsafe(base);
424617 deserializer.ReadProperty(200, "min", string_data.min, StringStatsData::MAX_STRING_MINMAX_SIZE);
424618 deserializer.ReadProperty(201, "max", string_data.max, StringStatsData::MAX_STRING_MINMAX_SIZE);
424619 deserializer.ReadProperty(202, "has_unicode", string_data.has_unicode);
424620 deserializer.ReadProperty(203, "has_max_string_length", string_data.has_max_string_length);
424621 deserializer.ReadProperty(204, "max_string_length", string_data.max_string_length);
424622}

◆ ToString()

string duckdb::StringStats::ToString ( const BaseStatistics & stats)
static
424770 {
424771 auto &string_data = StringStats::GetDataUnsafe(stats);
424772 uint32_t min_len = GetValidMinMaxSubstring(string_data.min);
424773 uint32_t max_len = GetValidMinMaxSubstring(string_data.max);
424774 return StringUtil::Format("[Min: %s, Max: %s, Has Unicode: %s, Max String Length: %s]",
424775 Blob::ToString(string_t(const_char_ptr_cast(string_data.min), min_len)),
424776 Blob::ToString(string_t(const_char_ptr_cast(string_data.max), max_len)),
424777 string_data.has_unicode ? "true" : "false",
424778 string_data.has_max_string_length ? to_string(string_data.max_string_length) : "?");
424779}
static DUCKDB_API void ToString(string_t blob, char *output)
Converts a blob to a string, writing the output to the designated output string. The string needs to ...
Definition duckdb.cpp:113152
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
std::string to_string(const T &value)
Definition duckdb.cpp:19425
::uint32_t uint32_t

◆ CheckZonemap() [1/2]

FilterPropagateResult duckdb::StringStats::CheckZonemap ( const BaseStatistics & stats,
ExpressionType comparison_type,
array_ptr< const Value > constants )
static
424703 {
424704 auto &string_data = StringStats::GetDataUnsafe(stats);
424705 D_ASSERT(stats.CanHaveNoNull());
424706 for (auto &constant_value : constants) {
424707 D_ASSERT(constant_value.type() == stats.GetType());
424708 D_ASSERT(!constant_value.IsNull());
424709 auto &constant = StringValue::Get(constant_value);
424710 auto prune_result = CheckZonemap(string_data.min, StringStatsData::MAX_STRING_MINMAX_SIZE, string_data.max,
424711 StringStatsData::MAX_STRING_MINMAX_SIZE, comparison_type, constant);
424712 if (prune_result == FilterPropagateResult::NO_PRUNING_POSSIBLE) {
424713 return FilterPropagateResult::NO_PRUNING_POSSIBLE;
424714 } else if (prune_result == FilterPropagateResult::FILTER_ALWAYS_TRUE) {
424715 return FilterPropagateResult::FILTER_ALWAYS_TRUE;
424716 }
424717 }
424718 return FilterPropagateResult::FILTER_ALWAYS_FALSE;
424719}

◆ CheckZonemap() [2/2]

FilterPropagateResult duckdb::StringStats::CheckZonemap ( const_data_ptr_t min_data,
idx_t min_len,
const_data_ptr_t max_data,
idx_t max_len,
ExpressionType comparison_type,
const string & value )
static
424722 {
424723 auto data = const_data_ptr_cast(constant.c_str());
424724 idx_t size = constant.size();
424725
424726 int min_comp = StringValueComparison(data, MinValue(min_len, size), min_data);
424727 int max_comp = StringValueComparison(data, MinValue(max_len, size), max_data);
424728 switch (comparison_type) {
424729 case ExpressionType::COMPARE_EQUAL:
424730 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
424731 if (min_comp >= 0 && max_comp <= 0) {
424732 return FilterPropagateResult::NO_PRUNING_POSSIBLE;
424733 } else {
424734 return FilterPropagateResult::FILTER_ALWAYS_FALSE;
424735 }
424736 case ExpressionType::COMPARE_NOTEQUAL:
424737 case ExpressionType::COMPARE_DISTINCT_FROM:
424738 if (min_comp < 0 || max_comp > 0) {
424739 return FilterPropagateResult::FILTER_ALWAYS_TRUE;
424740 }
424741 return FilterPropagateResult::NO_PRUNING_POSSIBLE;
424742 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
424743 case ExpressionType::COMPARE_GREATERTHAN:
424744 if (max_comp <= 0) {
424745 return FilterPropagateResult::NO_PRUNING_POSSIBLE;
424746 } else {
424747 return FilterPropagateResult::FILTER_ALWAYS_FALSE;
424748 }
424749 case ExpressionType::COMPARE_LESSTHAN:
424750 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
424751 if (min_comp >= 0) {
424752 return FilterPropagateResult::NO_PRUNING_POSSIBLE;
424753 } else {
424754 return FilterPropagateResult::FILTER_ALWAYS_FALSE;
424755 }
424756 default:
424757 throw InternalException("Expression type not implemented for string statistics zone map");
424758 }
424759}
GOpaque< Size > size(const GMat &src)

◆ Update()

void duckdb::StringStats::Update ( BaseStatistics & stats,
const string_t & value )
static

we can only fit 8 bytes, so we might need to trim our string

424643 {
424644 auto data = const_data_ptr_cast(value.GetData());
424645 auto size = value.GetSize();
424646
424648 // construct the value
424649 data_t target[StringStatsData::MAX_STRING_MINMAX_SIZE];
424650 ConstructValue(data, size, target);
424651
424652 // update the min and max
424653 auto &string_data = StringStats::GetDataUnsafe(stats);
424654 if (StringValueComparison(target, StringStatsData::MAX_STRING_MINMAX_SIZE, string_data.min) < 0) {
424655 memcpy(string_data.min, target, StringStatsData::MAX_STRING_MINMAX_SIZE);
424656 }
424657 if (StringValueComparison(target, StringStatsData::MAX_STRING_MINMAX_SIZE, string_data.max) > 0) {
424658 memcpy(string_data.max, target, StringStatsData::MAX_STRING_MINMAX_SIZE);
424659 }
424660 if (size > string_data.max_string_length) {
424661 string_data.max_string_length = UnsafeNumericCast<uint32_t>(size);
424662 }
424663 if (stats.GetType().id() == LogicalTypeId::VARCHAR && !string_data.has_unicode) {
424664 auto unicode = Utf8Proc::Analyze(const_char_ptr_cast(data), size);
424665 if (unicode == UnicodeType::UTF8) {
424666 string_data.has_unicode = true;
424667 } else if (unicode == UnicodeType::INVALID) {
424668 throw ErrorManager::InvalidUnicodeError(string(const_char_ptr_cast(data), size),
424669 "segment statistics update");
424670 }
424671 }
424672}
static UnicodeType Analyze(const char *s, size_t len, UnicodeInvalidReason *invalid_reason=nullptr, size_t *invalid_pos=nullptr)
Distinguishes ASCII, Valid UTF8 and Invalid UTF8 strings.
Definition duckdb.cpp:507297
uint8_t data_t
data pointers
Definition duckdb.hpp:246
Here is the call graph for this function:

◆ SetMin()

void duckdb::StringStats::SetMin ( BaseStatistics & stats,
const string_t & value )
static
424674 {
424675 ConstructValue(const_data_ptr_cast(value.GetData()), value.GetSize(), GetDataUnsafe(stats).min);
424676}

◆ SetMax()

void duckdb::StringStats::SetMax ( BaseStatistics & stats,
const string_t & value )
static
424678 {
424679 ConstructValue(const_data_ptr_cast(value.GetData()), value.GetSize(), GetDataUnsafe(stats).max);
424680}

◆ Merge()

void duckdb::StringStats::Merge ( BaseStatistics & stats,
const BaseStatistics & other )
static
424682 {
424683 if (other.GetType().id() == LogicalTypeId::VALIDITY) {
424684 return;
424685 }
424686 if (other.GetType().id() == LogicalTypeId::SQLNULL) {
424687 return;
424688 }
424689 auto &string_data = StringStats::GetDataUnsafe(stats);
424690 auto &other_data = StringStats::GetDataUnsafe(other);
424691 if (StringValueComparison(other_data.min, StringStatsData::MAX_STRING_MINMAX_SIZE, string_data.min) < 0) {
424692 memcpy(string_data.min, other_data.min, StringStatsData::MAX_STRING_MINMAX_SIZE);
424693 }
424694 if (StringValueComparison(other_data.max, StringStatsData::MAX_STRING_MINMAX_SIZE, string_data.max) > 0) {
424695 memcpy(string_data.max, other_data.max, StringStatsData::MAX_STRING_MINMAX_SIZE);
424696 }
424697 string_data.has_unicode = string_data.has_unicode || other_data.has_unicode;
424698 string_data.has_max_string_length = string_data.has_max_string_length && other_data.has_max_string_length;
424699 string_data.max_string_length = MaxValue<uint32_t>(string_data.max_string_length, other_data.max_string_length);
424700}

◆ Verify()

void duckdb::StringStats::Verify ( const BaseStatistics & stats,
Vector & vector,
const SelectionVector & sel,
idx_t count )
static
424781 {
424782 auto &string_data = StringStats::GetDataUnsafe(stats);
424783
424784 UnifiedVectorFormat vdata;
424785 vector.ToUnifiedFormat(count, vdata);
424786 auto data = UnifiedVectorFormat::GetData<string_t>(vdata);
424787 for (idx_t i = 0; i < count; i++) {
424788 auto idx = sel.get_index(i);
424789 auto index = vdata.sel->get_index(idx);
424790 if (!vdata.validity.RowIsValid(index)) {
424791 continue;
424792 }
424793 auto value = data[index];
424794 auto data = value.GetData();
424795 auto len = value.GetSize();
424796 // LCOV_EXCL_START
424797 if (string_data.has_max_string_length && len > string_data.max_string_length) {
424798 throw InternalException(
424799 "Statistics mismatch: string value exceeds maximum string length.\nStatistics: %s\nVector: %s",
424800 stats.ToString(), vector.ToString(count));
424801 }
424802 if (stats.GetType().id() == LogicalTypeId::VARCHAR && !string_data.has_unicode) {
424803 auto unicode = Utf8Proc::Analyze(data, len);
424804 if (unicode == UnicodeType::UTF8) {
424805 throw InternalException("Statistics mismatch: string value contains unicode, but statistics says it "
424806 "shouldn't.\nStatistics: %s\nVector: %s",
424807 stats.ToString(), vector.ToString(count));
424808 } else if (unicode == UnicodeType::INVALID) {
424809 throw InternalException("Invalid unicode detected in vector: %s", vector.ToString(count));
424810 }
424811 }
424812 if (StringValueComparison(const_data_ptr_cast(data),
424813 MinValue<idx_t>(len, StringStatsData::MAX_STRING_MINMAX_SIZE), string_data.min) < 0) {
424814 throw InternalException("Statistics mismatch: value is smaller than min.\nStatistics: %s\nVector: %s",
424815 stats.ToString(), vector.ToString(count));
424816 }
424817 if (StringValueComparison(const_data_ptr_cast(data),
424818 MinValue<idx_t>(len, StringStatsData::MAX_STRING_MINMAX_SIZE), string_data.max) > 0) {
424819 throw InternalException("Statistics mismatch: value is bigger than max.\nStatistics: %s\nVector: %s",
424820 stats.ToString(), vector.ToString(count));
424821 }
424822 // LCOV_EXCL_STOP
424823 }
424824}
index

◆ GetDataUnsafe() [1/2]

StringStatsData & duckdb::StringStats::GetDataUnsafe ( BaseStatistics & stats)
staticprivate
424543 {
424544 D_ASSERT(stats.GetStatsType() == StatisticsType::STRING_STATS);
424545 return stats.stats_union.string_data;
424546}

◆ GetDataUnsafe() [2/2]

const StringStatsData & duckdb::StringStats::GetDataUnsafe ( const BaseStatistics & stats)
staticprivate
424548 {
424549 D_ASSERT(stats.GetStatsType() == StatisticsType::STRING_STATS);
424550 return stats.stats_union.string_data;
424551}

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