Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ch-sc committed Jan 3, 2025
1 parent 844569f commit 4a51126
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
17 changes: 12 additions & 5 deletions datafusion/expr/src/interval_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,14 @@ fn sub_bounds<const UPPER: bool>(
rhs: &ScalarValue,
) -> ScalarValue {
if lhs.is_null() || rhs.is_null() {
return ScalarValue::try_from(dt).unwrap();
return Interval::make_unbounded(dt).unwrap().lower;
// return ScalarValue::try_from(dt).unwrap();
// } else if lhs.is_null() && dt.is_unsigned_integer() {
// // null values for lower bounds are set to zero:
// let sanitized_lower = ScalarValue::new_zero(dt).unwrap();
// return sub_bounds::<UPPER>(dt, &sanitized_lower, rhs);
// } else if rhs.is_null() {
// return sub_bounds::<UPPER>(dt, lhs, &ScalarValue::new_zero(dt).unwrap());
}

match dt {
Expand Down Expand Up @@ -1032,14 +1039,14 @@ fn handle_overflow<const UPPER: bool>(
}
}

// This function should remain private since it may corrupt the an interval if
// This function should remain private since it may corrupt an interval if
// used without caution.
fn next_value(value: ScalarValue) -> ScalarValue {
use ScalarValue::*;
value_transition!(MAX, true, value)
}

// This function should remain private since it may corrupt the an interval if
// This function should remain private since it may corrupt an interval if
// used without caution.
fn prev_value(value: ScalarValue) -> ScalarValue {
use ScalarValue::*;
Expand All @@ -1049,10 +1056,10 @@ fn prev_value(value: ScalarValue) -> ScalarValue {
trait OneTrait: Sized + std::ops::Add + std::ops::Sub {
fn one() -> Self;
}
macro_rules! impl_OneTrait{
macro_rules! impl_one_trait {
($($m:ty),*) => {$( impl OneTrait for $m { fn one() -> Self { 1 as $m } })*}
}
impl_OneTrait! {u8, u16, u32, u64, i8, i16, i32, i64, i128}
impl_one_trait! {u8, u16, u32, u64, i8, i16, i32, i64, i128}

impl OneTrait for IntervalDayTime {
fn one() -> Self {
Expand Down
28 changes: 28 additions & 0 deletions datafusion/physical-expr/src/expressions/in_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use datafusion_common::{exec_err, internal_err, not_impl_err, Result, ScalarValu
use datafusion_expr::ColumnarValue;

use ahash::RandomState;
use datafusion_expr::interval_arithmetic::Interval;
use hashbrown::hash_map::RawEntryMut;
use hashbrown::HashMap;

Expand Down Expand Up @@ -401,6 +402,33 @@ impl PhysicalExpr for InListExpr {
self.list.hash(&mut s);
// Add `self.static_filter` when hash is available
}

/// Computes the output interval for the `InListExpr` expression,
/// given the input intervals.
///
/// ```text
/// Full interval range of expr: ....---------------------....
/// Some list items: .....|.......|.....|.|.......
/// New interval range: .....|---------------|.......
/// ```
///
/// If `negated` is true, the expr's interval range is returned.
fn evaluate_bounds(&self, children: &[&Interval]) -> Result<Interval> {
// children[0]: expr bounds
// children[1..]: list item bounds
let expr_bounds = children[0];
if self.negated {
return Ok(expr_bounds.clone());
}

let list_bound = children[1..]
.iter()
.try_fold(Some(children[1].clone()), |acc, item| {
acc.expect("children[1] must not be absent").union(*item)
})?;

Ok(list_bound.unwrap_or(Interval::make_unbounded(&expr_bounds.data_type())?))
}
}

impl PartialEq<dyn Any> for InListExpr {
Expand Down

0 comments on commit 4a51126

Please sign in to comment.