Skip to main content
PYSPARK • LESSON 104

Complex Relational Entity Resolution Pipeline

How do we resolve raw CRM leads against established master accounts and coalesce fallback master IDs?

Advanced3 Minutes620 XP
🤔 THE QUESTION

How do we resolve raw CRM leads against established master accounts and coalesce fallback master IDs?

💡 WHAT IS IT?

An entity resolution pipeline performing aliased left joins and coalescing master account keys with lead keys.

🎯 WHAT IS IT USED FOR?

Enterprise Master Data Management (MDM), customer identity resolution, and marketing attribution.

💻 EXAMPLE
from pyspark.sql.functions import col, coalesce

resolved_df = raw_leads.alias("lead").join(
    crm_accounts.alias("crm"),
    col("lead.email") == col("crm.primary_email"),
    "left"
).select(
    col("lead.lead_id"),
    coalesce(col("crm.account_id"), col("lead.lead_id")).alias("master_id"),
    col("lead.email"),
    col("crm.company_name")
)

🎯 Mission Objectives

Practice typing production-grade PySpark code for Complex Relational Entity Resolution Pipeline.

  • Alias leads and CRM DataFrames
  • Match on customer email addresses
  • Coalesce CRM master ID with lead fallback