Skip to content

Commit

Permalink
refactor(ir): actually remove analysis.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Apr 30, 2024
1 parent 3704088 commit 255e0c3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
37 changes: 0 additions & 37 deletions ibis/expr/analysis.py

This file was deleted.

36 changes: 36 additions & 0 deletions ibis/expr/rewrites.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ibis.common.deferred import Item, _, deferred, var
from ibis.common.exceptions import ExpressionError, IbisInputError
from ibis.common.graph import Node as Traversable
from ibis.common.graph import traverse
from ibis.common.grounds import Concrete
from ibis.common.patterns import Check, pattern, replace
from ibis.common.typing import VarTuple # noqa: TCH001
Expand Down Expand Up @@ -158,6 +159,41 @@ def dereference(self, value):
return value.replace(self.subs, filter=ops.Value)


def flatten_predicates(node):
"""Yield the expressions corresponding to the `And` nodes of a predicate.
Examples
--------
>>> import ibis
>>> t = ibis.table([("a", "int64"), ("b", "string")], name="t")
>>> filt = (t.a == 1) & (t.b == "foo")
>>> predicates = flatten_predicates(filt.op())
>>> len(predicates)
2
>>> predicates[0].to_expr().name("left")
r0 := UnboundTable: t
a int64
b string
left: r0.a == 1
>>> predicates[1].to_expr().name("right")
r0 := UnboundTable: t
a int64
b string
right: r0.b == 'foo'
"""

def predicate(node):
if isinstance(node, ops.And):
# proceed and don't yield the node
return True, None
else:
# halt and yield the node
return False, node

return list(traverse(predicate, node))


@replace(p.Field(p.JoinChain))
def peel_join_field(_):
return _.rel.values[_.name]
Expand Down
3 changes: 1 addition & 2 deletions ibis/expr/types/joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
InputTypeError,
IntegrityError,
)
from ibis.expr.analysis import flatten_predicates
from ibis.expr.rewrites import peel_join_field
from ibis.expr.rewrites import flatten_predicates, peel_join_field
from ibis.expr.types.generic import Value
from ibis.expr.types.relations import (
DerefMap,
Expand Down
3 changes: 1 addition & 2 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2475,8 +2475,7 @@ def filter(
│ male │ 68 │
└────────┴───────────┘
"""
from ibis.expr.analysis import flatten_predicates
from ibis.expr.rewrites import rewrite_filter_input
from ibis.expr.rewrites import flatten_predicates, rewrite_filter_input

preds = self.bind(*predicates)
preds = unwrap_aliases(preds)
Expand Down

0 comments on commit 255e0c3

Please sign in to comment.