Skip to content

Read Primitives — Window ROW_NUMBER

Read Primitives benchmark · all Read Primitives queries

Window function ROW_NUMBER() OVER (PARTITION BY … ORDER BY …)

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
o_custkey,
o_orderkey,
o_totalprice,
ROW_NUMBER() OVER (PARTITION BY o_custkey ORDER BY o_totalprice DESC) AS order_rank
FROM orders
WHERE
o_orderdate >= CAST('1995-01-01' AS DATE)
AND o_orderdate < CAST('1996-01-01' AS DATE)

Representative DataFrame

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

def window_row_number_expression_impl(ctx: DataFrameContext) -> Any:
col, lit = ctx.col, ctx.lit
return (
ctx.get_table("orders")
.filter((col("o_orderdate") >= lit(date(1995, 1, 1))) & (col("o_orderdate") < lit(date(1996, 1, 1))))
.with_columns(
ctx.window_row_number(order_by=[("o_totalprice", False)], partition_by=["o_custkey"]).alias("order_rank")
)
.select("o_custkey", "o_orderkey", "o_totalprice", "order_rank")
)

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

For the DataFrame form:

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

Source

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