Struct datafusion::logical_expr::interval_arithmetic::Interval
source · pub struct Interval { /* private fields */ }
Expand description
The Interval
type represents a closed interval used for computing
reliable bounds for mathematical expressions.
Conventions:
-
Closed bounds: The interval always encompasses its endpoints. We accommodate operations resulting in open intervals by incrementing or decrementing the interval endpoint value to its successor/predecessor.
-
Unbounded endpoints: If the
lower
orupper
bounds are indeterminate, they are labeled as unbounded. This is represented using aNULL
. -
Overflow handling: If the
lower
orupper
endpoints exceed their limits after any operation, they either become unbounded or they are fixed to the maximum/minimum value of the datatype, depending on the direction of the overflowing endpoint, opting for the safer choice. -
Floating-point special cases:
INF
values are converted toNULL
s while constructing an interval to ensure consistency, with other data types.NaN
(Not a Number) results are conservatively result in unbounded endpoints.
Implementations§
source§impl Interval
impl Interval
sourcepub fn try_new(
lower: ScalarValue,
upper: ScalarValue
) -> Result<Interval, DataFusionError>
pub fn try_new( lower: ScalarValue, upper: ScalarValue ) -> Result<Interval, DataFusionError>
Attempts to create a new Interval
from the given lower and upper bounds.
Notes
This constructor creates intervals in a “canonical” form where:
- Boolean intervals:
- Unboundedness (
NULL
) for boolean endpoints is converted tofalse
for lower andtrue
for upper bounds.
- Unboundedness (
- Floating-point intervals:
- Floating-point endpoints with
NaN
,INF
, orNEG_INF
are converted toNULL
s.
- Floating-point endpoints with
sourcepub fn make<T>(
lower: Option<T>,
upper: Option<T>
) -> Result<Interval, DataFusionError>
pub fn make<T>( lower: Option<T>, upper: Option<T> ) -> Result<Interval, DataFusionError>
Convenience function to create a new Interval
from the given (optional)
bounds, for use in tests only. Absence of either endpoint indicates
unboundedness on that side. See Interval::try_new
for more information.
sourcepub fn make_unbounded(data_type: &DataType) -> Result<Interval, DataFusionError>
pub fn make_unbounded(data_type: &DataType) -> Result<Interval, DataFusionError>
Creates an unbounded interval from both sides if the datatype supported.
sourcepub fn lower(&self) -> &ScalarValue
pub fn lower(&self) -> &ScalarValue
Returns a reference to the lower bound.
sourcepub fn upper(&self) -> &ScalarValue
pub fn upper(&self) -> &ScalarValue
Returns a reference to the upper bound.
sourcepub fn into_bounds(self) -> (ScalarValue, ScalarValue)
pub fn into_bounds(self) -> (ScalarValue, ScalarValue)
Converts this Interval
into its boundary scalar values. It’s useful
when you need to work with the individual bounds directly.
sourcepub fn cast_to(
&self,
data_type: &DataType,
cast_options: &CastOptions<'_>
) -> Result<Interval, DataFusionError>
pub fn cast_to( &self, data_type: &DataType, cast_options: &CastOptions<'_> ) -> Result<Interval, DataFusionError>
Casts this interval to data_type
using cast_options
.
pub const CERTAINLY_FALSE: Interval = _
pub const UNCERTAIN: Interval = _
pub const CERTAINLY_TRUE: Interval = _
sourcepub fn intersect<T>(
&self,
other: T
) -> Result<Option<Interval>, DataFusionError>
pub fn intersect<T>( &self, other: T ) -> Result<Option<Interval>, DataFusionError>
Compute the intersection of this interval with the given interval.
If the intersection is empty, return None
.
NOTE: This function only works with intervals of the same data type. Attempting to compare intervals of different data types will lead to an error.
sourcepub fn contains_value<T>(&self, other: T) -> Result<bool, DataFusionError>where
T: Borrow<ScalarValue>,
pub fn contains_value<T>(&self, other: T) -> Result<bool, DataFusionError>where
T: Borrow<ScalarValue>,
Decide if this interval certainly contains, possibly contains, or can’t
contain a ScalarValue
(other
) by returning [true, true]
,
[false, true]
or [false, false]
respectively.
NOTE: This function only works with intervals of the same data type. Attempting to compare intervals of different data types will lead to an error.
sourcepub fn contains<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn contains<T>(&self, other: T) -> Result<Interval, DataFusionError>
Decide if this interval is a superset of, overlaps with, or
disjoint with other
by returning [true, true]
, [false, true]
or
[false, false]
respectively.
NOTE: This function only works with intervals of the same data type. Attempting to compare intervals of different data types will lead to an error.
sourcepub fn add<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn add<T>(&self, other: T) -> Result<Interval, DataFusionError>
Add the given interval (other
) to this interval. Say we have intervals
[a1, b1]
and [a2, b2]
, then their sum is [a1 + a2, b1 + b2]
. Note
that this represents all possible values the sum can take if one can
choose single values arbitrarily from each of the operands.
sourcepub fn sub<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn sub<T>(&self, other: T) -> Result<Interval, DataFusionError>
Subtract the given interval (other
) from this interval. Say we have
intervals [a1, b1]
and [a2, b2]
, then their difference is
[a1 - b2, b1 - a2]
. Note that this represents all possible values the
difference can take if one can choose single values arbitrarily from
each of the operands.
sourcepub fn mul<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn mul<T>(&self, other: T) -> Result<Interval, DataFusionError>
Multiply the given interval (other
) with this interval. Say we have
intervals [a1, b1]
and [a2, b2]
, then their product is [min(a1 * a2, a1 * b2, b1 * a2, b1 * b2), max(a1 * a2, a1 * b2, b1 * a2, b1 * b2)]
.
Note that this represents all possible values the product can take if
one can choose single values arbitrarily from each of the operands.
NOTE: This function only works with intervals of the same data type. Attempting to compare intervals of different data types will lead to an error.
sourcepub fn div<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn div<T>(&self, other: T) -> Result<Interval, DataFusionError>
Divide this interval by the given interval (other
). Say we have intervals
[a1, b1]
and [a2, b2]
, then their division is [a1, b1] * [1 / b2, 1 / a2]
if 0 ∉ [a2, b2]
and [NEG_INF, INF]
otherwise. Note that this represents
all possible values the quotient can take if one can choose single values
arbitrarily from each of the operands.
NOTE: This function only works with intervals of the same data type. Attempting to compare intervals of different data types will lead to an error.
TODO: Once interval sets are supported, cases where the divisor contains zero should result in an interval set, not the universal set.
sourcepub fn cardinality(&self) -> Option<u64>
pub fn cardinality(&self) -> Option<u64>
Returns the cardinality of this interval, which is the number of all
distinct points inside it. This function returns None
if:
- The interval is unbounded from either side, or
- Cardinality calculations for the datatype in question is not implemented yet, or
- An overflow occurs during the calculation: This case can only arise
when the calculated cardinality does not fit in an
u64
.
Trait Implementations§
source§impl PartialEq for Interval
impl PartialEq for Interval
impl Eq for Interval
impl StructuralEq for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl !RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl !UnwindSafe for Interval
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.