From 00a7fcbb3ec5af1684cbfd62c4be9abf93c92131 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 2 Nov 2022 15:54:07 -0400 Subject: [PATCH 1/2] minor: Use Operator::swap --- .../core/src/physical_optimizer/pruning.rs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/datafusion/core/src/physical_optimizer/pruning.rs b/datafusion/core/src/physical_optimizer/pruning.rs index 11e86c2e136e..575efd7755ba 100644 --- a/datafusion/core/src/physical_optimizer/pruning.rs +++ b/datafusion/core/src/physical_optimizer/pruning.rs @@ -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( @@ -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) => { @@ -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!( @@ -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 { + 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 @@ -842,7 +841,7 @@ fn build_statistics_expr(expr_builder: &mut PruningExpressionBuilder) -> Result< } // other expressions are not supported _ => return Err(DataFusionError::Plan( - "expressions other than (neq, eq, gt, gteq, lt, lteq) are not supported" + "expressions} other than (neq, eq, gt, gteq, lt, lteq) are not supported" .to_string(), )), }; From 94c93a8fef9ec20192fa5c802b11f0bbd58a5a3b Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 2 Nov 2022 15:58:34 -0400 Subject: [PATCH 2/2] fixup --- datafusion/core/src/physical_optimizer/pruning.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/core/src/physical_optimizer/pruning.rs b/datafusion/core/src/physical_optimizer/pruning.rs index 575efd7755ba..d33082cd87b8 100644 --- a/datafusion/core/src/physical_optimizer/pruning.rs +++ b/datafusion/core/src/physical_optimizer/pruning.rs @@ -841,7 +841,7 @@ fn build_statistics_expr(expr_builder: &mut PruningExpressionBuilder) -> Result< } // other expressions are not supported _ => return Err(DataFusionError::Plan( - "expressions} other than (neq, eq, gt, gteq, lt, lteq) are not supported" + "expressions other than (neq, eq, gt, gteq, lt, lteq) are not supported" .to_string(), )), };