Skip to content

TPC-H Skew Q13 — Customer Distribution

TPC-H Skew benchmark · all TPC-H Skew queries

Distribution of customers by order count

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
c_count,
COUNT(*) AS custdist
FROM (
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_count
ORDER BY
custdist DESC,
c_count DESC

Representative 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 TPCHSkew
bench = TPCHSkew(scale_factor=0.01) # your scale factor
queries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQL
print(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_skew', '13', family="expression").source) # or family="pandas"

Source

Query text: benchbox/_binaries/tpc-h/templates/queries/13.sql