Skip to content

Commit

Permalink
test(api): flesh out join predicate tests
Browse files Browse the repository at this point in the history
As I was exploring #6506, I
discovered that there are join predicate types that currently work, but
aren't tested for. This commits adds tests for those predicate types.
  • Loading branch information
NickCrews authored and cpcloud committed Oct 26, 2023
1 parent 9f618c6 commit a965f67
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions ibis/tests/expr/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,25 +1102,39 @@ def test_inner_join_overlapping_column_names():
]


def test_join_key_alternatives(con):
@pytest.mark.parametrize(
"key_maker",
[
lambda t1, t2: t1.foo_id == t2.foo_id,
lambda t1, t2: [("foo_id", "foo_id")],
lambda t1, t2: [(t1.foo_id, t2.foo_id)],
lambda t1, t2: [(_.foo_id, _.foo_id)],
lambda t1, t2: [(t1.foo_id, _.foo_id)],
lambda t1, t2: [(2, 0)], # foo_id is 2nd in t1, 0th in t2
lambda t1, t2: [(lambda t: t.foo_id, lambda t: t.foo_id)],
],
)
def test_join_key_alternatives(con, key_maker):
t1 = con.table("star1")
t2 = con.table("star2")

# Join with tuples
joined = t1.inner_join(t2, [("foo_id", "foo_id")])
joined2 = t1.inner_join(t2, [(t1.foo_id, t2.foo_id)])

# Join with single expr
joined3 = t1.inner_join(t2, t1.foo_id == t2.foo_id)

expected = t1.inner_join(t2, [t1.foo_id == t2.foo_id])

key = key_maker(t1, t2)
joined = t1.inner_join(t2, key)
assert_equal(joined, expected)
assert_equal(joined2, expected)
assert_equal(joined3, expected)

with pytest.raises(com.ExpressionError):
t1.inner_join(t2, [("foo_id", "foo_id", "foo_id")])

@pytest.mark.parametrize(
"key,error",
[
([("foo_id", "foo_id", "foo_id")], com.ExpressionError),
([(s.c("foo_id"), s.c("foo_id"))], ValueError),
],
)
def test_join_key_invalid(con, key, error):
t1 = con.table("star1")
t2 = con.table("star2")
with pytest.raises(error):
t1.inner_join(t2, key)


def test_join_invalid_refs(con):
Expand Down

0 comments on commit a965f67

Please sign in to comment.