Forum Discussion

gdb729's avatar
gdb729
Regular Visitor
1 year ago
Solved

Notebook Merge Only Inserting Not Updating Matched Rows

See my code below: from delta.tables import * # Get the target Delta table. target_table = DeltaTable.forName(spark, "targettable") # Define the source DataFrame (e.g., from a CSV file or ano...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi gdb729 ,

    It sounds like you're really close but what you're describing usually points to the merge condition not evaluating as a true match, even though the data looks identical at first glance. A few things that can trip this up.

    1. Data type mismatches: For example, if target.id is an int and source.id is a string, Spark won't match them even if the values appear the same.
    2. Null values: Regular = comparison fails when either side is null. In Spark, null = null returns false. You’ll want to use the null-safe equality operator (<=>) instead.
    3. Whitespace / case issues:   Especially on strings like transaction, even a trailing space can cause a mismatch.

    Regards,
    Akhil.