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

add exists -> semi in q4 #126

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions queries/dask/q4.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def query() -> pd.DataFrame:
var1 = date(1993, 7, 1)
var2 = date(1993, 10, 1)

jn = line_item_ds.merge(orders_ds, left_on="l_orderkey", right_on="o_orderkey")
exists = line_item_ds[
line_item_ds["l_commitdate"] < line_item_ds["l_receiptdate"]
]

jn = orders_ds.merge(
exists, left_on="o_orderkey", right_on="l_orderkey", how="leftsemi"
)
jn = jn[(jn["o_orderdate"] >= var1) & (jn["o_orderdate"] < var2)]
jn = jn[jn["l_commitdate"] < jn["l_receiptdate"]]

jn = jn.drop_duplicates(subset=["o_orderpriority", "l_orderkey"])

gb = jn.groupby("o_orderpriority")
agg = gb.agg(
Expand Down
10 changes: 7 additions & 3 deletions queries/polars/q4.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ def q() -> None:
var2 = date(1993, 10, 1)

q_final = (
lineitem.join(orders, left_on="l_orderkey", right_on="o_orderkey")
# SQL exists translates to semi join in Polars API
orders.join(
(lineitem.filter(pl.col("l_commitdate") < pl.col("l_receiptdate"))),
left_on="o_orderkey",
right_on="l_orderkey",
how="semi",
)
.filter(pl.col("o_orderdate").is_between(var1, var2, closed="left"))
.filter(pl.col("l_commitdate") < pl.col("l_receiptdate"))
.unique(subset=["o_orderpriority", "l_orderkey"])
.group_by("o_orderpriority")
.agg(pl.len().alias("order_count"))
.sort("o_orderpriority")
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dask[dataframe]
dask-expr
duckdb
modin[ray]
pandas>=2.0
Expand Down