Skip to content

Read Primitives — Inner Join with GroupBy

Read Primitives benchmark · all Read Primitives queries

Standard inner join with one-to-many relationship

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
c.c_mktsegment,
COUNT(*) AS order_count,
SUM(o.o_totalprice) AS total_revenue
FROM customer AS c
INNER JOIN orders AS o
ON c.c_custkey = o.o_custkey
GROUP BY
c.c_mktsegment

Representative DataFrame

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

def expression_impl(ctx: DataFrameContext) -> Any:
joined = ctx.get_table("customer").join(
ctx.get_table("orders"), left_on="c_custkey", right_on="o_custkey", how=how
)
return joined.group_by("c_mktsegment").agg(
*(getattr(ctx.col(col), func)().alias(alias) for col, func, alias in aggs)
)

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

For the DataFrame form:

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

Source

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