Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add more weird join predicate tests #7424

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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