Skip to content

Commit

Permalink
feat: support deferred predicates in join
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist authored and cpcloud committed Nov 4, 2022
1 parent 438eb19 commit b51a64b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ibis/expr/operations/relations.py
Expand Up @@ -13,6 +13,7 @@
import ibis.expr.types as ir
import ibis.util as util
from ibis.common.annotations import attribute
from ibis.expr.deferred import Deferred
from ibis.expr.operations.core import Named, Node, Value
from ibis.expr.operations.generic import TableColumn
from ibis.expr.operations.logical import Equals, ExistsSubquery, NotExistsSubquery
Expand Down Expand Up @@ -109,6 +110,9 @@ def _clean_join_predicates(left, right, predicates):
pred = left.to_expr()[pred] == right.to_expr()[pred]
elif isinstance(pred, Value):
pred = pred.to_expr()
elif isinstance(pred, Deferred):
# resolve deferred expressions on the left table
pred = pred.resolve(left.to_expr())
elif not isinstance(pred, ir.Expr):
raise NotImplementedError

Expand Down
8 changes: 8 additions & 0 deletions ibis/tests/expr/test_table.py
Expand Up @@ -794,6 +794,14 @@ def test_join_no_predicate_list(con):
assert_equal(joined, expected)


def test_join_deferred(con):
region = con.table("tpch_region")
nation = con.table("tpch_nation")
res = region.join(nation, _.r_regionkey == nation.n_regionkey)
exp = region.join(nation, region.r_regionkey == nation.n_regionkey)
assert_equal(res, exp)


def test_asof_join():
left = ibis.table([('time', 'int32'), ('value', 'double')])
right = ibis.table([('time', 'int32'), ('value2', 'double')])
Expand Down

0 comments on commit b51a64b

Please sign in to comment.