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::DistinctStatistics Class Reference
Collaboration diagram for duckdb::DistinctStatistics:

Public Member Functions

 DistinctStatistics (unique_ptr< HyperLogLog > log, idx_t sample_count, idx_t total_count)
void Merge (const DistinctStatistics &other)
unique_ptr< DistinctStatistics > Copy () const
void UpdateSample (Vector &new_data, idx_t count, Vector &hashes)
void Update (Vector &new_data, idx_t count, Vector &hashes)
string ToString () const
idx_t GetCount () const
void Serialize (Serializer &serializer) const

Static Public Member Functions

static bool TypeIsSupported (const LogicalType &type)
static unique_ptr< DistinctStatistics > Deserialize (Deserializer &deserializer)

Public Attributes

unique_ptr< HyperLogLog > log
 The HLL of the table.
atomic< idx_t > sample_count
 How many values have been sampled into the HLL.
atomic< idx_t > total_count
 How many values have been inserted (before sampling).

Private Member Functions

void UpdateInternal (Vector &update, idx_t count, Vector &hashes)

Static Private Attributes

static constexpr double BASE_SAMPLE_RATE = 0.1
 For distinct statistics we sample the input to speed up insertions.
static constexpr double INTEGRAL_SAMPLE_RATE = 0.3
 For integers, we sample more: likely to be join keys (and hashing is cheaper than, e.g., strings).

Constructor & Destructor Documentation

◆ DistinctStatistics() [1/2]

duckdb::DistinctStatistics::DistinctStatistics ( )
423339 : log(make_uniq<HyperLogLog>()), sample_count(0), total_count(0) {
423340}
atomic< idx_t > sample_count
How many values have been sampled into the HLL.
Definition duckdb.hpp:48303
unique_ptr< HyperLogLog > log
The HLL of the table.
Definition duckdb.hpp:48301
atomic< idx_t > total_count
How many values have been inserted (before sampling).
Definition duckdb.hpp:48305

◆ DistinctStatistics() [2/2]

duckdb::DistinctStatistics::DistinctStatistics ( unique_ptr< HyperLogLog > log,
idx_t sample_count,
idx_t total_count )
explicit
423344}

Member Function Documentation

◆ Merge()

void duckdb::DistinctStatistics::Merge ( const DistinctStatistics & other)
423350 {
423351 log->Merge(*other.log);
423352 sample_count += other.sample_count;
423353 total_count += other.total_count;
423354}

◆ Copy()

unique_ptr< DistinctStatistics > duckdb::DistinctStatistics::Copy ( ) const
423346 {
423347 return make_uniq<DistinctStatistics>(log->Copy(), sample_count, total_count);
423348}

◆ UpdateSample()

void duckdb::DistinctStatistics::UpdateSample ( Vector & new_data,
idx_t count,
Vector & hashes )
423356 {
423357 total_count += count;
423358 const auto original_count = count;
423359 const auto sample_rate = new_data.GetType().IsIntegral() ? INTEGRAL_SAMPLE_RATE : BASE_SAMPLE_RATE;
423360 // Sample up to 'sample_rate' of STANDARD_VECTOR_SIZE of this vector (at least 1)
423361 count = MaxValue<idx_t>(LossyNumericCast<idx_t>(sample_rate * static_cast<double>(STANDARD_VECTOR_SIZE)), 1);
423362 // But never more than the original count
423363 count = MinValue<idx_t>(count, original_count);
423364
423365 UpdateInternal(new_data, count, hashes);
423366}
static constexpr double INTEGRAL_SAMPLE_RATE
For integers, we sample more: likely to be join keys (and hashing is cheaper than,...
Definition duckdb.hpp:48330
static constexpr double BASE_SAMPLE_RATE
For distinct statistics we sample the input to speed up insertions.
Definition duckdb.hpp:48328

◆ Update()

void duckdb::DistinctStatistics::Update ( Vector & new_data,
idx_t count,
Vector & hashes )
423368 {
423369 total_count += count;
423370 UpdateInternal(new_data, count, hashes);
423371}

◆ ToString()

string duckdb::DistinctStatistics::ToString ( ) const
423380 {
423381 return StringUtil::Format("[Approx Unique: %llu]", GetCount());
423382}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002

◆ GetCount()

idx_t duckdb::DistinctStatistics::GetCount ( ) const
423384 {
423385 if (sample_count == 0 || total_count == 0) {
423386 return 0;
423387 }
423388
423389 double u = static_cast<double>(MinValue<idx_t>(log->Count(), sample_count));
423390 double s = static_cast<double>(sample_count.load());
423391 double n = static_cast<double>(total_count.load());
423392
423393 // Assume this proportion of the the sampled values occurred only once
423394 double u1 = pow(u / s, 2) * u;
423395
423396 // Estimate total uniques using Good Turing Estimation
423397 idx_t estimate = LossyNumericCast<idx_t>(u + u1 / s * (n - s));
423398 return MinValue<idx_t>(estimate, total_count);
423399}
void pow(InputArray src, double power, OutputArray dst)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ TypeIsSupported()

bool duckdb::DistinctStatistics::TypeIsSupported ( const LogicalType & type)
static
423401 {
423402 switch (type.InternalType()) {
423403 case PhysicalType::LIST:
423405 case PhysicalType::ARRAY:
423406 return false; // We don't support nested types
423407 case PhysicalType::BIT:
423408 case PhysicalType::BOOL:
423409 return false; // Doesn't make much sense
423410 default:
423411 return true;
423412 }
423413}
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
@ BIT
Boolean as 1 bit, LSB bit-packed ordering.
Definition duckdb.hpp:2852

◆ Serialize()

void duckdb::DistinctStatistics::Serialize ( Serializer & serializer) const
419339 {
419340 serializer.WritePropertyWithDefault<idx_t>(100, "sample_count", sample_count);
419341 serializer.WritePropertyWithDefault<idx_t>(101, "total_count", total_count);
419342 serializer.WritePropertyWithDefault<unique_ptr<HyperLogLog>>(102, "log", log);
419343}

◆ Deserialize()

unique_ptr< DistinctStatistics > duckdb::DistinctStatistics::Deserialize ( Deserializer & deserializer)
static
419345 {
419346 auto sample_count = deserializer.ReadPropertyWithDefault<idx_t>(100, "sample_count");
419347 auto total_count = deserializer.ReadPropertyWithDefault<idx_t>(101, "total_count");
419348 auto log = deserializer.ReadPropertyWithDefault<unique_ptr<HyperLogLog>>(102, "log");
419349 auto result = duckdb::unique_ptr<DistinctStatistics>(new DistinctStatistics(std::move(log), sample_count, total_count));
419350 return result;
419351}

◆ UpdateInternal()

void duckdb::DistinctStatistics::UpdateInternal ( Vector & update,
idx_t count,
Vector & hashes )
private
423373 {
423374 sample_count += count;
423375 VectorOperations::Hash(new_data, hashes, count);
423376
423377 log->Update(new_data, hashes, count);
423378}

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