Skip to content

Commit

Permalink
refactor(ir): remove lin.lineage() since it's not used anywhere
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ibis.expr.lineage.lineage() is now removed
  • Loading branch information
kszucs committed Sep 16, 2022
1 parent 762d384 commit 120b1d7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 266 deletions.
71 changes: 0 additions & 71 deletions ibis/expr/lineage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from __future__ import annotations

import collections
import itertools
from typing import Any, Callable, Iterable, Iterator

import ibis.expr.operations as ops
import ibis.expr.types as ir


Expand Down Expand Up @@ -56,75 +54,6 @@ def get(self):
return self.data.popleft()


def _get_args(op, name):
"""Hack to get relevant arguments for lineage computation.
We need a better way to determine the relevant arguments of an expression.
"""
# Could use multipledispatch here to avoid the pasta
if isinstance(op, ops.Selection):
assert name is not None, 'name is None'
result = op.selections

# if Selection.selections is always columnar, could use an
# OrderedDict to prevent scanning the whole thing
return [col for col in result if col.get_name() == name]
elif isinstance(op, ops.Aggregation):
assert name is not None, 'name is None'
return [
col
for col in itertools.chain(op.by, op.metrics)
if col.get_name() == name
]
else:
return op.args


def lineage(expr, container=Stack):
"""Yield the path of the expression tree that comprises a column
expression.
Parameters
----------
expr : Expr
An ibis expression. It must be an instance of
:class:`ibis.expr.types.Column`.
container : Container, {Stack, Queue}
Stack for depth-first traversal, and Queue for breadth-first.
Depth-first will reach root table nodes before continuing on to other
columns in a column that is derived from multiple column. Breadth-
first will traverse all columns at each level before reaching root
tables.
Yields
------
node : Expr
A column and its dependencies
"""
if not isinstance(expr, ir.Column):
raise TypeError('Input expression must be an instance of Column')

c = container([(expr, expr.get_name() if expr.has_name() else None)])

seen = set()

# while we haven't visited everything
while c:
node, name = c.get()

if node not in seen:
seen.add(node)
yield node

# add our dependencies to the container if they match our name
# and are ibis expressions
c.extend(
(arg, arg.get_name() if arg.has_name() else name)
for arg in c.visitor(_get_args(node.op(), name))
if isinstance(arg, ir.Expr)
)


# these could be callables instead
proceed = True
halt = False
Expand Down
195 changes: 0 additions & 195 deletions ibis/tests/expr/test_lineage.py

This file was deleted.

0 comments on commit 120b1d7

Please sign in to comment.