Skip to content

Commit

Permalink
refactor(ir): simplify Expr._find_backends() implementation by usin…
Browse files Browse the repository at this point in the history
…g the `ibis.common.graph` utilities
  • Loading branch information
kszucs committed May 19, 2023
1 parent 05ff488 commit 91ff8d4
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions ibis/expr/types/core.py
Expand Up @@ -217,23 +217,16 @@ def _find_backends(self) -> tuple[list[BaseBackend], bool]:
list[BaseBackend]
A list of the backends found.
"""
import ibis.expr.operations as ops
from ibis.backends.base import BaseBackend

def finder(node):
# BaseBackend objects are not operation instances, so they don't
# get traversed, this is why we need to select backends out from
# the node's arguments
backends = [arg for arg in node.args if isinstance(arg, BaseBackend)]
return g.proceed, (backends, isinstance(node, ops.UnboundTable))

all_backends = []
any_unbound = False
for backends, has_unbound in g.traverse(finder, self.op()):
all_backends += backends
any_unbound |= has_unbound

return list(toolz.unique(all_backends)), any_unbound
backends = set()
has_unbound = False
node_types = (ops.DatabaseTable, ops.SQLQueryResult, ops.UnboundTable)
for table in self.op().find(node_types):
if isinstance(table, ops.UnboundTable):
has_unbound = True
else:
backends.add(table.source)

return list(backends), has_unbound

def _find_backend(self, *, use_default: bool = False) -> BaseBackend:
"""Find the backend attached to an expression.
Expand Down

0 comments on commit 91ff8d4

Please sign in to comment.