Skip to content

Commit 93d2a55

Browse files
committed
fix: incorrect results when using NOT physical expression in physical_expr::analyze
Fixes apache#19264
1 parent 81f7a87 commit 93d2a55

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎datafusion/physical-expr/src/analysis.rs‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,14 @@ mod tests {
297297
use std::sync::Arc;
298298

299299
use arrow::datatypes::{DataType, Field, Schema};
300-
use datafusion_common::{DFSchema, assert_contains};
300+
use datafusion_common::stats::Precision;
301+
use datafusion_common::{DFSchema, Result, ScalarValue, assert_contains};
301302
use datafusion_expr::{
302303
Expr, col, execution_props::ExecutionProps, interval_arithmetic::Interval, lit,
303304
};
304305

305306
use crate::{AnalysisContext, create_physical_expr};
307+
use crate::expressions::Column;
306308

307309
use super::{ExprBoundaries, analyze};
308310

@@ -435,4 +437,39 @@ mod tests {
435437
.unwrap_err();
436438
assert_contains!(analysis_error.to_string(), expected_error);
437439
}
440+
441+
#[test]
442+
fn analyze_not_eq_around() -> Result<()> {
443+
let schema = Arc::new(Schema::new(vec![make_field("a", DataType::Float32)]));
444+
let boundaries = vec![ExprBoundaries {
445+
column: Column::new("a", 0),
446+
interval: Some(Interval::try_new(
447+
ScalarValue::Float32(Some(-1.0)),
448+
ScalarValue::Float32(Some(1.0)),
449+
)?),
450+
distinct_count: Precision::Absent,
451+
}];
452+
453+
// NOT (a = 0.0)
454+
let pred_not_eq = datafusion_expr::not(col("a").eq(lit(0.0f32)));
455+
456+
let df_schema = DFSchema::try_from(Arc::clone(&schema))?;
457+
let physical_expr =
458+
create_physical_expr(&pred_not_eq, &df_schema, &ExecutionProps::new())?;
459+
460+
let out_not_eq = analyze(
461+
&physical_expr,
462+
AnalysisContext::new(boundaries),
463+
df_schema.as_ref(),
464+
)?;
465+
466+
let actual = out_not_eq.boundaries[0].interval.clone();
467+
let expected = Some(Interval::try_new(
468+
ScalarValue::Float32(Some(-1.0)),
469+
ScalarValue::Float32(Some(1.0)),
470+
)?);
471+
472+
assert_eq!(expected, actual);
473+
Ok(())
474+
}
438475
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub fn propagate_comparison(
364364
match op {
365365
Operator::Eq => {
366366
// TODO: Propagation is not possible until we support interval sets.
367-
Ok(None)
367+
Ok(Some((left_child.clone(), right_child.clone())))
368368
}
369369
Operator::Gt => satisfy_greater(right_child, left_child, false),
370370
Operator::GtEq => satisfy_greater(right_child, left_child, true),

0 commit comments

Comments
 (0)