QuestionQ247

VerifiedData Processing & Transformations

A data engineer is cleaning a bronze table that receives the same customer records from multiple source systems. Duplicate rows share the same customer_id and email but have different ingestion_timestamp values. The silver table should retain only one record per unique combination of customer_id and email.

Which PySpark operation correctly deduplicates the data based on these business keys?

Explanation

dropDuplicates(['customer_id', 'email']) removes duplicate rows by comparing only the specified subset of columns, keeping one full record (with all its original columns) for each distinct combination of customer_id and email — exactly what's needed when duplicate rows differ in non-key columns like ingestion_timestamp. The other options either aggregate away the other columns (B), keep only the key columns (C), or rely on full-row equality which fails when ingestion_timestamp differs (D).

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!