TPC-DS Q90 — Web Sales AM/PM Ratio Analysis
TPC-DS benchmark · all TPC-DS queries
Computes the ratio of AM to PM web sales counts
Representative SQL
Rendered for DataFusion with default parameters.
SELECT CAST(amc AS DECIMAL(15, 4)) / NULLIF(CAST(pmc AS DECIMAL(15, 4)), 0) AS am_pm_ratioFROM ( SELECT COUNT(*) AS amc FROM web_sales, household_demographics, time_dim, web_page WHERE ws_sold_time_sk = time_dim.t_time_sk AND ws_ship_hdemo_sk = household_demographics.hd_demo_sk AND ws_web_page_sk = web_page.wp_web_page_sk AND time_dim.t_hour BETWEEN 6 AND 6 + 1 AND household_demographics.hd_dep_count = 8 AND web_page.wp_char_count BETWEEN 5000 AND 5200) AS at, ( SELECT COUNT(*) AS pmc FROM web_sales, household_demographics, time_dim, web_page WHERE ws_sold_time_sk = time_dim.t_time_sk AND ws_ship_hdemo_sk = household_demographics.hd_demo_sk AND ws_web_page_sk = web_page.wp_web_page_sk AND time_dim.t_hour BETWEEN 14 AND 14 + 1 AND household_demographics.hd_dep_count = 8 AND web_page.wp_char_count BETWEEN 5000 AND 5200) AS ptORDER BY am_pm_ratioLIMIT 100Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def q90_expression_impl(ctx: DataFrameContext) -> Any: hour_am, hour_pm, dep_count, char_min, char_max = _q90_params() col = ctx.col lit = ctx.lit base = ( ctx.get_table("web_sales") .join(ctx.get_table("time_dim"), left_on="ws_sold_time_sk", right_on="t_time_sk") .join(ctx.get_table("household_demographics"), left_on="ws_ship_hdemo_sk", right_on="hd_demo_sk") .join(ctx.get_table("web_page"), left_on="ws_web_page_sk", right_on="wp_web_page_sk") .filter((col("hd_dep_count") == lit(dep_count)) & col("wp_char_count").is_between(char_min, char_max)) ) am_val = base.filter(col("t_hour").is_between(hour_am, hour_am + 1)).select(ctx.count().alias("amc")).scalar(0, 0) pm_val = base.filter(col("t_hour").is_between(hour_pm, hour_pm + 1)).select(ctx.count().alias("pmc")).scalar(0, 0) return ctx.create_dataframe({"am_pm_ratio": [am_val / pm_val if pm_val and pm_val > 0 else None]})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['90'])Parameter substitution for this benchmark is seed-driven; pass a seed for a specific stream’s parameters:
print(bench.get_query(90, 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', '90', family="expression").source) # or family="pandas"Source
Query text: _sources/tpc-ds/query_templates/query90.tpl