CoffeeShop — Product Mix
CoffeeShop benchmark · all CoffeeShop queries
Product mix by subcategory with date validity check on dim_products
Representative SQL
Rendered for DataFusion with default parameters.
SELECT dp.subcategory, COUNT(DISTINCT dp.product_id) AS active_products, SUM(ol.quantity) AS quantity_sold, SUM(ol.total_price) AS revenueFROM order_lines AS olJOIN dim_products AS dp ON ol.product_record_id = dp.record_idWHERE ol.order_date BETWEEN CAST('2023-01-01' AS DATE) AND CAST('2023-12-31' AS DATE) AND ol.order_date BETWEEN dp.from_date AND dp.to_dateGROUP BY dp.subcategoryORDER BY revenue DESCRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def pr1_expression_impl(ctx: DataFrameContext) -> Any: params = get_parameters("PR1") start_date = params.get("start_date", "2023-01-01") end_date = params.get("end_date", "2023-12-31")
ol = ctx.get_table("order_lines") dp = ctx.get_table("dim_products") col = ctx.col lit = ctx.lit
return ( ol.filter( (col("order_date") >= lit(_parse_date(start_date))) & (col("order_date") <= lit(_parse_date(end_date))) ) .join(dp, left_on="product_record_id", right_on="record_id") .filter((col("order_date") >= col("from_date")) & (col("order_date") <= col("to_date"))) .group_by("subcategory") .agg( col("product_id").n_unique().alias("active_products"), col("quantity").sum().alias("quantity_sold"), col("total_price").sum().alias("revenue"), ) .sort("revenue", descending=True) )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 CoffeeShop
bench = CoffeeShop(scale_factor=0.001) # your scale factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['PR1'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('coffeeshop', 'PR1', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/coffeeshop/queries.py