Skip to content

CoffeeShop — Price Band Distribution

CoffeeShop benchmark · all CoffeeShop queries

Price-band distribution using multi-way CASE WHEN binning

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
CASE
WHEN ol.unit_price < 4
THEN 'Under $4'
WHEN ol.unit_price < 6
THEN '$4-$5.99'
WHEN ol.unit_price < 8
THEN '$6-$7.99'
ELSE '$8+'
END AS price_band,
COUNT(*) AS line_count,
SUM(ol.total_price) AS revenue
FROM order_lines AS ol
WHERE
ol.order_date BETWEEN CAST('2023-01-01' AS DATE) AND CAST('2024-12-31' AS DATE)
GROUP BY
price_band
ORDER BY
price_band

Representative DataFrame

Expression family (Polars, PySpark, DataFusion), default parameters.

def pr2_expression_impl(ctx: DataFrameContext) -> Any:
params = get_parameters("PR2")
start_date = params.get("start_date", "2023-01-01")
end_date = params.get("end_date", "2024-12-31")
ol = ctx.get_table("order_lines")
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)))
)
.with_columns(
ctx.when(col("unit_price") < lit(4))
.then(lit("Under $4"))
.otherwise(
ctx.when(col("unit_price") < lit(6))
.then(lit("$4-$5.99"))
.otherwise(ctx.when(col("unit_price") < lit(8)).then(lit("$6-$7.99")).otherwise(lit("$8+")))
)
.alias("price_band")
)
.group_by("price_band")
.agg(
col("price_band").count().alias("line_count"),
col("total_price").sum().alias("revenue"),
)
.sort("price_band")
)

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 factor
queries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQL
print(queries['PR2'])

For the DataFrame form:

from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('coffeeshop', 'PR2', family="expression").source) # or family="pandas"

Source

Query text: benchbox/core/coffeeshop/queries.py