Skip to content

Read Primitives — Left Join with GroupBy

Read Primitives benchmark · all Read Primitives queries

LEFT JOIN with preservation of all left-side rows

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
c.c_mktsegment,
COUNT(o.o_orderkey) AS order_count,
COUNT(*) AS total_rows
FROM customer AS c
LEFT 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_left_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_left_join_one_to_many_string_with_groupby', family="expression").source) # or family="pandas"

Source

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