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

feat: semi-join for duckdb #1767

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 10 additions & 7 deletions narwhals/_duckdb/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def join(
if isinstance(right_on, str):
right_on = [right_on]

if how not in ("inner", "left"):
if how not in ("inner", "left", "semi"):
msg = "Only inner and left join is implemented for DuckDB"
raise NotImplementedError(msg)

Expand All @@ -242,12 +242,15 @@ def join(
other._native_frame.set_alias("rhs"), condition=condition, how=how
)

select = [f"lhs.{x}" for x in self._native_frame.columns]
for col in other._native_frame.columns:
if col in self._native_frame.columns and col not in right_on:
select.append(f"rhs.{col} as {col}{suffix}")
elif col not in right_on:
select.append(col)
if how in ("inner", "left"):
select = [f"lhs.{x}" for x in self._native_frame.columns]
for col in other._native_frame.columns:
if col in self._native_frame.columns and col not in right_on:
select.append(f"rhs.{col} as {col}{suffix}")
elif col not in right_on:
select.append(col)
elif how == "semi":
select = [f"lhs.{x}" for x in self._native_frame.columns]

res = rel.select(", ".join(select)).set_alias(original_alias)
return self._from_native_frame(res)
Expand Down
3 changes: 0 additions & 3 deletions tests/frame/join_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ def test_semi_join(
join_key: list[str],
filter_expr: nw.Expr,
expected: dict[str, list[Any]],
request: pytest.FixtureRequest,
) -> None:
if "duckdb" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {"antananarivo": [1, 3, 2], "bob": [4, 4, 6], "zorro": [7.0, 8, 9]}
df = nw.from_native(constructor(data))
other = df.filter(filter_expr)
Expand Down
2 changes: 1 addition & 1 deletion tpch/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"dask": lambda x: x.compute(),
}

DUCKDB_XFAILS = ["q11", "q14", "q15", "q16", "q18", "q22"]
DUCKDB_XFAILS = ["q11", "q14", "q15", "q16", "q22"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17 out of 22 πŸ₯³

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

18 if we count the n-unique pr too 😎


QUERY_DATA_PATH_MAP = {
"q1": (LINEITEM_PATH,),
Expand Down
Loading