Read Primitives — Window RANK
Read Primitives benchmark · all Read Primitives queries
Window function RANK() OVER (PARTITION BY … ORDER BY …)
Representative SQL
Rendered for DataFusion with default parameters.
SELECT l_orderkey, l_returnflag, l_quantity, qty_rankFROM ( SELECT l_orderkey, l_returnflag, l_quantity, RANK() OVER (PARTITION BY l_returnflag ORDER BY l_quantity DESC) AS qty_rank FROM lineitem) AS rankedWHERE qty_rank <= 5ORDER BY l_returnflag, qty_rank, l_orderkeyRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def window_rank_expression_impl(ctx: DataFrameContext) -> Any: result = ctx.get_table("lineitem").with_columns( ctx.window_rank(order_by=[("l_quantity", False)], partition_by=["l_returnflag"]).alias("qty_rank") ) return ( result.filter(ctx.col("qty_rank") <= 5) .select("l_orderkey", "l_returnflag", "l_quantity", "qty_rank") .sort(["l_returnflag", "qty_rank", "l_orderkey"]) )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['window_rank'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('read_primitives', 'window_rank', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/read_primitives/queries.py