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_physical_expr::intervals::{Interval, NullableInterval};
use datafusion_common::ScalarValue;
// [1, 2) U {NULL}
NullableInterval::MaybeNull {
values: Interval::make(Some(1), Some(2), (false, true)),
};
// (0, ∞)
NullableInterval::NotNull {
values: Interval::make(Some(0), None, (true, true)),
};
// {NULL}
NullableInterval::Null { datatype: DataType::Int32 };
// {4}
NullableInterval::from(ScalarValue::Int32(Some(4)));
Variants§
Null
The value is always null in this interval
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 in this interval. If it is non null its value is within the specified values interval
NotNull
The value is definitely not null in this interval and is within values
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 get_datatype(&self) -> Result<DataType>
pub fn get_datatype(&self) -> Result<DataType>
Get the data type
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::Operator;
use datafusion_physical_expr::intervals::{Interval, 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::make(Some(1), Some(3), (false, true)),
};
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::make(Some(1), Some(3), (false, false)),
};
let rhs = NullableInterval::NotNull {
values: Interval::make(Some(2), Some(4), (false, false)),
};
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>
Determine if this interval contains the given interval. Returns a boolean interval that is [true, true] if this interval is a superset of the given interval, [false, false] if this interval is disjoint from the given interval, and [false, true] otherwise.
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_physical_expr::intervals::{Interval, 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::make(Some(1), Some(4), (false, true)),
};
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 Default for NullableInterval
impl Default 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
source§fn eq(&self, other: &NullableInterval) -> bool
fn eq(&self, other: &NullableInterval) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for NullableInterval
impl StructuralEq for NullableInterval
impl StructuralPartialEq for NullableInterval
Auto Trait Implementations§
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.