Skip to content

Commit ed5d432

Browse files
committed
add change
1 parent 314acd5 commit ed5d432

1 file changed

Lines changed: 32 additions & 14 deletions

File tree

datafusion/common/src/stats.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use arrow::datatypes::{DataType, Schema};
2727

2828
/// Represents a value with a degree of certainty. `Precision` is used to
2929
/// propagate information the precision of statistical values.
30-
#[derive(Clone, PartialEq, Eq, Default, Copy)]
31-
pub enum Precision<T: Debug + Clone + PartialEq + Eq + PartialOrd> {
30+
#[derive(Clone, Default, Copy)]
31+
pub enum Precision<T: Debug + Clone> {
3232
/// The exact value is known. Used for guaranteeing correctness.
3333
///
3434
/// Comes from definitive sources such as:
@@ -60,7 +60,7 @@ pub enum Precision<T: Debug + Clone + PartialEq + Eq + PartialOrd> {
6060
Absent,
6161
}
6262

63-
impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Precision<T> {
63+
impl<T: Debug + Clone> Precision<T> {
6464
/// If we have some value (exact or inexact), it returns that value.
6565
/// Otherwise, it returns `None`.
6666
pub fn get_value(&self) -> Option<&T> {
@@ -75,7 +75,7 @@ impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Precision<T> {
7575
pub fn map<U, F>(self, f: F) -> Precision<U>
7676
where
7777
F: Fn(T) -> U,
78-
U: Debug + Clone + PartialEq + Eq + PartialOrd,
78+
U: Debug + Clone,
7979
{
8080
match self {
8181
Precision::Exact(val) => Precision::Exact(f(val)),
@@ -94,6 +94,16 @@ impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Precision<T> {
9494
}
9595
}
9696

97+
/// Demotes the precision state from exact to inexact (if present).
98+
pub fn to_inexact(self) -> Self {
99+
match self {
100+
Precision::Exact(value) => Precision::Inexact(value),
101+
_ => self,
102+
}
103+
}
104+
}
105+
106+
impl<T: Debug + Clone + PartialOrd> Precision<T> {
97107
/// Returns the maximum of two (possibly inexact) values, conservatively
98108
/// propagating exactness information. If one of the input values is
99109
/// [`Precision::Absent`], the result is `Absent` too.
@@ -127,14 +137,6 @@ impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Precision<T> {
127137
(_, _) => Precision::Absent,
128138
}
129139
}
130-
131-
/// Demotes the precision state from exact to inexact (if present).
132-
pub fn to_inexact(self) -> Self {
133-
match self {
134-
Precision::Exact(value) => Precision::Inexact(value),
135-
_ => self,
136-
}
137-
}
138140
}
139141

140142
impl Precision<usize> {
@@ -318,7 +320,23 @@ impl Precision<ScalarValue> {
318320
}
319321
}
320322

321-
impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Debug for Precision<T> {
323+
impl<T: Debug + Clone> PartialEq for Precision<T>
324+
where
325+
T: PartialEq,
326+
{
327+
fn eq(&self, other: &Self) -> bool {
328+
match (self, other) {
329+
(Precision::Exact(a), Precision::Exact(b)) => a == b,
330+
(Precision::Inexact(a), Precision::Inexact(b)) => a == b,
331+
(Precision::Absent, Precision::Absent) => true,
332+
_ => false,
333+
}
334+
}
335+
}
336+
337+
impl<T: Debug + Clone + Eq> Eq for Precision<T> {}
338+
339+
impl<T: Debug + Clone> Debug for Precision<T> {
322340
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
323341
match self {
324342
Precision::Exact(inner) => write!(f, "Exact({inner:?})"),
@@ -328,7 +346,7 @@ impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Debug for Precision<T> {
328346
}
329347
}
330348

331-
impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Display for Precision<T> {
349+
impl<T: Debug + Clone> Display for Precision<T> {
332350
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
333351
match self {
334352
Precision::Exact(inner) => write!(f, "Exact({inner:?})"),

0 commit comments

Comments
 (0)