Skip to content

Read Primitives — Statistical Percentiles

Read Primitives benchmark · all Read Primitives queries

Percentile calculation functions for distribution analysis

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
l_returnflag,
l_linestatus,
COUNT(*) AS record_count,
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY
l_quantity) AS quantity_q1,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY
l_quantity) AS quantity_median,
PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY
l_quantity) AS quantity_q3,
PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY
l_extendedprice) AS price_p95
FROM lineitem
GROUP BY
l_returnflag,
l_linestatus

Representative DataFrame

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

def impl(ctx: DataFrameContext) -> Any:
return aggregation_groupby_impl(
ctx,
table_name=table_name,
group_cols=group_cols,
agg_specs=agg_specs,
conditions=conditions,
sort_cols=sort_cols,
sort_desc=sort_desc,
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 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['statistical_percentiles'])

For the DataFrame form:

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

Source

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