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

Static Public Member Functions

static DUCKDB_API BaseStatistics CreateUnknown (LogicalType type)
 Unknown statistics - i.e. "has_min" is false, "has_max" is false.
static DUCKDB_API BaseStatistics CreateEmpty (LogicalType type)
 Empty statistics - i.e. "min = MaxValue<type>, max = MinValue<type>".
static DUCKDB_API bool IsConstant (const BaseStatistics &stats)
 Returns true if the stats has a constant value.
static DUCKDB_API bool HasMinMax (const BaseStatistics &stats)
 Returns true if the stats has both a min and max value defined.
static DUCKDB_API bool HasMin (const BaseStatistics &stats)
 Returns true if the stats has a min value defined.
static DUCKDB_API bool HasMax (const BaseStatistics &stats)
 Returns true if the stats has a max value defined.
static DUCKDB_API Value Min (const BaseStatistics &stats)
 Returns the min value - throws an exception if there is no min value.
static DUCKDB_API Value Max (const BaseStatistics &stats)
 Returns the max value - throws an exception if there is no max value.
static DUCKDB_API void SetMin (BaseStatistics &stats, const Value &val)
 Sets the min value of the statistics.
static DUCKDB_API void SetMax (BaseStatistics &stats, const Value &val)
 Sets the max value of the statistics.
template<class T>
static void SetMax (BaseStatistics &stats, T val)
template<class T>
static void SetMin (BaseStatistics &stats, T val)
static DUCKDB_API FilterPropagateResult CheckZonemap (const BaseStatistics &stats, ExpressionType comparison_type, array_ptr< const Value > constants)
 Check whether or not a given comparison with a constant could possibly be satisfied by rows given the statistics.
static DUCKDB_API void Merge (BaseStatistics &stats, const BaseStatistics &other_p)
static DUCKDB_API void Serialize (const BaseStatistics &stats, Serializer &serializer)
static DUCKDB_API void Deserialize (Deserializer &deserializer, BaseStatistics &stats)
static DUCKDB_API string ToString (const BaseStatistics &stats)
template<class T>
static void UpdateValue (T new_value, T &min, T &max)
template<class T>
static void Update (NumericStatsData &nstats, T new_value)
static void Verify (const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count)
template<class T>
static T GetMin (const BaseStatistics &stats)
template<class T>
static T GetMax (const BaseStatistics &stats)
template<class T>
static T GetMinUnsafe (const BaseStatistics &stats)
template<class T>
static T GetMaxUnsafe (const BaseStatistics &stats)

Static Private Member Functions

static NumericStatsData & GetDataUnsafe (BaseStatistics &stats)
static const NumericStatsData & GetDataUnsafe (const BaseStatistics &stats)
static Value MinOrNull (const BaseStatistics &stats)
static Value MaxOrNull (const BaseStatistics &stats)
template<class T>
static void TemplatedVerify (const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count)

Member Function Documentation

◆ CreateUnknown()

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

Unknown statistics - i.e. "has_min" is false, "has_max" is false.

423870 {
423871 BaseStatistics result(std::move(type));
423872 result.InitializeUnknown();
423873 SetMin(result, Value(result.GetType()));
423874 SetMax(result, Value(result.GetType()));
423875 return result;
423876}
static DUCKDB_API void SetMin(BaseStatistics &stats, const Value &val)
Sets the min value of the statistics.
Definition duckdb.cpp:424188
static DUCKDB_API void SetMax(BaseStatistics &stats, const Value &val)
Sets the max value of the statistics.
Definition duckdb.cpp:424193
Here is the call graph for this function:

◆ CreateEmpty()

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

Empty statistics - i.e. "min = MaxValue<type>, max = MinValue<type>".

423878 {
423879 BaseStatistics result(std::move(type));
423880 result.InitializeEmpty();
423881 SetMin(result, Value::MaximumValue(result.GetType()));
423882 SetMax(result, Value::MinimumValue(result.GetType()));
423883 return result;
423884}
static DUCKDB_API Value MinimumValue(const LogicalType &type)
Create the lowest possible value of a given type (numeric only).
Definition duckdb.cpp:131884
static DUCKDB_API Value MaximumValue(const LogicalType &type)
Create the highest possible value of a given type (numeric only).
Definition duckdb.cpp:131980
Here is the call graph for this function:

◆ IsConstant()

bool duckdb::NumericStats::IsConstant ( const BaseStatistics & stats)
static

Returns true if the stats has a constant value.

424130 {
424131 return NumericStats::Max(stats) <= NumericStats::Min(stats);
424132}
static DUCKDB_API Value Min(const BaseStatistics &stats)
Returns the min value - throws an exception if there is no min value.
Definition duckdb.cpp:424256
static DUCKDB_API Value Max(const BaseStatistics &stats)
Returns the max value - throws an exception if there is no max value.
Definition duckdb.cpp:424263
Here is the call graph for this function:

◆ HasMinMax()

bool duckdb::NumericStats::HasMinMax ( const BaseStatistics & stats)
static

Returns true if the stats has both a min and max value defined.

424237 {
424238 return NumericStats::HasMin(stats) && NumericStats::HasMax(stats) &&
424239 NumericStats::Min(stats) <= NumericStats::Max(stats);
424240}
static DUCKDB_API bool HasMin(const BaseStatistics &stats)
Returns true if the stats has a min value defined.
Definition duckdb.cpp:424242
static DUCKDB_API bool HasMax(const BaseStatistics &stats)
Returns true if the stats has a max value defined.
Definition duckdb.cpp:424249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasMin()

bool duckdb::NumericStats::HasMin ( const BaseStatistics & stats)
static

Returns true if the stats has a min value defined.

424242 {
424243 if (stats.GetType().id() == LogicalTypeId::SQLNULL) {
424244 return false;
424245 }
424246 return NumericStats::GetDataUnsafe(stats).has_min;
424247}
Here is the caller graph for this function:

◆ HasMax()

bool duckdb::NumericStats::HasMax ( const BaseStatistics & stats)
static

Returns true if the stats has a max value defined.

424249 {
424250 if (stats.GetType().id() == LogicalTypeId::SQLNULL) {
424251 return false;
424252 }
424253 return NumericStats::GetDataUnsafe(stats).has_max;
424254}
Here is the caller graph for this function:

◆ Min()

Value duckdb::NumericStats::Min ( const BaseStatistics & stats)
static

Returns the min value - throws an exception if there is no min value.

424256 {
424257 if (!NumericStats::HasMin(stats)) {
424258 throw InternalException("Min() called on statistics that does not have min");
424259 }
424260 return NumericValueUnionToValue(stats.GetType(), NumericStats::GetDataUnsafe(stats).min);
424261}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Max()

Value duckdb::NumericStats::Max ( const BaseStatistics & stats)
static

Returns the max value - throws an exception if there is no max value.

424263 {
424264 if (!NumericStats::HasMax(stats)) {
424265 throw InternalException("Max() called on statistics that does not have max");
424266 }
424267 return NumericValueUnionToValue(stats.GetType(), NumericStats::GetDataUnsafe(stats).max);
424268}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetMin() [1/2]

void duckdb::NumericStats::SetMin ( BaseStatistics & stats,
const Value & val )
static

Sets the min value of the statistics.

424188 {
424189 auto &data = NumericStats::GetDataUnsafe(stats);
424190 SetNumericValueInternal(new_min, stats.GetType(), data.min, data.has_min);
424191}
Here is the caller graph for this function:

◆ SetMax() [1/2]

void duckdb::NumericStats::SetMax ( BaseStatistics & stats,
const Value & val )
static

Sets the max value of the statistics.

424193 {
424194 auto &data = NumericStats::GetDataUnsafe(stats);
424195 SetNumericValueInternal(new_max, stats.GetType(), data.max, data.has_max);
424196}
Here is the caller graph for this function:

◆ SetMax() [2/2]

template<class T>
void duckdb::NumericStats::SetMax ( BaseStatistics & stats,
T val )
inlinestatic
15224 {
15225 auto &nstats = GetDataUnsafe(stats);
15226 nstats.has_max = true;
15227 nstats.max.GetReferenceUnsafe<T>() = val;
15228 }

◆ SetMin() [2/2]

template<class T>
void duckdb::NumericStats::SetMin ( BaseStatistics & stats,
T val )
inlinestatic
15231 {
15232 auto &nstats = GetDataUnsafe(stats);
15233 nstats.has_min = true;
15234 nstats.min.GetReferenceUnsafe<T>() = val;
15235 }

◆ CheckZonemap()

FilterPropagateResult duckdb::NumericStats::CheckZonemap ( const BaseStatistics & stats,
ExpressionType comparison_type,
array_ptr< const Value > constants )
static

Check whether or not a given comparison with a constant could possibly be satisfied by rows given the statistics.

424095 {
424096 if (!NumericStats::HasMinMax(stats)) {
424097 return FilterPropagateResult::NO_PRUNING_POSSIBLE;
424098 }
424099 D_ASSERT(stats.CanHaveNoNull());
424100 switch (stats.GetType().InternalType()) {
424101 case PhysicalType::INT8:
424102 return CheckZonemapTemplated<int8_t>(stats, comparison_type, constants);
424103 case PhysicalType::INT16:
424104 return CheckZonemapTemplated<int16_t>(stats, comparison_type, constants);
424105 case PhysicalType::INT32:
424106 return CheckZonemapTemplated<int32_t>(stats, comparison_type, constants);
424107 case PhysicalType::INT64:
424108 return CheckZonemapTemplated<int64_t>(stats, comparison_type, constants);
424109 case PhysicalType::UINT8:
424110 return CheckZonemapTemplated<uint8_t>(stats, comparison_type, constants);
424112 return CheckZonemapTemplated<uint16_t>(stats, comparison_type, constants);
424114 return CheckZonemapTemplated<uint32_t>(stats, comparison_type, constants);
424116 return CheckZonemapTemplated<uint64_t>(stats, comparison_type, constants);
424117 case PhysicalType::INT128:
424118 return CheckZonemapTemplated<hugeint_t>(stats, comparison_type, constants);
424119 case PhysicalType::UINT128:
424120 return CheckZonemapTemplated<uhugeint_t>(stats, comparison_type, constants);
424121 case PhysicalType::FLOAT:
424122 return CheckZonemapTemplated<float>(stats, comparison_type, constants);
424124 return CheckZonemapTemplated<double>(stats, comparison_type, constants);
424125 default:
424126 throw InternalException("Unsupported type for NumericStats::CheckZonemap");
424127 }
424128}
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ 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
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ INT8
Signed 8-bit little-endian integer.
Definition duckdb.hpp:2749
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776
static DUCKDB_API bool HasMinMax(const BaseStatistics &stats)
Returns true if the stats has both a min and max value defined.
Definition duckdb.cpp:424237
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Merge()

void duckdb::NumericStats::Merge ( BaseStatistics & stats,
const BaseStatistics & other_p )
static
423896 {
423897 if (other.GetType().id() == LogicalTypeId::VALIDITY) {
423898 return;
423899 }
423900 D_ASSERT(stats.GetType() == other.GetType());
423901 if (NumericStats::HasMin(other) && NumericStats::HasMin(stats)) {
423902 auto other_min = NumericStats::Min(other);
423903 if (other_min < NumericStats::Min(stats)) {
423904 NumericStats::SetMin(stats, other_min);
423905 }
423906 } else {
423907 NumericStats::SetMin(stats, Value());
423908 }
423909 if (NumericStats::HasMax(other) && NumericStats::HasMax(stats)) {
423910 auto other_max = NumericStats::Max(other);
423911 if (other_max > NumericStats::Max(stats)) {
423912 NumericStats::SetMax(stats, other_max);
423913 }
423914 } else {
423915 NumericStats::SetMax(stats, Value());
423916 }
423917}

◆ Serialize()

void duckdb::NumericStats::Serialize ( const BaseStatistics & stats,
Serializer & serializer )
static
424388 {
424389 auto &numeric_stats = NumericStats::GetDataUnsafe(stats);
424390 serializer.WriteObject(200, "max", [&](Serializer &object) {
424391 SerializeNumericStatsValue(stats.GetType(), numeric_stats.min, numeric_stats.has_min, object);
424392 });
424393 serializer.WriteObject(201, "min", [&](Serializer &object) {
424394 SerializeNumericStatsValue(stats.GetType(), numeric_stats.max, numeric_stats.has_max, object);
424395 });
424396}

◆ Deserialize()

void duckdb::NumericStats::Deserialize ( Deserializer & deserializer,
BaseStatistics & stats )
static
424398 {
424399 auto &numeric_stats = NumericStats::GetDataUnsafe(result);
424400
424401 deserializer.ReadObject(200, "max", [&](Deserializer &object) {
424402 DeserializeNumericStatsValue(result.GetType(), numeric_stats.min, numeric_stats.has_min, object);
424403 });
424404 deserializer.ReadObject(201, "min", [&](Deserializer &object) {
424405 DeserializeNumericStatsValue(result.GetType(), numeric_stats.max, numeric_stats.has_max, object);
424406 });
424407}

◆ ToString()

string duckdb::NumericStats::ToString ( const BaseStatistics & stats)
static
424409 {
424410 return StringUtil::Format("[Min: %s, Max: %s]", NumericStats::MinOrNull(stats).ToString(),
424411 NumericStats::MaxOrNull(stats).ToString());
424412}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002

◆ UpdateValue()

template<class T>
void duckdb::NumericStats::UpdateValue ( T new_value,
T & min,
T & max )
inlinestatic
15249 {
15250 min = LessThan::Operation(new_value, min) ? new_value : min;
15251 max = GreaterThan::Operation(new_value, max) ? new_value : max;
15252 }
static softfloat min()
static softfloat max()

◆ Update()

template<class T>
void duckdb::NumericStats::Update ( NumericStatsData & nstats,
T new_value )
inlinestatic
15254 {
15255 UpdateValue<T>(new_value, nstats.min.GetReferenceUnsafe<T>(), nstats.max.GetReferenceUnsafe<T>());
15256 }

◆ Verify()

void duckdb::NumericStats::Verify ( const BaseStatistics & stats,
Vector & vector,
const SelectionVector & sel,
idx_t count )
static
424440 {
424441 auto &type = stats.GetType();
424442 switch (type.InternalType()) {
424443 case PhysicalType::BOOL:
424444 break;
424445 case PhysicalType::INT8:
424446 TemplatedVerify<int8_t>(stats, vector, sel, count);
424447 break;
424448 case PhysicalType::INT16:
424449 TemplatedVerify<int16_t>(stats, vector, sel, count);
424450 break;
424451 case PhysicalType::INT32:
424452 TemplatedVerify<int32_t>(stats, vector, sel, count);
424453 break;
424454 case PhysicalType::INT64:
424455 TemplatedVerify<int64_t>(stats, vector, sel, count);
424456 break;
424457 case PhysicalType::UINT8:
424458 TemplatedVerify<uint8_t>(stats, vector, sel, count);
424459 break;
424461 TemplatedVerify<uint16_t>(stats, vector, sel, count);
424462 break;
424464 TemplatedVerify<uint32_t>(stats, vector, sel, count);
424465 break;
424467 TemplatedVerify<uint64_t>(stats, vector, sel, count);
424468 break;
424469 case PhysicalType::INT128:
424470 TemplatedVerify<hugeint_t>(stats, vector, sel, count);
424471 break;
424472 case PhysicalType::UINT128:
424473 TemplatedVerify<uhugeint_t>(stats, vector, sel, count);
424474 break;
424475 case PhysicalType::FLOAT:
424476 TemplatedVerify<float>(stats, vector, sel, count);
424477 break;
424479 TemplatedVerify<double>(stats, vector, sel, count);
424480 break;
424481 default:
424482 throw InternalException("Unsupported type %s for numeric statistics verify", type.ToString());
424483 }
424484}
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743

◆ GetMin()

template<class T>
T duckdb::NumericStats::GetMin ( const BaseStatistics & stats)
inlinestatic
15261 {
15262 return NumericStats::Min(stats).GetValueUnsafe<T>();
15263 }

◆ GetMax()

template<class T>
T duckdb::NumericStats::GetMax ( const BaseStatistics & stats)
inlinestatic
15265 {
15266 return NumericStats::Max(stats).GetValueUnsafe<T>();
15267 }

◆ GetMinUnsafe()

template<class T>
template uint32_t duckdb::NumericStats::GetMinUnsafe ( const BaseStatistics & stats)
static
423985 {
423986 return GetNumericValueUnion::Operation<T>(NumericStats::GetDataUnsafe(stats).min);
423987}

◆ GetMaxUnsafe()

template<class T>
template uint32_t duckdb::NumericStats::GetMaxUnsafe ( const BaseStatistics & stats)
static
423990 {
423991 return GetNumericValueUnion::Operation<T>(NumericStats::GetDataUnsafe(stats).max);
423992}

◆ GetDataUnsafe() [1/2]

NumericStatsData & duckdb::NumericStats::GetDataUnsafe ( BaseStatistics & stats)
staticprivate
423886 {
423887 D_ASSERT(stats.GetStatsType() == StatisticsType::NUMERIC_STATS);
423888 return stats.stats_union.numeric_data;
423889}

◆ GetDataUnsafe() [2/2]

const NumericStatsData & duckdb::NumericStats::GetDataUnsafe ( const BaseStatistics & stats)
staticprivate
423891 {
423892 D_ASSERT(stats.GetStatsType() == StatisticsType::NUMERIC_STATS);
423893 return stats.stats_union.numeric_data;
423894}

◆ MinOrNull()

Value duckdb::NumericStats::MinOrNull ( const BaseStatistics & stats)
staticprivate
424270 {
424271 if (!NumericStats::HasMin(stats)) {
424272 return Value(stats.GetType());
424273 }
424274 return NumericStats::Min(stats);
424275}

◆ MaxOrNull()

Value duckdb::NumericStats::MaxOrNull ( const BaseStatistics & stats)
staticprivate
424277 {
424278 if (!NumericStats::HasMax(stats)) {
424279 return Value(stats.GetType());
424280 }
424281 return NumericStats::Max(stats);
424282}

◆ TemplatedVerify()

template<class T>
void duckdb::NumericStats::TemplatedVerify ( const BaseStatistics & stats,
Vector & vector,
const SelectionVector & sel,
idx_t count )
staticprivate
424416 {
424417 UnifiedVectorFormat vdata;
424418 vector.ToUnifiedFormat(count, vdata);
424419
424420 auto data = UnifiedVectorFormat::GetData<T>(vdata);
424421 auto min_value = NumericStats::MinOrNull(stats);
424422 auto max_value = NumericStats::MaxOrNull(stats);
424423 for (idx_t i = 0; i < count; i++) {
424424 auto idx = sel.get_index(i);
424425 auto index = vdata.sel->get_index(idx);
424426 if (!vdata.validity.RowIsValid(index)) {
424427 continue;
424428 }
424429 if (!min_value.IsNull() && LessThan::Operation(data[index], min_value.GetValueUnsafe<T>())) { // LCOV_EXCL_START
424430 throw InternalException("Statistics mismatch: value is smaller than min.\nStatistics: %s\nVector: %s",
424431 stats.ToString(), vector.ToString(count));
424432 } // LCOV_EXCL_STOP
424433 if (!max_value.IsNull() && GreaterThan::Operation(data[index], max_value.GetValueUnsafe<T>())) {
424434 throw InternalException("Statistics mismatch: value is bigger than max.\nStatistics: %s\nVector: %s",
424435 stats.ToString(), vector.ToString(count));
424436 }
424437 }
424438}
index
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

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