SpinTheMic
Pro

Interview practice question

Removing duplicates keeping the latest

Data Engineering · Spark · Beginner

A DataFrame has multiple rows per order_id from repeated loads. How do you keep only the latest version of each order?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • dropDuplicates keeps an arbitrary row, not the latest.
  • Use row_number over a window partitioned by order_id ordered by updated_at desc.
  • Keep rows with row_number = 1.
  • Add a tie-breaker column for deterministic results.
  • For streams, use dropDuplicatesWithinWatermark or stateful dedup.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics