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
pub const CERTAINLY_FALSE: Interval = _
pub const UNCERTAIN: Interval = _
pub const CERTAINLY_TRUE: 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_zero(data_type: &DataType) -> Result<Interval, DataFusionError>
pub fn make_zero(data_type: &DataType) -> Result<Interval, DataFusionError>
Creates a singleton zero interval if the datatype supported.
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 make_symmetric_unit_interval(
data_type: &DataType,
) -> Result<Interval, DataFusionError>
pub fn make_symmetric_unit_interval( data_type: &DataType, ) -> Result<Interval, DataFusionError>
Creates an interval between -1 to 1.
Sourcepub fn make_symmetric_pi_interval(
data_type: &DataType,
) -> Result<Interval, DataFusionError>
pub fn make_symmetric_pi_interval( data_type: &DataType, ) -> Result<Interval, DataFusionError>
Create an interval from -π to π.
Sourcepub fn make_symmetric_half_pi_interval(
data_type: &DataType,
) -> Result<Interval, DataFusionError>
pub fn make_symmetric_half_pi_interval( data_type: &DataType, ) -> Result<Interval, DataFusionError>
Create an interval from -π/2 to π/2.
Sourcepub fn make_non_negative_infinity_interval(
data_type: &DataType,
) -> Result<Interval, DataFusionError>
pub fn make_non_negative_infinity_interval( data_type: &DataType, ) -> Result<Interval, DataFusionError>
Create an interval from 0 to infinity.
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
.
Sourcepub fn gt<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn gt<T>(&self, other: T) -> Result<Interval, DataFusionError>
Decide if this interval is certainly greater than, possibly greater than,
or can’t be greater than 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 gt_eq<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn gt_eq<T>(&self, other: T) -> Result<Interval, DataFusionError>
Decide if this interval is certainly greater than or equal to, possibly
greater than or equal to, or can’t be greater than or equal to 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 lt<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn lt<T>(&self, other: T) -> Result<Interval, DataFusionError>
Decide if this interval is certainly less than, possibly less than, or
can’t be less than 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 lt_eq<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn lt_eq<T>(&self, other: T) -> Result<Interval, DataFusionError>
Decide if this interval is certainly less than or equal to, possibly
less than or equal to, or can’t be less than or equal to 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 equal<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn equal<T>(&self, other: T) -> Result<Interval, DataFusionError>
Decide if this interval is certainly equal to, possibly equal to, or
can’t be equal to 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 and<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn and<T>(&self, other: T) -> Result<Interval, DataFusionError>
Compute the logical conjunction of this (boolean) interval with the given boolean interval.
Sourcepub fn or<T>(&self, other: T) -> Result<Interval, DataFusionError>
pub fn or<T>(&self, other: T) -> Result<Interval, DataFusionError>
Compute the logical disjunction of this boolean interval with the given boolean interval.
Sourcepub fn not(&self) -> Result<Interval, DataFusionError>
pub fn not(&self) -> Result<Interval, DataFusionError>
Compute the logical negation of this (boolean) 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
.
Sourcepub fn arithmetic_negate(self) -> Result<Interval, DataFusionError>
pub fn arithmetic_negate(self) -> Result<Interval, DataFusionError>
Reflects an Interval
around the point zero.
This method computes the arithmetic negation of the interval, reflecting it about the origin of the number line. This operation swaps and negates the lower and upper bounds of the interval.
Trait Implementations§
impl Eq for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl Freeze for Interval
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more