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

Fields

§datatype: DataType

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

Fields

§values: Interval

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

Fields

§values: Interval

The value is definitely not null in this interval and is within values

Implementations§

source§

impl NullableInterval

source

pub fn values(&self) -> Option<&Interval>

Get the values interval, or None if this interval is definitely null.

source

pub fn get_datatype(&self) -> Result<DataType>

Get the data type

source

pub fn is_certainly_true(&self) -> bool

Return true if the value is definitely true (and not null).

source

pub fn is_certainly_false(&self) -> bool

Return true if the value is definitely false (and not null).

source

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,
});
source

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.

source

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

source§

fn clone(&self) -> NullableInterval

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NullableInterval

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for NullableInterval

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for NullableInterval

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<ScalarValue> for NullableInterval

source§

fn from(value: ScalarValue) -> Self

Create an interval that represents a single value.

source§

impl PartialEq for NullableInterval

source§

fn eq(&self, other: &NullableInterval) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for NullableInterval

source§

impl StructuralEq for NullableInterval

source§

impl StructuralPartialEq for NullableInterval

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Allocation for Twhere T: RefUnwindSafe + Send + Sync,