TPC-H Skew Q19 — Discounted Revenue
TPC-H Skew benchmark · all TPC-H Skew queries
Revenue for parts with specific conditions
Representative SQL
Rendered for DataFusion with default parameters.
SELECT SUM(l_extendedprice * ( 1 - l_discount )) AS revenueFROM lineitem, partWHERE ( p_partkey = l_partkey AND p_brand = 'Brand#12' AND p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') AND l_quantity >= 1 AND l_quantity <= 1 + 10 AND p_size BETWEEN 1 AND 5 AND l_shipmode IN ('AIR', 'AIR REG') AND l_shipinstruct = 'DELIVER IN PERSON' ) OR ( p_partkey = l_partkey AND p_brand = 'Brand#23' AND p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') AND l_quantity >= 10 AND l_quantity <= 10 + 10 AND p_size BETWEEN 1 AND 10 AND l_shipmode IN ('AIR', 'AIR REG') AND l_shipinstruct = 'DELIVER IN PERSON' ) OR ( p_partkey = l_partkey AND p_brand = 'Brand#34' AND p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') AND l_quantity >= 20 AND l_quantity <= 20 + 10 AND p_size BETWEEN 1 AND 15 AND l_shipmode IN ('AIR', 'AIR REG') AND l_shipinstruct = 'DELIVER IN PERSON' )Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def q19_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(19) brand1 = params["brand1"] brand2 = params["brand2"] brand3 = params["brand3"] quantity1 = params["quantity1"] quantity2 = params["quantity2"] quantity3 = params["quantity3"]
sm_containers = ["SM CASE", "SM BOX", "SM PACK", "SM PKG"] med_containers = ["MED BAG", "MED BOX", "MED PKG", "MED PACK"] lg_containers = ["LG CASE", "LG BOX", "LG PACK", "LG PKG"] ship_modes = ["AIR", "AIR REG"]
return ( lineitem.join(part, left_on="l_partkey", right_on="p_partkey") .filter( col("l_shipmode").is_in(ship_modes) & (col("l_shipinstruct") == lit("DELIVER IN PERSON")) & ( ( (col("p_brand") == lit(brand1)) & col("p_container").is_in(sm_containers) & (col("l_quantity") >= lit(quantity1)) & (col("l_quantity") <= lit(quantity1 + 10)) & (col("p_size") >= lit(1)) & (col("p_size") <= lit(5)) ) | ( (col("p_brand") == lit(brand2)) & col("p_container").is_in(med_containers) & (col("l_quantity") >= lit(quantity2)) & (col("l_quantity") <= lit(quantity2 + 10)) & (col("p_size") >= lit(1)) & (col("p_size") <= lit(10)) ) | ( (col("p_brand") == lit(brand3)) & col("p_container").is_in(lg_containers) & (col("l_quantity") >= lit(quantity3)) & (col("l_quantity") <= lit(quantity3 + 10)) & (col("p_size") >= lit(1)) & (col("p_size") <= lit(15)) ) ) ) .select((col("l_extendedprice") * (lit(1) - col("l_discount"))).alias("revenue")) .sum() )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 factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['19'])Parameter substitution for this benchmark is seed-driven; pass a seed for a specific stream’s parameters:
print(bench.get_query(19, 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', '19', family="expression").source) # or family="pandas"Source
Query text: benchbox/_binaries/tpc-h/templates/queries/19.sql