diff --git a/tpch/README.md b/tpch/README.md index 3ae09b723..fbf130e7d 100644 --- a/tpch/README.md +++ b/tpch/README.md @@ -11,7 +11,7 @@ Run `python generate_data.py` from this folder. ## Run queries -To run Q1, you can run `python -m execute.q1` from this folder. +To run Q1, you can run `python -m execute q1` from this folder. Please add query definitions in `queries`, and scripts to execute them in `execute` (see `queries/q1.py` and `execute/q1.py` for examples). diff --git a/tpch/execute.py b/tpch/execute.py new file mode 100644 index 000000000..3b4ea11cb --- /dev/null +++ b/tpch/execute.py @@ -0,0 +1,110 @@ +from __future__ import annotations + +import argparse +from importlib import import_module +from pathlib import Path + +import dask.dataframe as dd +import pandas as pd +import polars as pl +import pyarrow.parquet as pq + +pd.options.mode.copy_on_write = True +pd.options.future.infer_string = True + +DATA_DIR = Path("data") +LINEITEM_PATH = DATA_DIR / "lineitem.parquet" +REGION_PATH = DATA_DIR / "region.parquet" +NATION_PATH = DATA_DIR / "nation.parquet" +SUPPLIER_PATH = DATA_DIR / "supplier.parquet" +PART_PATH = DATA_DIR / "part.parquet" +PARTSUPP_PATH = DATA_DIR / "partsupp.parquet" +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_COLLECT_FUNC_MAP = { + "polars[lazy]": lambda x: x.collect(), + "dask": lambda x: x.compute(), +} + +QUERY_DATA_PATH_MAP = { + "q1": (LINEITEM_PATH,), + "q2": (REGION_PATH, NATION_PATH, SUPPLIER_PATH, PART_PATH, PARTSUPP_PATH), + "q3": (CUSTOMER_PATH, LINEITEM_PATH, ORDERS_PATH), + "q4": (LINEITEM_PATH, ORDERS_PATH), + "q5": ( + REGION_PATH, + NATION_PATH, + CUSTOMER_PATH, + LINEITEM_PATH, + ORDERS_PATH, + SUPPLIER_PATH, + ), + "q6": (LINEITEM_PATH,), + "q7": (NATION_PATH, CUSTOMER_PATH, LINEITEM_PATH, ORDERS_PATH, SUPPLIER_PATH), + "q8": ( + PART_PATH, + SUPPLIER_PATH, + LINEITEM_PATH, + ORDERS_PATH, + CUSTOMER_PATH, + NATION_PATH, + REGION_PATH, + ), + "q9": ( + PART_PATH, + PARTSUPP_PATH, + NATION_PATH, + LINEITEM_PATH, + ORDERS_PATH, + SUPPLIER_PATH, + ), + "q10": (CUSTOMER_PATH, NATION_PATH, LINEITEM_PATH, ORDERS_PATH), + "q11": (NATION_PATH, PARTSUPP_PATH, SUPPLIER_PATH), + "q12": (LINEITEM_PATH, ORDERS_PATH), + "q13": (CUSTOMER_PATH, ORDERS_PATH), + "q14": (LINEITEM_PATH, PART_PATH), + "q15": (LINEITEM_PATH, SUPPLIER_PATH), + "q16": (PART_PATH, PARTSUPP_PATH, SUPPLIER_PATH), + "q17": (LINEITEM_PATH, PART_PATH), + "q18": (CUSTOMER_PATH, LINEITEM_PATH, ORDERS_PATH), + "q19": (LINEITEM_PATH, PART_PATH), + "q20": (PART_PATH, PARTSUPP_PATH, NATION_PATH, LINEITEM_PATH, SUPPLIER_PATH), + "q21": (LINEITEM_PATH, NATION_PATH, ORDERS_PATH, SUPPLIER_PATH), + "q22": (CUSTOMER_PATH, ORDERS_PATH), +} + + +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(): + print(f"\nRunning {query_id} with {backend=}") # noqa: T201 + result = query_module.query(*(read_func(path) for path in data_paths)) + if collect_func := BACKEND_COLLECT_FUNC_MAP.get(backend): + result = collect_func(result) + print(result) # noqa: T201 + + +def main() -> None: + parser = argparse.ArgumentParser(description="Execute a TPCH query by number.") + parser.add_argument("query", type=str, help="The query to execute, e.g. 'q1'.") + args = parser.parse_args() + + execute_query(query_id=args.query) + + +if __name__ == "__main__": + main() diff --git a/tpch/execute/__init__.py b/tpch/execute/__init__.py deleted file mode 100644 index ecbf1db53..000000000 --- a/tpch/execute/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import annotations - -from pathlib import Path - -import dask.dataframe as dd -import pandas as pd -import polars as pl -import pyarrow.parquet as pq - -pd.options.mode.copy_on_write = True -pd.options.future.infer_string = True - -lineitem = Path("data") / "lineitem.parquet" -region = Path("data") / "region.parquet" -nation = Path("data") / "nation.parquet" -supplier = Path("data") / "supplier.parquet" -part = Path("data") / "part.parquet" -partsupp = Path("data") / "partsupp.parquet" -orders = Path("data") / "orders.parquet" -customer = Path("data") / "customer.parquet" -line_item = Path("data") / "lineitem.parquet" - -IO_FUNCS = { - "pandas": lambda x: pd.read_parquet(x, engine="pyarrow"), - "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"), -} diff --git a/tpch/execute/q1.py b/tpch/execute/q1.py deleted file mode 100644 index 6bfdc1a16..000000000 --- a/tpch/execute/q1.py +++ /dev/null @@ -1,10 +0,0 @@ -from __future__ import annotations - -from queries import q1 - -from . import IO_FUNCS -from . import lineitem - -print(q1.query(IO_FUNCS["pandas[pyarrow]"](lineitem))) -print(q1.query(IO_FUNCS["polars[lazy]"](lineitem)).collect()) -print(q1.query(IO_FUNCS["pyarrow"](lineitem))) diff --git a/tpch/execute/q10.py b/tpch/execute/q10.py deleted file mode 100644 index fefcd0e8d..000000000 --- a/tpch/execute/q10.py +++ /dev/null @@ -1,21 +0,0 @@ -from __future__ import annotations - -from queries import q10 - -from . import IO_FUNCS -from . import customer -from . import lineitem -from . import nation -from . import orders - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q10.query(fn(customer), fn(nation), fn(lineitem), fn(orders))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q10.query(fn(customer), fn(nation), fn(lineitem), fn(orders)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q10.query(fn(customer), fn(nation), fn(lineitem), fn(orders))) diff --git a/tpch/execute/q11.py b/tpch/execute/q11.py deleted file mode 100644 index ad0146d3e..000000000 --- a/tpch/execute/q11.py +++ /dev/null @@ -1,20 +0,0 @@ -from __future__ import annotations - -from queries import q11 - -from . import IO_FUNCS -from . import nation -from . import partsupp -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q11.query(fn(nation), fn(partsupp), fn(supplier))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q11.query(fn(nation), fn(partsupp), fn(supplier)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q11.query(fn(nation), fn(partsupp), fn(supplier))) diff --git a/tpch/execute/q12.py b/tpch/execute/q12.py deleted file mode 100644 index 42d6d245e..000000000 --- a/tpch/execute/q12.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q12 - -from . import IO_FUNCS -from . import line_item -from . import orders - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q12.query(fn(line_item), fn(orders))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q12.query(fn(line_item), fn(orders)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q12.query(fn(line_item), fn(orders))) diff --git a/tpch/execute/q13.py b/tpch/execute/q13.py deleted file mode 100644 index b7162d97a..000000000 --- a/tpch/execute/q13.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q13 - -from . import IO_FUNCS -from . import customer -from . import orders - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q13.query(fn(customer), fn(orders))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q13.query(fn(customer), fn(orders)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q13.query(fn(customer), fn(orders))) diff --git a/tpch/execute/q14.py b/tpch/execute/q14.py deleted file mode 100644 index 443130100..000000000 --- a/tpch/execute/q14.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q14 - -from . import IO_FUNCS -from . import line_item -from . import part - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q14.query(fn(line_item), fn(part))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q14.query(fn(line_item), fn(part)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q14.query(fn(line_item), fn(part))) diff --git a/tpch/execute/q15.py b/tpch/execute/q15.py deleted file mode 100644 index 1fca0b078..000000000 --- a/tpch/execute/q15.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q15 - -from . import IO_FUNCS -from . import lineitem -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q15.query(fn(lineitem), fn(supplier))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q15.query(fn(lineitem), fn(supplier)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q15.query(fn(lineitem), fn(supplier))) diff --git a/tpch/execute/q16.py b/tpch/execute/q16.py deleted file mode 100644 index 4d65a1b51..000000000 --- a/tpch/execute/q16.py +++ /dev/null @@ -1,20 +0,0 @@ -from __future__ import annotations - -from queries import q16 - -from . import IO_FUNCS -from . import part -from . import partsupp -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q16.query(fn(part), fn(partsupp), fn(supplier))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q16.query(fn(part), fn(partsupp), fn(supplier)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q16.query(fn(part), fn(partsupp), fn(supplier))) diff --git a/tpch/execute/q17.py b/tpch/execute/q17.py deleted file mode 100644 index bec1abdf5..000000000 --- a/tpch/execute/q17.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q17 - -from . import IO_FUNCS -from . import lineitem -from . import part - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q17.query(fn(lineitem), fn(part))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q17.query(fn(lineitem), fn(part)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q17.query(fn(lineitem), fn(part))) diff --git a/tpch/execute/q18.py b/tpch/execute/q18.py deleted file mode 100644 index 727780a79..000000000 --- a/tpch/execute/q18.py +++ /dev/null @@ -1,20 +0,0 @@ -from __future__ import annotations - -from queries import q18 - -from . import IO_FUNCS -from . import customer -from . import lineitem -from . import orders - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q18.query(fn(customer), fn(lineitem), fn(orders))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q18.query(fn(customer), fn(lineitem), fn(orders)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q18.query(fn(customer), fn(lineitem), fn(orders))) diff --git a/tpch/execute/q19.py b/tpch/execute/q19.py deleted file mode 100644 index 3dd966ea7..000000000 --- a/tpch/execute/q19.py +++ /dev/null @@ -1,16 +0,0 @@ -from __future__ import annotations - -from queries import q19 - -from . import IO_FUNCS -from . import lineitem -from . import part - -fn = IO_FUNCS["pandas[pyarrow]"] -print(q19.query(fn(lineitem), fn(part))) - -fn = IO_FUNCS["polars[lazy]"] -print(q19.query(fn(lineitem), fn(part)).collect()) - -fn = IO_FUNCS["pyarrow"] -print(q19.query(fn(lineitem), fn(part))) diff --git a/tpch/execute/q2.py b/tpch/execute/q2.py deleted file mode 100644 index 2aff3c0a6..000000000 --- a/tpch/execute/q2.py +++ /dev/null @@ -1,44 +0,0 @@ -from __future__ import annotations - -from queries import q2 - -from . import IO_FUNCS -from . import nation -from . import part -from . import partsupp -from . import region -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print( - q2.query( - fn(region), - fn(nation), - fn(supplier), - fn(part), - fn(partsupp), - ) -) -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print( - q2.query( - fn(region), - fn(nation), - fn(supplier), - fn(part), - fn(partsupp), - ).collect() -) -tool = "pyarrow" -fn = IO_FUNCS[tool] -print( - q2.query( - fn(region), - fn(nation), - fn(supplier), - fn(part), - fn(partsupp), - ) -) diff --git a/tpch/execute/q20.py b/tpch/execute/q20.py deleted file mode 100644 index b61d2cddb..000000000 --- a/tpch/execute/q20.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q20 - -from . import IO_FUNCS -from . import lineitem -from . import nation -from . import part -from . import partsupp -from . import supplier - -fn = IO_FUNCS["pandas[pyarrow]"] -print(q20.query(fn(part), fn(partsupp), fn(nation), fn(lineitem), fn(supplier))) - -fn = IO_FUNCS["polars[lazy]"] -print(q20.query(fn(part), fn(partsupp), fn(nation), fn(lineitem), fn(supplier)).collect()) - -fn = IO_FUNCS["pyarrow"] -print(q20.query(fn(part), fn(partsupp), fn(nation), fn(lineitem), fn(supplier))) diff --git a/tpch/execute/q21.py b/tpch/execute/q21.py deleted file mode 100644 index 3fb412320..000000000 --- a/tpch/execute/q21.py +++ /dev/null @@ -1,18 +0,0 @@ -from __future__ import annotations - -from queries import q21 - -from . import IO_FUNCS -from . import lineitem -from . import nation -from . import orders -from . import supplier - -fn = IO_FUNCS["pandas[pyarrow]"] -print(q21.query(fn(lineitem), fn(nation), fn(orders), fn(supplier))) - -fn = IO_FUNCS["polars[lazy]"] -print(q21.query(fn(lineitem), fn(nation), fn(orders), fn(supplier)).collect()) - -fn = IO_FUNCS["pyarrow"] -print(q21.query(fn(lineitem), fn(nation), fn(orders), fn(supplier))) diff --git a/tpch/execute/q22.py b/tpch/execute/q22.py deleted file mode 100644 index 96744ea59..000000000 --- a/tpch/execute/q22.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q22 - -from . import IO_FUNCS -from . import customer -from . import orders - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q22.query(fn(customer), fn(orders))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q22.query(fn(customer), fn(orders)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q22.query(fn(customer), fn(orders))) diff --git a/tpch/execute/q3.py b/tpch/execute/q3.py deleted file mode 100644 index 17b7cf566..000000000 --- a/tpch/execute/q3.py +++ /dev/null @@ -1,20 +0,0 @@ -from __future__ import annotations - -from queries import q3 - -from . import IO_FUNCS -from . import customer -from . import lineitem -from . import orders - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q3.query(fn(customer), fn(lineitem), fn(orders))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q3.query(fn(customer), fn(lineitem), fn(orders)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q3.query(fn(customer), fn(lineitem), fn(orders))) diff --git a/tpch/execute/q4.py b/tpch/execute/q4.py deleted file mode 100644 index a1bfe95fc..000000000 --- a/tpch/execute/q4.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -from queries import q4 - -from . import IO_FUNCS -from . import line_item -from . import orders - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q4.query(fn(line_item), fn(orders))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q4.query(fn(line_item), fn(orders)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q4.query(fn(line_item), fn(orders))) diff --git a/tpch/execute/q5.py b/tpch/execute/q5.py deleted file mode 100644 index 2bdb05541..000000000 --- a/tpch/execute/q5.py +++ /dev/null @@ -1,35 +0,0 @@ -from __future__ import annotations - -from queries import q5 - -from . import IO_FUNCS -from . import customer -from . import line_item -from . import nation -from . import orders -from . import region -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print( - q5.query( - fn(region), fn(nation), fn(customer), fn(line_item), fn(orders), fn(supplier) - ) -) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print( - q5.query( - fn(region), fn(nation), fn(customer), fn(line_item), fn(orders), fn(supplier) - ).collect() -) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print( - q5.query( - fn(region), fn(nation), fn(customer), fn(line_item), fn(orders), fn(supplier) - ) -) diff --git a/tpch/execute/q6.py b/tpch/execute/q6.py deleted file mode 100644 index 8a87bd707..000000000 --- a/tpch/execute/q6.py +++ /dev/null @@ -1,18 +0,0 @@ -from __future__ import annotations - -from queries import q6 - -from . import IO_FUNCS -from . import lineitem - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q6.query(fn(lineitem))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print(q6.query(fn(lineitem)).collect()) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q6.query(fn(lineitem))) diff --git a/tpch/execute/q7.py b/tpch/execute/q7.py deleted file mode 100644 index ea15568f1..000000000 --- a/tpch/execute/q7.py +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import annotations - -from queries import q7 - -from . import IO_FUNCS -from . import customer -from . import lineitem -from . import nation -from . import orders -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print(q7.query(fn(nation), fn(customer), fn(lineitem), fn(orders), fn(supplier))) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print( - q7.query(fn(nation), fn(customer), fn(lineitem), fn(orders), fn(supplier)).collect() -) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print(q7.query(fn(nation), fn(customer), fn(lineitem), fn(orders), fn(supplier))) diff --git a/tpch/execute/q8.py b/tpch/execute/q8.py deleted file mode 100644 index 9e4f706a8..000000000 --- a/tpch/execute/q8.py +++ /dev/null @@ -1,55 +0,0 @@ -from __future__ import annotations - -from queries import q8 - -from . import IO_FUNCS -from . import customer -from . import lineitem -from . import nation -from . import orders -from . import part -from . import region -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print( - q8.query( - fn(part), - fn(supplier), - fn(lineitem), - fn(orders), - fn(customer), - fn(nation), - fn(region), - ) -) - - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print( - q8.query( - fn(part), - fn(supplier), - fn(lineitem), - fn(orders), - fn(customer), - fn(nation), - fn(region), - ).collect() -) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print( - q8.query( - fn(part), - fn(supplier), - fn(lineitem), - fn(orders), - fn(customer), - fn(nation), - fn(region), - ) -) diff --git a/tpch/execute/q9.py b/tpch/execute/q9.py deleted file mode 100644 index 6f191d763..000000000 --- a/tpch/execute/q9.py +++ /dev/null @@ -1,31 +0,0 @@ -from __future__ import annotations - -from queries import q9 - -from . import IO_FUNCS -from . import lineitem -from . import nation -from . import orders -from . import part -from . import partsupp -from . import supplier - -tool = "pandas[pyarrow]" -fn = IO_FUNCS[tool] -print( - q9.query(fn(part), fn(partsupp), fn(nation), fn(lineitem), fn(orders), fn(supplier)) -) - -tool = "polars[lazy]" -fn = IO_FUNCS[tool] -print( - q9.query( - fn(part), fn(partsupp), fn(nation), fn(lineitem), fn(orders), fn(supplier) - ).collect() -) - -tool = "pyarrow" -fn = IO_FUNCS[tool] -print( - q9.query(fn(part), fn(partsupp), fn(nation), fn(lineitem), fn(orders), fn(supplier)) -) diff --git a/tpch/tests/queries_test.py b/tpch/tests/queries_test.py index c228fd52b..2dfd7cc1c 100644 --- a/tpch/tests/queries_test.py +++ b/tpch/tests/queries_test.py @@ -4,20 +4,22 @@ import sys from pathlib import Path +import pytest -def test_execute_scripts() -> None: - root = Path(__file__).resolve().parent.parent - # directory containing all the queries - execute_dir = root / "execute" +ROOT_PATH = Path(__file__).resolve().parent.parent +# Directory containing all the query scripts +QUERIES_DIR = ROOT_PATH / "queries" - for script_path in execute_dir.glob("q[1-9]*.py"): - print(f"executing query {script_path.stem}") # noqa: T201 - result = subprocess.run( # noqa: S603 - [sys.executable, "-m", f"execute.{script_path.stem}"], - capture_output=True, - text=True, - check=False, - ) - assert ( - result.returncode == 0 - ), f"Script {script_path} failed with error: {result.stderr}" + +@pytest.mark.parametrize("query_path", QUERIES_DIR.glob("q[1-9]*.py")) +def test_execute_scripts(query_path: Path) -> None: + print(f"executing query {query_path.stem}") # noqa: T201 + result = subprocess.run( # noqa: S603 + [sys.executable, "-m", "execute", str(query_path.stem)], + capture_output=True, + text=True, + check=False, + ) + assert ( + result.returncode == 0 + ), f"Script {query_path} failed with error: {result.stderr}"