TPC-H Q13 — Customer Distribution
TPC-H benchmark · all TPC-H queries
Distribution of customers by order count
Representative SQL
Rendered for DataFusion with default parameters.
SELECT c_count, COUNT(*) AS custdistFROM ( SELECT c_custkey, COUNT(o_orderkey) FROM customer LEFT OUTER JOIN orders ON c_custkey = o_custkey AND o_comment NOT LIKE '%special%requests%' GROUP BY c_custkey) AS c_orders(c_custkey, c_count)GROUP BY c_countORDER BY custdist DESC, c_count DESCRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def q13_expression_impl(ctx: DataFrameContext) -> Any: customer = ctx.get_table("customer") orders = ctx.get_table("orders") col = ctx.col
params = get_tpch_parameters(13) word1 = params["word1"] word2 = params["word2"]
customer_orders = ( customer.join( orders.filter(~col("o_comment").str.contains(f"{word1}.*{word2}")), left_on="c_custkey", right_on="o_custkey", how="left", ) .group_by("c_custkey") .agg(col("o_orderkey").count().alias("c_count")) )
return ( customer_orders.group_by("c_count") .agg(col("c_custkey").count().alias("custdist")) .sort(["custdist", "c_count"], descending=[True, True]) )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['13'])Parameter substitution for this benchmark is seed-driven; pass a seed for a specific stream’s parameters:
print(bench.get_query(13, 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', '13', family="expression").source) # or family="pandas"Source
Query text: benchbox/_binaries/tpc-h/templates/queries/13.sql