Skip to content

Commit f5092b6

Browse files
committed
fixup tests
1 parent 8248ca5 commit f5092b6

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

datafusion-examples/examples/expr_api.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn boundary_analysis_in_conjuctions_demo() -> Result<()> {
424424
//
425425
// But `AND` conjunctions are easier to reason with because their interval
426426
// arithmetic follows naturally from set intersection operations, let us
427-
// now look at an example that is a tad more complicated `OR` conjunctions.
427+
// now look at an example that is a tad more complicated `OR` disjunctions.
428428

429429
// The expression we will look at is `age > 60 OR age <= 18`.
430430
let age_greater_than_60_less_than_18 =
@@ -435,7 +435,7 @@ fn boundary_analysis_in_conjuctions_demo() -> Result<()> {
435435
//
436436
// Initial range: [14, 79] as described in our column statistics.
437437
//
438-
// From the left-hand side and right-hand side of our `OR` conjunctions
438+
// From the left-hand side and right-hand side of our `OR` disjunctions
439439
// we end up with two ranges, instead of just one.
440440
//
441441
// - age > 60: [61, 79]
@@ -446,7 +446,8 @@ fn boundary_analysis_in_conjuctions_demo() -> Result<()> {
446446
let physical_expr = SessionContext::new()
447447
.create_physical_expr(age_greater_than_60_less_than_18, &df_schema)?;
448448

449-
// Since we don't handle interval arithmetic for `OR` operator this will error out.
449+
// However, analysis only supports a single interval, so we don't yet deal
450+
// with the multiple possibilities of the `OR` disjunctions.
450451
let analysis = analyze(
451452
&physical_expr,
452453
AnalysisContext::new(initial_boundaries),

datafusion/physical-expr/src/analysis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl ExprBoundaries {
100100
) -> Result<Self> {
101101
let field = schema.fields().get(col_index).ok_or_else(|| {
102102
internal_datafusion_err!(
103-
"Could not create `ExprBoundaries`: in `try_from_column` `col_index`
103+
"Could not create `ExprBoundaries`: in `try_from_column` `col_index`
104104
has gone out of bounds with a value of {col_index}, the schema has {} columns.",
105105
schema.fields.len()
106106
)
@@ -425,7 +425,7 @@ mod tests {
425425
fn test_analyze_invalid_boundary_exprs() {
426426
let schema = Arc::new(Schema::new(vec![make_field("a", DataType::Int32)]));
427427
let expr = col("a").lt(lit(10)).or(col("a").gt(lit(20)));
428-
let expected_error = "Interval arithmetic does not support the operator OR";
428+
let expected_error = "OR operator cannot yet propagate true intervals";
429429
let boundaries = ExprBoundaries::try_new_unbounded(&schema).unwrap();
430430
let df_schema = DFSchema::try_from(Arc::clone(&schema)).unwrap();
431431
let physical_expr =

datafusion/physical-expr/src/expressions/binary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl PhysicalExpr for BinaryExpr {
516516
}
517517
} else if self.op.eq(&Operator::Or) {
518518
if interval.eq(&Interval::CERTAINLY_FALSE) {
519-
// A certainly false logical conjunction can only derive from certainly
519+
// A certainly false logical disjunction can only derive from certainly
520520
// false operands. Otherwise, we prove infeasibility.
521521
Ok((!left_interval.eq(&Interval::CERTAINLY_TRUE)
522522
&& !right_interval.eq(&Interval::CERTAINLY_TRUE))

datafusion/physical-expr/src/intervals/cp_solver.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ use std::sync::Arc;
148148
use super::utils::{
149149
convert_duration_type_to_interval, convert_interval_type_to_duration, get_inverse_op,
150150
};
151-
use crate::expressions::Literal;
151+
use crate::expressions::{BinaryExpr, Literal};
152152
use crate::utils::{build_dag, ExprTreeNode};
153153
use crate::PhysicalExpr;
154154

155155
use arrow::datatypes::{DataType, Schema};
156-
use datafusion_common::{internal_err, Result};
156+
use datafusion_common::{internal_err, not_impl_err, Result};
157157
use datafusion_expr::interval_arithmetic::{apply_operator, satisfy_greater, Interval};
158158
use datafusion_expr::Operator;
159159

@@ -645,6 +645,17 @@ impl ExprIntervalGraph {
645645
.map(|child| self.graph[*child].interval())
646646
.collect::<Vec<_>>();
647647
let node_interval = self.graph[node].interval();
648+
// Special case: true OR could in principle be propagated by 3 interval sets,
649+
// (i.e. left true, or right true, or both true) however we do not support this yet.
650+
if node_interval == &Interval::CERTAINLY_TRUE
651+
&& self.graph[node]
652+
.expr
653+
.as_any()
654+
.downcast_ref::<BinaryExpr>()
655+
.is_some_and(|expr| expr.op() == &Operator::Or)
656+
{
657+
return not_impl_err!("OR operator cannot yet propagate true intervals");
658+
}
648659
let propagated_intervals = self.graph[node]
649660
.expr
650661
.propagate_constraints(node_interval, &children_intervals)?;

0 commit comments

Comments
 (0)