A PySpark job defines the following window spec for cumulative metrics: w = Window.partitionBy('customer_id').orderBy('event_time') and then computes F.sum('amount').over(w) without calling rowsBetween or rangeBetween. Which window frame is used by default, and what is the correct way to compute a rolling sum over the last 7 rows per customer (row-based, not value/range-based)?
Answer & explanation
Correct answer: B
WHY B: In PySpark, when ordering is defined, the default frame is a growing range frame from unbounded preceding to current row (rangeFrame, UNBOUNDED PRECEDING to CURRENT ROW). To get the last 7 rows (row-count based), you must explicitly specify a row frame like rowsBetween(-6, 0). WHY NOT A: With an ORDER BY, Spark does not default to a full-partition, unbounded-following frame, and it never auto-limits to 7 rows. WHY NOT C: rangeBetween(-6, 0) is range/value-based and depends on the ordering column’s value semantics; it’s not “last 7 rows”. WHY NOT D: Spark does not require an explicit frame; it chooses a default based on whether ordering is defined.