Skip to main content
PYSPARK โ€ข LESSON 225

Duplicate Identification & Audit Log Extraction

How can we extract all duplicate records (rn > 1) into an audit log table for compliance investigation?

Advancedโฑ 3 Minutesโญ 840 XP
๐Ÿค” THE QUESTION

How can we extract all duplicate records (rn > 1) into an audit log table for compliance investigation?

๐Ÿ’ก WHAT IS IT?

Filtering for row_number() > 1 isolates every discarded duplicate record along with its rank for auditing.

๐ŸŽฏ WHAT IS IT USED FOR?

Regulatory compliance reporting and identifying upstream double-billing or re-transmission anomalies.

๐Ÿ’ป EXAMPLE
w = Window.partitionBy("transaction_id").orderBy(col("received_at").desc())
df_duplicates_audit = df.withColumn("rn", row_number().over(w)).filter(col("rn") > 1)

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Duplicate Identification & Audit Log Extraction.

  • โœ“ Isolating discarded duplicates
  • โœ“ Audit log extraction
  • โœ“ Data anomaly reporting