Read Primitives — QUALIFY PERCENT_RANK
Read Primitives benchmark · all Read Primitives queries
Find orders in top 10% per priority using PERCENT_RANK
Representative SQL
Rendered for DataFusion with default parameters.
SELECT o_orderpriority, o_orderkey, o_totalprice, price_percentileFROM ( SELECT o_orderpriority, o_orderkey, o_totalprice, PERCENT_RANK() OVER (PARTITION BY o_orderpriority ORDER BY o_totalprice) AS price_percentile, PERCENT_RANK() OVER (PARTITION BY o_orderpriority ORDER BY o_totalprice) AS _w FROM orders WHERE o_orderdate >= CAST('1995-01-01' AS DATE) ORDER BY o_orderpriority, o_totalprice DESC) AS _tWHERE _w >= 0.9Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def qualify_percentile_expression_impl(ctx: DataFrameContext) -> Any: result = ( ctx.get_table("orders") .filter(ctx.col("o_orderdate") >= ctx.lit(date(1995, 1, 1))) .with_columns( ctx.window_percent_rank(order_by=[("o_totalprice", True)], partition_by=["o_orderpriority"]).alias( "price_percentile" ) ) ) return ( result.filter(ctx.col("price_percentile") >= ctx.lit(0.9)) .select("o_orderpriority", "o_orderkey", "o_totalprice", "price_percentile") .sort(["o_orderpriority", "o_totalprice"], descending=[False, True]) )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 factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['qualify_percentile'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('read_primitives', 'qualify_percentile', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/read_primitives/queries.py