Skip to content

Read Primitives — Predicate Ordering with Aggregation

Read Primitives benchmark · all Read Primitives queries

Order filter predicates by selectivity for aggregation

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
SUM(l_extendedprice) AS total_price
FROM lineitem
WHERE
l_shipdate >= CAST('1994-01-01' AS DATE)
AND l_shipdate < CAST('1995-01-01' AS DATE)
AND l_discount BETWEEN 0.05 AND 0.07
AND l_quantity < 24

Representative DataFrame

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

def predicate_ordering_aggregation_expression_impl(ctx: DataFrameContext) -> Any:
col, lit = ctx.col, ctx.lit
return (
ctx.get_table("lineitem")
.filter(
(col("l_shipdate") >= lit(date(1994, 1, 1)))
& (col("l_shipdate") < lit(date(1995, 1, 1)))
& (col("l_discount") >= lit(0.05))
& (col("l_discount") <= lit(0.07))
& (col("l_quantity") < lit(24))
)
.select(col("l_extendedprice").sum().alias("total_price"))
)

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

For the DataFrame form:

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

Source

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