Skip to content

Commit

Permalink
fix bug in predicate pushdown of binary predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 29, 2022
1 parent a9752d3 commit 058a8e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions polars/polars-lazy/src/logical_plan/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ make_literal!(u64, UInt64);

/// The literal Null
pub struct Null {}
pub const NULL: Null = Null {};

impl Literal for Null {
fn lit(self) -> Expr {
Expand Down
16 changes: 16 additions & 0 deletions polars/polars-lazy/src/tests/predicate_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,19 @@ fn test_pass_unrelated_apply() -> Result<()> {

Ok(())
}

#[test]
fn filter_added_column_issue_2470() -> Result<()> {
let df = fruits_cars();

// the binary expression in the predicate lead to an incorrect pushdown because the rhs
// was not checked on the schema.
let out = df
.lazy()
.select([col("A"), lit(NULL).alias("foo")])
.filter(col("A").gt(lit(2i32)).and(col("foo").is_null()))
.collect()?;
assert_eq!(out.shape(), (3, 2));

Ok(())
}
12 changes: 3 additions & 9 deletions polars/polars-lazy/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,9 @@ pub(crate) fn check_input_node(
input_schema: &Schema,
expr_arena: &Arena<AExpr>,
) -> bool {
// first determine output field, and then check if that output field could be selected
// on the input schema.
match expr_arena
.get(node)
.to_field(input_schema, Context::Default, expr_arena)
{
Ok(output_expr) => input_schema.field_with_name(output_expr.name()).is_ok(),
Err(_) => false,
}
aexpr_to_root_names(node, expr_arena)
.iter()
.all(|name| input_schema.index_of(name).is_ok())
}

pub(crate) fn aexprs_to_schema(
Expand Down

0 comments on commit 058a8e1

Please sign in to comment.