TPC-DS-OBT Q6 — obt_avg_ticket_by_channel
TPC-DS-OBT benchmark · all TPC-DS-OBT queries
Average ticket and sales count by channel
Representative SQL
Rendered for DataFusion with default parameters.
SELECT bill_addr_ca_state AS state, COUNT(*) AS cntFROM tpcds_sales_returns_obt AS obtWHERE ( bill_addr_ca_address_sk = bill_customer_c_current_addr_sk AND bill_customer_c_customer_sk = obt.ship_customer_sk AND obt.sold_date_sk = sold_date_d_date_sk AND obt.item_sk = item_i_item_sk AND sold_date_d_month_seq = ( SELECT DISTINCT ( obt.sold_date_d_month_seq ) FROM tpcds_sales_returns_obt AS obt WHERE ( obt.sold_date_d_year = 1998 AND obt.sold_date_d_moy = 1 ) AND channel = 'store' ) AND item_i_current_price > 1.2 * ( SELECT AVG(item_i_current_price) FROM tpcds_sales_returns_obt AS obt WHERE item_i_category = obt.item_i_category AND channel = 'store' ) ) AND channel = 'store'GROUP BY bill_addr_ca_stateHAVING COUNT(*) >= 10ORDER BY cnt, bill_addr_ca_stateLIMIT 100Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def impl(ctx: DataFrameContext) -> Any: table = ctx.get_table(OBT_TABLE) for column, op, value in spec.filters: table = table.filter(_FILTER_OPS[op](ctx.col(column), ctx.lit(value))) aggregates = [getattr(ctx.col(column), func)().alias(alias) for alias, column, func in spec.aggregations] if spec.group_keys: result = table.group_by(*spec.group_keys).agg(*aggregates) else: result = table.select(*aggregates) if spec.sort_keys: descending = list(spec.descending) if spec.descending else [False] * len(spec.sort_keys) result = result.sort(list(spec.sort_keys), descending=descending) if spec.limit: result = result.limit(spec.limit) return resultGet 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 TPCDSOBT
bench = TPCDSOBT(scale_factor=1.0) # your scale factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['6'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('tpcds_obt', '6', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/tpcds_obt/queries.py