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

minor: Use Operator::swap #4092

Merged
merged 2 commits into from
Nov 3, 2022
Merged
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
21 changes: 10 additions & 11 deletions datafusion/core/src/physical_optimizer/pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl<'a> PruningExpressionBuilder<'a> {
let (column_expr, scalar_expr, columns, correct_operator) =
match (left_columns.len(), right_columns.len()) {
(1, 0) => (left, right, left_columns, op),
(0, 1) => (right, left, right_columns, reverse_operator(op)),
(0, 1) => (right, left, right_columns, reverse_operator(op)?),
_ => {
// if more than one column used in expression - not supported
return Err(DataFusionError::Plan(
Expand Down Expand Up @@ -547,7 +547,7 @@ fn rewrite_expr_to_prunable(
// `-col > lit()` --> `col < -lit()`
Expr::Negative(c) => {
let (left, op, right) = rewrite_expr_to_prunable(c, op, scalar_expr, schema)?;
Ok((left, reverse_operator(op), Expr::Negative(Box::new(right))))
Ok((left, reverse_operator(op)?, Expr::Negative(Box::new(right))))
}
// `!col = true` --> `col = !true`
Expr::Not(c) => {
Expand All @@ -560,7 +560,7 @@ fn rewrite_expr_to_prunable(
return match c.as_ref() {
Expr::Column(_) => Ok((
c.as_ref().clone(),
reverse_operator(op),
reverse_operator(op)?,
Expr::Not(Box::new(scalar_expr.clone())),
)),
_ => Err(DataFusionError::Plan(format!(
Expand Down Expand Up @@ -641,14 +641,13 @@ fn rewrite_column_expr(
})
}

fn reverse_operator(op: Operator) -> Operator {
match op {
Operator::Lt => Operator::Gt,
Operator::Gt => Operator::Lt,
Operator::LtEq => Operator::GtEq,
Operator::GtEq => Operator::LtEq,
_ => op,
}
fn reverse_operator(op: Operator) -> Result<Operator> {
op.swap().ok_or_else(|| {
DataFusionError::Internal(format!(
"Could not reverse operator {} while building pruning predicate",
op
))
})
}

/// Given a column reference to `column`, returns a pruning
Expand Down