TPC-DS Q34 — Store Sales County Household
TPC-DS benchmark · all TPC-DS queries
Analyzes customer purchases by county and household demographics
Representative SQL
Rendered for DataFusion with default parameters.
SELECT c_last_name, c_first_name, c_salutation, c_preferred_cust_flag, ss_ticket_number, cntFROM ( SELECT ss_ticket_number, ss_customer_sk, COUNT(*) AS cnt FROM store_sales, date_dim, store, household_demographics WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk AND store_sales.ss_store_sk = store.s_store_sk AND store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk AND ( date_dim.d_dom BETWEEN 1 AND 3 OR date_dim.d_dom BETWEEN 25 AND 28 ) AND ( household_demographics.hd_buy_potential = '>10000' OR household_demographics.hd_buy_potential = 'Unknown' ) AND household_demographics.hd_vehicle_count > 0 AND ( CASE WHEN household_demographics.hd_vehicle_count > 0 THEN household_demographics.hd_dep_count / household_demographics.hd_vehicle_count ELSE NULL END ) > 1.2 AND date_dim.d_year IN (1998, 1998 + 1, 1998 + 2) AND store.s_county IN ( 'Williamson County', 'Williamson County', 'Williamson County', 'Williamson County', 'Williamson County', 'Williamson County', 'Williamson County', 'Williamson County' ) GROUP BY ss_ticket_number, ss_customer_sk) AS dn, customerWHERE ss_customer_sk = c_customer_sk AND cnt BETWEEN 15 AND 20ORDER BY c_last_name, c_first_name, c_salutation, c_preferred_cust_flag DESC, ss_ticket_numberRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def q34_expression_impl(ctx: DataFrameContext) -> Any: params = get_parameters(34) year = params.get("year", 1998) counties = params.get( "counties", [ "Williamson County", "Williamson County", "Williamson County", "Williamson County", "Williamson County", "Williamson County", "Williamson County", "Williamson County", ], ) buy_potential_1 = params.get("buy_potential_1", ">10000") buy_potential_2 = params.get("buy_potential_2", "Unknown")
store_sales, date_dim, store, household_demographics, customer = _tables( ctx, "store_sales", "date_dim", "store", "household_demographics", "customer" ) col = ctx.col lit = ctx.lit
ticket_agg = ( store_sales.join(date_dim, left_on="ss_sold_date_sk", right_on="d_date_sk") .join(store, left_on="ss_store_sk", right_on="s_store_sk") .join(household_demographics, left_on="ss_hdemo_sk", right_on="hd_demo_sk") .filter( ( (col("d_dom") >= lit(1)) & (col("d_dom") <= lit(3)) | (col("d_dom") >= lit(25)) & (col("d_dom") <= lit(28)) ) & ((col("hd_buy_potential") == lit(buy_potential_1)) | (col("hd_buy_potential") == lit(buy_potential_2))) & (col("hd_vehicle_count") > lit(0)) & ((col("hd_dep_count") / col("hd_vehicle_count")) > lit(1.2)) & (col("d_year").is_in([year, year + 1, year + 2])) & col("s_county").is_in(counties) ) .group_by("ss_ticket_number", "ss_customer_sk") .agg(col("ss_ticket_number").count().alias("cnt")) .filter((col("cnt") >= lit(15)) & (col("cnt") <= lit(20))) )
result = ticket_agg.join(customer, left_on="ss_customer_sk", right_on="c_customer_sk").select( col("c_last_name"), col("c_first_name"), col("c_salutation"), col("c_preferred_cust_flag"), col("ss_ticket_number"), col("cnt"), ) return _sort_null_largest_expression( ctx, result, ["c_last_name", "c_first_name", "c_salutation", "c_preferred_cust_flag", "ss_ticket_number"], [False, False, False, True, False], )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 TPCDS
bench = TPCDS(scale_factor=1.0) # your scale factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['34'])Parameter substitution for this benchmark is seed-driven; pass a seed for a specific stream’s parameters:
print(bench.get_query(34, scale_factor=1.0, seed=42, dialect="datafusion"))For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('tpcds', '34', family="expression").source) # or family="pandas"Source
Query text: _sources/tpc-ds/query_templates/query34.tpl