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 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_certainly_false(&self) -> bool
pub fn is_certainly_false(&self) -> bool
Return true if the value is definitely false (and not null).
Sourcepub fn apply_operator(&self, op: &Operator, rhs: &Self) -> Result<Self>
pub fn apply_operator(&self, op: &Operator, rhs: &Self) -> Result<Self>
Apply the given operator to this interval and the given interval.
§Examples
use datafusion_common::ScalarValue;
use datafusion_expr_common::operator::Operator;
use datafusion_expr_common::interval_arithmetic::Interval;
use datafusion_expr_common::interval_arithmetic::NullableInterval;
// 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::UNCERTAIN,
});
Sourcepub fn contains<T: Borrow<Self>>(&self, other: T) -> Result<Self>
pub fn contains<T: Borrow<Self>>(&self, other: T) -> Result<Self>
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 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) -> Self
fn from(value: ScalarValue) -> Self
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§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