Read Primitives — Window Moving Frame
Read Primitives benchmark · all Read Primitives queries
Window aggregations with complex moving frame definitions
Representative SQL
Rendered for DataFusion with default parameters.
SELECT o_orderkey, o_orderdate, o_totalprice, AVG(o_totalprice) OVER (ORDER BY o_orderdate, o_orderkey ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS moving_avg_6_orders, SUM(o_totalprice) OVER (ORDER BY o_orderdate RANGE BETWEEN INTERVAL '30 DAY' PRECEDING AND CURRENT ROW) AS monthly_running_totalFROM ordersWHERE o_orderdate >= CAST('1995-01-01' AS DATE) AND o_orderdate < CAST('1996-01-01' AS DATE)ORDER BY o_orderdate, o_orderkeyRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def window_moving_frame_expression_impl(ctx: DataFrameContext) -> Any: import polars as pl
lf = ( ctx.get_table("orders") .native.filter((pl.col("o_orderdate") >= date(1995, 1, 1)) & (pl.col("o_orderdate") < date(1996, 1, 1))) .sort(["o_orderdate", "o_orderkey"]) ) return lf.with_columns( pl.col("o_totalprice").rolling_mean(window_size=6, min_samples=1).alias("moving_avg_6_orders"), pl.col("o_totalprice") .rolling_sum_by("o_orderdate", window_size="30d", closed="both") .alias("monthly_running_total"), ).select("o_orderkey", "o_orderdate", "o_totalprice", "moving_avg_6_orders", "monthly_running_total")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_moving_frame'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('read_primitives', 'window_moving_frame', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/read_primitives/queries.py