Home / DE Professional practice test / Data Transformation, Cleansing, and Quality / Question

Databricks Data Engineer Professional · free practice question

A PySpark job defines the following window spec for cumulative metrics: `w = Window.partitionBy('customer_id').orderBy('event_time')` and then computes…

Exam-style question on Data Transformation, Cleansing, and Quality from the free DE Professional practice test, with the answer and a full explanation below.

Updated November 16, 2026

Data Transformation, Cleansing, and Quality Medium

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)?

  1. ADefault: ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. Rolling 7 rows: keep the same spec; Spark automatically limits to the last 7 rows when an ORDER BY is present.
  2. BDefault: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW when an ordering is defined. Rolling 7 rows: w7 = w.rowsBetween(-6, 0) and then F.sum('amount').over(w7).
  3. CDefault: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW when an ordering is defined. Rolling 7 rows: w7 = w.rangeBetween(-6, 0) and then F.sum('amount').over(w7).
  4. DDefault: no frame is defined; Spark throws an error unless you specify either rowsBetween or rangeBetween. Rolling 7 rows: w7 = w.rowsBetween(-7, -1).
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.

Take the full DE Professional practice test free →

Would you pass today?

This question is one of 60 in the free, timed Databricks Data Engineer Professional practice test. Take it and get a section-by-section score.

Start the free test →