Skip to content

CoffeeShop — Top Locations

CoffeeShop benchmark · all CoffeeShop queries

Top-performing locations by revenue with multi-column GROUP BY

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
dl.location_id,
dl.city,
dl.state,
dl.region,
COUNT(DISTINCT ol.order_id) AS orders,
SUM(ol.total_price) AS revenue,
AVG(ol.total_price) AS avg_line_value
FROM order_lines AS ol
JOIN dim_locations AS dl
ON ol.location_record_id = dl.record_id
WHERE
ol.order_date BETWEEN CAST('2023-01-01' AS DATE) AND CAST('2024-12-31' AS DATE)
GROUP BY
dl.location_id,
dl.city,
dl.state,
dl.region
ORDER BY
revenue DESC
LIMIT 20

Representative DataFrame

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

def sa5_expression_impl(ctx: DataFrameContext) -> Any:
params = get_parameters("SA5")
start_date = params.get("start_date", "2023-01-01")
end_date = params.get("end_date", "2024-12-31")
limit = params.get("limit", 20)
ol = ctx.get_table("order_lines")
dl = ctx.get_table("dim_locations")
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(dl, left_on="location_record_id", right_on="record_id")
.group_by("location_id", "city", "state", "region")
.agg(
col("order_id").n_unique().alias("orders"),
col("total_price").sum().alias("revenue"),
col("total_price").mean().alias("avg_line_value"),
)
.sort("revenue", descending=True)
.limit(limit)
)

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['SA5'])

For the DataFrame form:

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

Source

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