Skip to content

TPC-H Skew Q14 — Promotion Effect

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

Effect of promotions on revenue

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
100.00 * SUM(
CASE
WHEN p_type LIKE 'PROMO%'
THEN l_extendedprice * (
1 - l_discount
)
ELSE 0
END
) / SUM(l_extendedprice * (
1 - l_discount
)) AS promo_revenue
FROM lineitem, part
WHERE
l_partkey = p_partkey
AND l_shipdate >= CAST('1995-09-01' AS DATE)
AND l_shipdate < CAST('1995-09-01' AS DATE) + INTERVAL '1 MONTH'

Representative DataFrame

Expression family (Polars, PySpark, DataFusion), default parameters.

def q14_expression_impl(ctx: DataFrameContext) -> Any:
lineitem = ctx.get_table("lineitem")
part = ctx.get_table("part")
col = ctx.col
lit = ctx.lit
params = get_tpch_parameters(14)
start_date = params["start_date"]
end_date = params["end_date"]
return (
lineitem.filter((col("l_shipdate") >= lit(start_date)) & (col("l_shipdate") < lit(end_date)))
.join(part, left_on="l_partkey", right_on="p_partkey")
.select(
(
lit(100.0)
* (col("l_extendedprice") * (lit(1) - col("l_discount")))
.filter(col("p_type").str.starts_with("PROMO"))
.sum()
/ (col("l_extendedprice") * (lit(1) - col("l_discount"))).sum()
).alias("promo_revenue")
)
)

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['14'])

Parameter substitution for this benchmark is seed-driven; pass a seed for a specific stream’s parameters:

print(bench.get_query(14, 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', '14', family="expression").source) # or family="pandas"

Source

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