How do we define a 10-minute watermark to drop late data and count events in 5-minute tumbling windows?
withWatermark() specifies how late data can arrive before being discarded from in-memory state stores.
Real-time windowed metrics, DDoS detection, and rolling traffic volume monitoring.
from pyspark.sql.functions import col, window
windowed_counts = streaming_df \
.withWatermark("event_time", "10 minutes") \
.groupBy(window(col("event_time"), "5 minutes"), col("device_type")) \
.count()Practice typing production-grade PySpark code for Watermarking & Stateful Streaming Aggregations.