TPC-H Q18 — Large Volume Customer
TPC-H benchmark · all TPC-H queries
Customers with large orders
Representative SQL
Rendered for DataFusion with default parameters.
SELECT c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, SUM(l_quantity)FROM customer, orders, lineitemWHERE o_orderkey IN ( SELECT l_orderkey FROM lineitem GROUP BY l_orderkey HAVING SUM(l_quantity) > 300 ) AND c_custkey = o_custkey AND o_orderkey = l_orderkeyGROUP BY c_name, c_custkey, o_orderkey, o_orderdate, o_totalpriceORDER BY o_totalprice DESC, o_orderdateLIMIT 100Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def q18_expression_impl(ctx: DataFrameContext) -> Any: customer = ctx.get_table("customer") orders = ctx.get_table("orders") lineitem = ctx.get_table("lineitem") col = ctx.col lit = ctx.lit
params = get_tpch_parameters(18) quantity_threshold = params["quantity_threshold"]
large_orders = ( lineitem.group_by("l_orderkey") .agg(col("l_quantity").sum().alias("total_qty")) .filter(col("total_qty") > lit(quantity_threshold)) .select("l_orderkey") )
return ( customer.join(orders, left_on="c_custkey", right_on="o_custkey") .join(large_orders, left_on="o_orderkey", right_on="l_orderkey", how="semi") .join(lineitem, left_on="o_orderkey", right_on="l_orderkey") .group_by("c_name", "c_custkey", "o_orderkey", "o_orderdate", "o_totalprice") .agg(col("l_quantity").sum().alias("sum_qty")) .sort(["o_totalprice", "o_orderdate"], descending=[True, False]) .limit(100) )Get the exact query for your run
The blocks above are representative. To get the precise statement a specific platform runs at a specific scale, substitute your own values:
from benchbox import TPCH
bench = TPCH(scale_factor=0.01) # your scale factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['18'])Parameter substitution for this benchmark is seed-driven; pass a seed for a specific stream’s parameters:
print(bench.get_query(18, scale_factor=0.01, seed=42, dialect="datafusion"))For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('tpch', '18', family="expression").source) # or family="pandas"Source
Query text: benchbox/_binaries/tpc-h/templates/queries/18.sql