pub enum NullableInterval {
Null {
datatype: DataType,
},
MaybeNull {
values: Interval,
},
NotNull {
values: Interval,
},
}Expand description
An Interval that also tracks null status using a boolean interval.
This represents values that may be in a particular range or be null.
§Examples
use arrow::datatypes::DataType;
use datafusion_common::ScalarValue;
use datafusion_expr_common::interval_arithmetic::Interval;
use datafusion_expr_common::interval_arithmetic::NullableInterval;
// [1, 2) U {NULL}
let maybe_null = NullableInterval::MaybeNull {
values: Interval::try_new(
ScalarValue::Int32(Some(1)),
ScalarValue::Int32(Some(2)),
)
.unwrap(),
};
// (0, ∞)
let not_null = NullableInterval::NotNull {
values: Interval::try_new(ScalarValue::Int32(Some(0)), ScalarValue::Int32(None))
.unwrap(),
};
// {NULL}
let null_interval = NullableInterval::Null {
datatype: DataType::Int32,
};
// {4}
let single_value = NullableInterval::from(ScalarValue::Int32(Some(4)));Variants§
Null
The value is always null. This is typed so it can be used in physical expressions, which don’t do type coercion.
MaybeNull
The value may or may not be null. If it is non-null, its is within the specified range.
NotNull
The value is definitely not null, and is within the specified range.
Implementations§
Source§impl NullableInterval
impl NullableInterval
Sourcepub const FALSE: NullableInterval
pub const FALSE: NullableInterval
An interval containing only the ‘false’ truth value. This interval is semantically equivalent to Interval::FALSE.
Sourcepub const TRUE: NullableInterval
pub const TRUE: NullableInterval
An interval containing only the ‘true’ truth value. This interval is semantically equivalent to Interval::TRUE.
Sourcepub const UNKNOWN: NullableInterval
pub const UNKNOWN: NullableInterval
An interval containing only the ‘unknown’ truth value.
Sourcepub const TRUE_OR_FALSE: NullableInterval
pub const TRUE_OR_FALSE: NullableInterval
An interval containing both the ‘true’, and ‘false’ truth values. This interval is semantically equivalent to Interval::TRUE_OR_FALSE.
Sourcepub const TRUE_OR_UNKNOWN: NullableInterval
pub const TRUE_OR_UNKNOWN: NullableInterval
An interval containing both the ‘true’ and ‘unknown’ truth values.
Sourcepub const FALSE_OR_UNKNOWN: NullableInterval
pub const FALSE_OR_UNKNOWN: NullableInterval
An interval containing both the ‘false’ and ‘unknown’ truth values.
Sourcepub const ANY_TRUTH_VALUE: NullableInterval
pub const ANY_TRUTH_VALUE: NullableInterval
An interval that contains all possible truth values: ‘true’, ‘false’ and ‘unknown’.
Sourcepub fn values(&self) -> Option<&Interval>
pub fn values(&self) -> Option<&Interval>
Get the values interval, or None if this interval is definitely null.
Sourcepub fn is_certainly_true(&self) -> bool
pub fn is_certainly_true(&self) -> bool
Return true if the value is definitely true (and not null).
Sourcepub fn is_true(&self) -> Result<NullableInterval, DataFusionError>
pub fn is_true(&self) -> Result<NullableInterval, DataFusionError>
Returns the set of possible values after applying the is true test on all
values in this set.
The resulting set can only contain ‘TRUE’ and/or ‘FALSE’, never ‘UNKNOWN’.
Sourcepub fn is_certainly_false(&self) -> bool
pub fn is_certainly_false(&self) -> bool
Return true if the value is definitely false (and not null).
Sourcepub fn is_false(&self) -> Result<NullableInterval, DataFusionError>
pub fn is_false(&self) -> Result<NullableInterval, DataFusionError>
Returns the set of possible values after applying the is false test on all
values in this set.
The resulting set can only contain ‘TRUE’ and/or ‘FALSE’, never ‘UNKNOWN’.
Sourcepub fn is_certainly_unknown(&self) -> bool
pub fn is_certainly_unknown(&self) -> bool
Return true if the value is definitely null (and not true or false).
Sourcepub fn is_unknown(&self) -> Result<NullableInterval, DataFusionError>
pub fn is_unknown(&self) -> Result<NullableInterval, DataFusionError>
Returns the set of possible values after applying the is unknown test on all
values in this set.
The resulting set can only contain ‘TRUE’ and/or ‘FALSE’, never ‘UNKNOWN’.
Sourcepub fn not(&self) -> Result<NullableInterval, DataFusionError>
pub fn not(&self) -> Result<NullableInterval, DataFusionError>
Returns an interval representing the set of possible values after applying SQL three-valued logical NOT on possible value in this interval.
This method uses the following truth table.
A | ¬A
----|----
F | T
U | U
T | FSourcepub fn and<T>(&self, rhs: T) -> Result<NullableInterval, DataFusionError>where
T: Borrow<NullableInterval>,
pub fn and<T>(&self, rhs: T) -> Result<NullableInterval, DataFusionError>where
T: Borrow<NullableInterval>,
Returns an interval representing the set of possible values after applying SQL
three-valued logical AND on each combination of possible values from self and other.
This method uses the following truth table.
│ B
A ∧ B ├──────
│ F U T
──┬───┼──────
│ F │ F F F
A │ U │ F U U
│ T │ F U TSourcepub fn or<T>(&self, rhs: T) -> Result<NullableInterval, DataFusionError>where
T: Borrow<NullableInterval>,
pub fn or<T>(&self, rhs: T) -> Result<NullableInterval, DataFusionError>where
T: Borrow<NullableInterval>,
Returns an interval representing the set of possible values after applying SQL three-valued
logical OR on each combination of possible values from self and other.
This method uses the following truth table.
│ B
A ∨ B ├──────
│ F U T
──┬───┼──────
│ F │ F U T
A │ U │ U U T
│ T │ T T TSourcepub fn apply_operator(
&self,
op: &Operator,
rhs: &NullableInterval,
) -> Result<NullableInterval, DataFusionError>
pub fn apply_operator( &self, op: &Operator, rhs: &NullableInterval, ) -> Result<NullableInterval, DataFusionError>
Apply the given operator to this interval and the given interval.
§Examples
use datafusion_common::ScalarValue;
use datafusion_expr_common::interval_arithmetic::Interval;
use datafusion_expr_common::interval_arithmetic::NullableInterval;
use datafusion_expr_common::operator::Operator;
// 4 > 3 -> true
let lhs = NullableInterval::from(ScalarValue::Int32(Some(4)));
let rhs = NullableInterval::from(ScalarValue::Int32(Some(3)));
let result = lhs.apply_operator(&Operator::Gt, &rhs).unwrap();
assert_eq!(
result,
NullableInterval::from(ScalarValue::Boolean(Some(true)))
);
// [1, 3) > NULL -> NULL
let lhs = NullableInterval::NotNull {
values: Interval::try_new(
ScalarValue::Int32(Some(1)),
ScalarValue::Int32(Some(3)),
)
.unwrap(),
};
let rhs = NullableInterval::from(ScalarValue::Int32(None));
let result = lhs.apply_operator(&Operator::Gt, &rhs).unwrap();
assert_eq!(result.single_value(), Some(ScalarValue::Boolean(None)));
// [1, 3] > [2, 4] -> [false, true]
let lhs = NullableInterval::NotNull {
values: Interval::try_new(
ScalarValue::Int32(Some(1)),
ScalarValue::Int32(Some(3)),
)
.unwrap(),
};
let rhs = NullableInterval::NotNull {
values: Interval::try_new(
ScalarValue::Int32(Some(2)),
ScalarValue::Int32(Some(4)),
)
.unwrap(),
};
let result = lhs.apply_operator(&Operator::Gt, &rhs).unwrap();
// Both inputs are valid (non-null), so result must be non-null
assert_eq!(
result,
NullableInterval::NotNull {
// Uncertain whether inequality is true or false
values: Interval::TRUE_OR_FALSE,
}
);Sourcepub fn contains<T>(&self, other: T) -> Result<NullableInterval, DataFusionError>where
T: Borrow<NullableInterval>,
pub fn contains<T>(&self, other: T) -> Result<NullableInterval, DataFusionError>where
T: Borrow<NullableInterval>,
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 contains_value<T>(&self, value: T) -> Result<bool, DataFusionError>where
T: Borrow<ScalarValue>,
pub fn contains_value<T>(&self, value: T) -> Result<bool, DataFusionError>where
T: Borrow<ScalarValue>,
Determines if this interval contains a ScalarValue or not.
Sourcepub fn single_value(&self) -> Option<ScalarValue>
pub fn single_value(&self) -> Option<ScalarValue>
If the interval has collapsed to a single value, return that value.
Otherwise, returns None.
§Examples
use datafusion_common::ScalarValue;
use datafusion_expr_common::interval_arithmetic::Interval;
use datafusion_expr_common::interval_arithmetic::NullableInterval;
let interval = NullableInterval::from(ScalarValue::Int32(Some(4)));
assert_eq!(interval.single_value(), Some(ScalarValue::Int32(Some(4))));
let interval = NullableInterval::from(ScalarValue::Int32(None));
assert_eq!(interval.single_value(), Some(ScalarValue::Int32(None)));
let interval = NullableInterval::MaybeNull {
values: Interval::try_new(
ScalarValue::Int32(Some(1)),
ScalarValue::Int32(Some(4)),
)
.unwrap(),
};
assert_eq!(interval.single_value(), None);Trait Implementations§
Source§impl Clone for NullableInterval
impl Clone for NullableInterval
Source§fn clone(&self) -> NullableInterval
fn clone(&self) -> NullableInterval
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NullableInterval
impl Debug for NullableInterval
Source§impl Display for NullableInterval
impl Display for NullableInterval
Source§impl From<ScalarValue> for NullableInterval
impl From<ScalarValue> for NullableInterval
Source§fn from(value: ScalarValue) -> NullableInterval
fn from(value: ScalarValue) -> NullableInterval
Create an interval that represents a single value.
Source§impl PartialEq for NullableInterval
impl PartialEq for NullableInterval
impl Eq for NullableInterval
impl StructuralPartialEq for NullableInterval
Auto Trait Implementations§
impl Freeze for NullableInterval
impl !RefUnwindSafe for NullableInterval
impl Send for NullableInterval
impl Sync for NullableInterval
impl Unpin for NullableInterval
impl !UnwindSafe for NullableInterval
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§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