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

refactor: use nw.scan_parquet in tpch benchmarks #1578

Merged
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
27 changes: 15 additions & 12 deletions tpch/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import dask.dataframe as dd
import pandas as pd
import polars as pl
import pyarrow.parquet as pq
import pyarrow as pa

import narwhals as nw

pd.options.mode.copy_on_write = True
pd.options.future.infer_string = True
Expand All @@ -22,15 +24,11 @@
ORDERS_PATH = DATA_DIR / "orders.parquet"
CUSTOMER_PATH = DATA_DIR / "customer.parquet"

BACKEND_READ_FUNC_MAP = {
# "pandas": lambda x: pd.read_parquet(x, engine="pyarrow"), # noqa: ERA001
"pandas[pyarrow]": lambda x: pd.read_parquet(
x, engine="pyarrow", dtype_backend="pyarrow"
),
# "polars[eager]": lambda x: pl.read_parquet(x),
"polars[lazy]": lambda x: pl.scan_parquet(x),
"pyarrow": lambda x: pq.read_table(x),
"dask": lambda x: dd.read_parquet(x, engine="pyarrow", dtype_backend="pyarrow"),
BACKEND_NAMESPACE_KWARGS_MAP = {
"pandas[pyarrow]": (pd, {"engine": "pyarrow", "dtype_backend": "pyarrow"}),
"polars[lazy]": (pl, {}),
"pyarrow": (pa, {}),
"dask": (dd, {"engine": "pyarrow", "dtype_backend": "pyarrow"}),
}

BACKEND_COLLECT_FUNC_MAP = {
Expand Down Expand Up @@ -90,9 +88,14 @@ def execute_query(query_id: str) -> None:
query_module = import_module(f"tpch.queries.{query_id}")
data_paths = QUERY_DATA_PATH_MAP[query_id]

for backend, read_func in BACKEND_READ_FUNC_MAP.items():
for backend, (native_namespace, kwargs) in BACKEND_NAMESPACE_KWARGS_MAP.items():
print(f"\nRunning {query_id} with {backend=}") # noqa: T201
result = query_module.query(*(read_func(path) for path in data_paths))
result = query_module.query(
*(
nw.scan_parquet(path, native_namespace=native_namespace, **kwargs)
for path in data_paths
)
)
if collect_func := BACKEND_COLLECT_FUNC_MAP.get(backend):
result = collect_func(result)
print(result) # noqa: T201
Expand Down
Loading