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::interval_arithmetic::Interval;
use datafusion_expr::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::Operator;
use datafusion_expr::interval_arithmetic::Interval;
use datafusion_expr::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::interval_arithmetic::Interval;
use datafusion_expr::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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default 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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.