TPC-H Q7 — Volume Shipping
TPC-H benchmark · all TPC-H queries
Value of goods shipped between nations
Representative SQL
Rendered for DataFusion with default parameters.
SELECT supp_nation, cust_nation, l_year, SUM(volume) AS revenueFROM ( SELECT n1.n_name AS supp_nation, n2.n_name AS cust_nation, EXTRACT(YEAR FROM l_shipdate) AS l_year, l_extendedprice * ( 1 - l_discount ) AS volume FROM supplier, lineitem, orders, customer, nation AS n1, nation AS n2 WHERE s_suppkey = l_suppkey AND o_orderkey = l_orderkey AND c_custkey = o_custkey AND s_nationkey = n1.n_nationkey AND c_nationkey = n2.n_nationkey AND ( ( n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY' ) OR ( n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE' ) ) AND l_shipdate BETWEEN CAST('1995-01-01' AS DATE) AND CAST('1996-12-31' AS DATE)) AS shippingGROUP BY supp_nation, cust_nation, l_yearORDER BY supp_nation, cust_nation, l_yearRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def q7_expression_impl(ctx: DataFrameContext) -> Any: supplier = ctx.get_table("supplier") lineitem = ctx.get_table("lineitem") orders = ctx.get_table("orders") customer = ctx.get_table("customer") nation = ctx.get_table("nation") col = ctx.col lit = ctx.lit
params = get_tpch_parameters(7) nation1 = params["nation1"] nation2 = params["nation2"] start_date = params["start_date"] end_date = params["end_date"]
n1 = nation.select(col("n_nationkey").alias("n1_nationkey"), col("n_name").alias("supp_nation")) n2 = nation.select(col("n_nationkey").alias("n2_nationkey"), col("n_name").alias("cust_nation"))
return ( supplier.join(n1, left_on="s_nationkey", right_on="n1_nationkey") .join(lineitem, left_on="s_suppkey", right_on="l_suppkey") .filter((col("l_shipdate") >= lit(start_date)) & (col("l_shipdate") <= lit(end_date))) .join(orders, left_on="l_orderkey", right_on="o_orderkey") .join(customer, left_on="o_custkey", right_on="c_custkey") .join(n2, left_on="c_nationkey", right_on="n2_nationkey") .filter( ((col("supp_nation") == lit(nation1)) & (col("cust_nation") == lit(nation2))) | ((col("supp_nation") == lit(nation2)) & (col("cust_nation") == lit(nation1))) ) .with_columns( col("l_shipdate").dt.year().alias("l_year"), (col("l_extendedprice") * (lit(1) - col("l_discount"))).alias("volume"), ) .group_by("supp_nation", "cust_nation", "l_year") .agg(col("volume").sum().alias("revenue")) .sort("supp_nation", "cust_nation", "l_year") )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['7'])Parameter substitution for this benchmark is seed-driven; pass a seed for a specific stream’s parameters:
print(bench.get_query(7, 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', '7', family="expression").source) # or family="pandas"Source
Query text: benchbox/_binaries/tpc-h/templates/queries/7.sql