Skip to content

Read Primitives — Predicate Ordering with GroupBy

Read Primitives benchmark · all Read Primitives queries

Order filter predicates by selectivity for aggregation within a low cardinality grouping

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
l_returnflag,
SUM(l_quantity) AS total_qty
FROM lineitem
WHERE
l_shipdate <= CAST('1998-09-01' AS DATE)
AND l_discount > 0.05
AND l_tax < 0.08
AND l_quantity BETWEEN 10 AND 30
GROUP BY
l_returnflag

Representative DataFrame

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

def predicate_ordering_groupby_expression_impl(ctx: DataFrameContext) -> Any:
col, lit = ctx.col, ctx.lit
return (
ctx.get_table("lineitem")
.filter(
(col("l_shipdate") <= lit(date(1998, 9, 1)))
& (col("l_discount") > lit(0.05))
& (col("l_tax") < lit(0.08))
& (col("l_quantity") >= lit(10))
& (col("l_quantity") <= lit(30))
)
.group_by("l_returnflag")
.agg(col("l_quantity").sum().alias("total_qty"))
)

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

For the DataFrame form:

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

Source

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