Skip to content

Commit 8741372

Browse files
authored
minor: Use Operator::swap (#4092)
* minor: Use Operator::swap * fixup
1 parent 52930cd commit 8741372

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

datafusion/core/src/physical_optimizer/pruning.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'a> PruningExpressionBuilder<'a> {
445445
let (column_expr, scalar_expr, columns, correct_operator) =
446446
match (left_columns.len(), right_columns.len()) {
447447
(1, 0) => (left, right, left_columns, op),
448-
(0, 1) => (right, left, right_columns, reverse_operator(op)),
448+
(0, 1) => (right, left, right_columns, reverse_operator(op)?),
449449
_ => {
450450
// if more than one column used in expression - not supported
451451
return Err(DataFusionError::Plan(
@@ -547,7 +547,7 @@ fn rewrite_expr_to_prunable(
547547
// `-col > lit()` --> `col < -lit()`
548548
Expr::Negative(c) => {
549549
let (left, op, right) = rewrite_expr_to_prunable(c, op, scalar_expr, schema)?;
550-
Ok((left, reverse_operator(op), Expr::Negative(Box::new(right))))
550+
Ok((left, reverse_operator(op)?, Expr::Negative(Box::new(right))))
551551
}
552552
// `!col = true` --> `col = !true`
553553
Expr::Not(c) => {
@@ -560,7 +560,7 @@ fn rewrite_expr_to_prunable(
560560
return match c.as_ref() {
561561
Expr::Column(_) => Ok((
562562
c.as_ref().clone(),
563-
reverse_operator(op),
563+
reverse_operator(op)?,
564564
Expr::Not(Box::new(scalar_expr.clone())),
565565
)),
566566
_ => Err(DataFusionError::Plan(format!(
@@ -641,14 +641,13 @@ fn rewrite_column_expr(
641641
})
642642
}
643643

644-
fn reverse_operator(op: Operator) -> Operator {
645-
match op {
646-
Operator::Lt => Operator::Gt,
647-
Operator::Gt => Operator::Lt,
648-
Operator::LtEq => Operator::GtEq,
649-
Operator::GtEq => Operator::LtEq,
650-
_ => op,
651-
}
644+
fn reverse_operator(op: Operator) -> Result<Operator> {
645+
op.swap().ok_or_else(|| {
646+
DataFusionError::Internal(format!(
647+
"Could not reverse operator {} while building pruning predicate",
648+
op
649+
))
650+
})
652651
}
653652

654653
/// Given a column reference to `column`, returns a pruning

0 commit comments

Comments
 (0)