Skip to main content
PYSPARK โ€ข LESSON 276

Sliding (Hopping) Time Window Aggregations

How can we calculate 10-minute moving window aggregations that update every 2 minutes (overlapping windows)?

Productionโฑ 3 Minutesโญ 850 XP
๐Ÿค” THE QUESTION

How can we calculate 10-minute moving window aggregations that update every 2 minutes (overlapping windows)?

๐Ÿ’ก WHAT IS IT?

window('event_timestamp', '10 minutes', '2 minutes') specifies a 10-minute window length sliding forward every 2 minutes.

๐ŸŽฏ WHAT IS IT USED FOR?

Smoothed real-time anomaly detection, fraud velocity scoring, and continuous moving averages on streams.

๐Ÿ’ป EXAMPLE
df_sliding = df_watermarked.groupBy(window(col("event_timestamp"), "10 minutes", "2 minutes"), col("device_id")).agg(avg("cpu_usage").alias("avg_cpu"))

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Sliding (Hopping) Time Window Aggregations.

  • โœ“ window() sliding specification
  • โœ“ Overlapping hopping windows
  • โœ“ Streaming velocity monitoring