Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(rust): One simplify expression module and keep utility local #18621

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions crates/polars-plan/src/plans/aexpr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,6 @@ impl AExpr {
pub(crate) fn is_leaf(&self) -> bool {
matches!(self, AExpr::Column(_) | AExpr::Literal(_) | AExpr::Len)
}
pub(crate) fn new_null_count(input: &[ExprIR]) -> Self {
AExpr::Function {
input: input.to_vec(),
function: FunctionExpr::NullCount,
options: FunctionOptions {
collect_groups: ApplyOptions::GroupWise,
fmt_str: "",
cast_to_supertypes: None,
check_lengths: UnsafeBool::default(),
flags: FunctionFlags::ALLOW_GROUP_AWARE | FunctionFlags::RETURNS_SCALAR,
},
}
}
}

impl IRAggExpr {
Expand Down
1 change: 0 additions & 1 deletion crates/polars-plan/src/plans/optimizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mod join_utils;
mod predicate_pushdown;
mod projection_pushdown;
mod simplify_expr;
mod simplify_functions;
mod slice_pushdown_expr;
mod slice_pushdown_lp;
mod stack_opt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
mod simplify_functions;

use polars_utils::floor_divmod::FloorDivMod;
use polars_utils::total_ord::ToTotalOrd;
use simplify_functions::optimize_functions;

use crate::plans::*;
use crate::prelude::optimizer::simplify_functions::optimize_functions;

fn new_null_count(input: &[ExprIR]) -> AExpr {
AExpr::Function {
input: input.to_vec(),
function: FunctionExpr::NullCount,
options: FunctionOptions {
collect_groups: ApplyOptions::GroupWise,
fmt_str: "",
cast_to_supertypes: None,
check_lengths: UnsafeBool::default(),
flags: FunctionFlags::ALLOW_GROUP_AWARE | FunctionFlags::RETURNS_SCALAR,
},
}
}

macro_rules! eval_binary_same_type {
($lhs:expr, $rhs:expr, |$l: ident, $r: ident| $ret: expr) => {{
Expand Down Expand Up @@ -457,7 +473,7 @@ impl OptimizationRule for SimplifyExprRule {
match expr_arena.get(drop_nulls_input_node) {
AExpr::Column(_) => Some(AExpr::BinaryExpr {
op: Operator::Minus,
right: expr_arena.add(AExpr::new_null_count(input)),
right: expr_arena.add(new_null_count(input)),
left: expr_arena.add(AExpr::Agg(IRAggExpr::Count(
drop_nulls_input_node,
true,
Expand All @@ -481,7 +497,7 @@ impl OptimizationRule for SimplifyExprRule {
input,
function: FunctionExpr::Boolean(BooleanFunction::IsNull),
options: _,
} => Some(AExpr::new_null_count(input)),
} => Some(new_null_count(input)),
AExpr::Function {
input,
function: FunctionExpr::Boolean(BooleanFunction::IsNotNull),
Expand All @@ -494,7 +510,7 @@ impl OptimizationRule for SimplifyExprRule {
match expr_arena.get(is_not_null_input_node) {
AExpr::Column(_) => Some(AExpr::BinaryExpr {
op: Operator::Minus,
right: expr_arena.add(AExpr::new_null_count(input)),
right: expr_arena.add(new_null_count(input)),
left: expr_arena.add(AExpr::Agg(IRAggExpr::Count(
is_not_null_input_node,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(super) fn optimize_functions(
function: FunctionExpr::Boolean(BooleanFunction::IsNull),
options: _,
} => Some(AExpr::BinaryExpr {
left: expr_arena.add(AExpr::new_null_count(input)),
left: expr_arena.add(new_null_count(input)),
op: Operator::Gt,
right: expr_arena.add(AExpr::Literal(LiteralValue::new_idxsize(0))),
}),
Expand All @@ -34,7 +34,7 @@ pub(super) fn optimize_functions(
match expr_arena.get(is_not_null_input_node) {
AExpr::Column(_) => Some(AExpr::BinaryExpr {
op: Operator::Lt,
left: expr_arena.add(AExpr::new_null_count(input)),
left: expr_arena.add(new_null_count(input)),
right: expr_arena.add(AExpr::Agg(IRAggExpr::Count(
is_not_null_input_node,
true,
Expand Down Expand Up @@ -66,7 +66,7 @@ pub(super) fn optimize_functions(
match expr_arena.get(is_null_input_node) {
AExpr::Column(_) => Some(AExpr::BinaryExpr {
op: Operator::Eq,
right: expr_arena.add(AExpr::new_null_count(input)),
right: expr_arena.add(new_null_count(input)),
left: expr_arena
.add(AExpr::Agg(IRAggExpr::Count(is_null_input_node, true))),
}),
Expand All @@ -81,7 +81,7 @@ pub(super) fn optimize_functions(
function: FunctionExpr::Boolean(BooleanFunction::IsNotNull),
options: _,
} => Some(AExpr::BinaryExpr {
left: expr_arena.add(AExpr::new_null_count(input)),
left: expr_arena.add(new_null_count(input)),
op: Operator::Eq,
right: expr_arena.add(AExpr::Literal(LiteralValue::new_idxsize(0))),
}),
Expand Down
Loading