Skip to content

Commit af13798

Browse files
committed
swap operators before analysis
1 parent 8da221f commit af13798

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

datafusion/physical-expr/src/utils/guarantee.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl LiteralGuarantee {
9494
/// create these structures from an predicate (boolean expression).
9595
fn try_new<'a>(
9696
column_name: impl Into<String>,
97-
op: &Operator,
97+
op: Operator,
9898
literals: impl IntoIterator<Item = &'a ScalarValue>,
9999
) -> Option<Self> {
100100
let guarantee = match op {
@@ -199,7 +199,7 @@ struct GuaranteeBuilder<'a> {
199199

200200
/// Key is the (column name, operator type)
201201
/// Value is the index into `guarantees`
202-
map: HashMap<(&'a crate::expressions::Column, &'a Operator), usize>,
202+
map: HashMap<(&'a crate::expressions::Column, Operator), usize>,
203203
}
204204

205205
impl<'a> GuaranteeBuilder<'a> {
@@ -233,7 +233,7 @@ impl<'a> GuaranteeBuilder<'a> {
233233
fn aggregate_multi_conjunct(
234234
mut self,
235235
col: &'a crate::expressions::Column,
236-
op: &'a Operator,
236+
op: Operator,
237237
new_values: impl IntoIterator<Item = &'a ScalarValue>,
238238
) -> Self {
239239
let key = (col, op);
@@ -290,7 +290,7 @@ impl<'a> GuaranteeBuilder<'a> {
290290
// new_values are combined with OR, so we can only create a
291291
// multi-column guarantee for `=` (or a single value).
292292
// (e.g. ignore `a != foo OR a != bar`)
293-
if op == &Operator::Eq || new_values.len() == 1 {
293+
if op == Operator::Eq || new_values.len() == 1 {
294294
if let Some(guarantee) =
295295
LiteralGuarantee::try_new(col.name(), op, new_values)
296296
{
@@ -314,7 +314,7 @@ impl<'a> GuaranteeBuilder<'a> {
314314
/// Represents a single `col <op> literal` expression
315315
struct ColOpLit<'a> {
316316
col: &'a crate::expressions::Column,
317-
op: &'a Operator,
317+
op: Operator,
318318
lit: &'a crate::expressions::Literal,
319319
}
320320

@@ -340,14 +340,15 @@ impl<'a> ColOpLit<'a> {
340340
left.downcast_ref::<crate::expressions::Column>(),
341341
right.downcast_ref::<crate::expressions::Literal>(),
342342
) {
343-
Some(Self { col, op, lit })
343+
Some(Self { col, op: *op, lit })
344344
}
345345
// literal <op> col
346346
else if let (Some(lit), Some(col)) = (
347347
left.downcast_ref::<crate::expressions::Literal>(),
348348
right.downcast_ref::<crate::expressions::Column>(),
349349
) {
350-
Some(Self { col, op, lit })
350+
// Used swapped operator operator, if possible
351+
op.swap().map(|op| Self { col, op, lit })
351352
} else {
352353
None
353354
}
@@ -667,7 +668,7 @@ mod test {
667668
S: Into<ScalarValue> + 'a,
668669
{
669670
let literals: Vec<_> = literals.into_iter().map(|s| s.into()).collect();
670-
LiteralGuarantee::try_new(column, &Operator::Eq, literals.iter()).unwrap()
671+
LiteralGuarantee::try_new(column, Operator::Eq, literals.iter()).unwrap()
671672
}
672673

673674
/// Guarantee that the expression is true if the column is NOT any of the specified values
@@ -677,7 +678,7 @@ mod test {
677678
S: Into<ScalarValue> + 'a,
678679
{
679680
let literals: Vec<_> = literals.into_iter().map(|s| s.into()).collect();
680-
LiteralGuarantee::try_new(column, &Operator::NotEq, literals.iter()).unwrap()
681+
LiteralGuarantee::try_new(column, Operator::NotEq, literals.iter()).unwrap()
681682
}
682683

683684
/// Convert a logical expression to a physical expression (without any simplification, etc)

0 commit comments

Comments
 (0)