Skip to content

Commit 4c8011b

Browse files
committed
x
1 parent 259407c commit 4c8011b

6 files changed

Lines changed: 154 additions & 183 deletions

File tree

src/common/statistics/src/histogram.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ impl Histogram {
157157

158158
pub fn bucket_iter(&self) -> HistogramBucketIter<'_> {
159159
match self {
160-
Self::Int(histogram) => HistogramBucketIter::Int(histogram.buckets_iter()),
161-
Self::UInt(histogram) => HistogramBucketIter::UInt(histogram.buckets_iter()),
162-
Self::Float(histogram) => HistogramBucketIter::Float(histogram.buckets_iter()),
163-
Self::Bytes(histogram) => HistogramBucketIter::Bytes(histogram.buckets_iter()),
160+
Self::Int(histogram) => HistogramBucketIter::Int(histogram.buckets.iter()),
161+
Self::UInt(histogram) => HistogramBucketIter::UInt(histogram.buckets.iter()),
162+
Self::Float(histogram) => HistogramBucketIter::Float(histogram.buckets.iter()),
163+
Self::Bytes(histogram) => HistogramBucketIter::Bytes(histogram.buckets.iter()),
164164
}
165165
}
166166

src/common/statistics/src/typed_histogram.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ impl<T> TypedHistogram<T> {
9393
self.buckets.iter().map(|bucket| bucket.num_distinct).sum()
9494
}
9595

96-
pub fn buckets_iter(&self) -> std::slice::Iter<'_, TypedHistogramBucket<T>> {
97-
self.buckets.iter()
98-
}
99-
10096
pub fn scale_counts(&mut self, selectivity: f64) {
10197
for bucket in &mut self.buckets {
10298
bucket.num_values *= selectivity;
@@ -846,7 +842,7 @@ mod tests {
846842
fn test_typed_histogram_builder_preserves_max_bound_when_range_not_divisible() {
847843
let histogram =
848844
TypedHistogramBuilder::from_ndv(738, 738, Some((0_u64, 737_u64)), 100).unwrap();
849-
let buckets = histogram.buckets_iter().collect::<Vec<_>>();
845+
let buckets = histogram.buckets.iter().collect::<Vec<_>>();
850846

851847
assert_eq!(buckets.last().unwrap().upper_bound(), &737);
852848
}
@@ -855,7 +851,8 @@ mod tests {
855851
fn test_typed_histogram_builder_partitions_discrete_synthetic_bounds() {
856852
let histogram = TypedHistogramBuilder::from_ndv(10, 10, Some((0_u64, 9_u64)), 10).unwrap();
857853
let bounds = histogram
858-
.buckets_iter()
854+
.buckets
855+
.iter()
859856
.map(|bucket| (*bucket.lower_bound(), *bucket.upper_bound()))
860857
.collect::<Vec<_>>();
861858

src/common/statistics/src/typed_histogram/join.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl<T: Value> TypedHistogram<T> {
4747
pub fn estimate_join(&self, other: &TypedHistogram<T>) -> JoinEstimation {
4848
let mut estimation = JoinEstimation::zero();
4949

50-
for left_bucket in self.buckets_iter() {
51-
for right_bucket in other.buckets_iter() {
50+
for left_bucket in &self.buckets {
51+
for right_bucket in &other.buckets {
5252
estimation = estimation.add(left_bucket.estimate_join_contribution(right_bucket));
5353
}
5454
}

src/query/expression/src/function/stat_distribution.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub use databend_common_statistics::Ndv;
1818
use crate::Domain;
1919
use crate::Scalar;
2020
use crate::types::DataType;
21+
use crate::types::boolean::BooleanDomain;
2122
use crate::types::nullable::NullableDomain;
2223

2324
#[derive(Debug, Clone)]
@@ -105,6 +106,18 @@ impl<'a> ArgStat<'a> {
105106
}
106107

107108
impl ReturnStat {
109+
pub fn boolean(true_count: StatEstimate) -> Self {
110+
Self {
111+
domain: Domain::Boolean(BooleanDomain {
112+
has_true: true,
113+
has_false: true,
114+
}),
115+
ndv: Ndv::Stat(2.0),
116+
null_count: 0,
117+
distribution: OwnedDistribution::Boolean(BooleanDistribution { true_count }),
118+
}
119+
}
120+
108121
pub fn histogram(&self) -> Option<&Histogram> {
109122
self.distribution.as_histogram()
110123
}
@@ -297,9 +310,3 @@ impl StatEstimate {
297310
pub struct BooleanDistribution {
298311
pub true_count: StatEstimate,
299312
}
300-
301-
impl BooleanDistribution {
302-
pub fn new(true_count: StatEstimate) -> Self {
303-
Self { true_count }
304-
}
305-
}

0 commit comments

Comments
 (0)