Skip to content

Read Primitives — Window Running Sum

Read Primitives benchmark · all Read Primitives queries

Window function SUM() OVER (ORDER BY …) - cumulative sum

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
o_orderkey,
o_orderdate,
o_totalprice,
SUM(o_totalprice) OVER (ORDER BY o_orderdate) AS cumulative_revenue
FROM orders
ORDER BY
o_orderdate
LIMIT 100

Representative DataFrame

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

def window_running_sum_expression_impl(ctx: DataFrameContext) -> Any:
col = ctx.col
orders = ctx.get_table("orders")
daily = (
orders.group_by("o_orderdate")
.agg(col("o_totalprice").sum().alias("_daily_total"))
.sort("o_orderdate")
.with_columns(ctx.window_sum("_daily_total", order_by=[("o_orderdate", True)]).alias("cumulative_revenue"))
.select("o_orderdate", "cumulative_revenue")
)
return (
orders.join(daily, on="o_orderdate")
.sort("o_orderdate")
.select("o_orderkey", "o_orderdate", "o_totalprice", "cumulative_revenue")
.limit(100)
)

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

For the DataFrame form:

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

Source

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