cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Avoiding Duplicate Ingestion with Autoloader and Migrated S3 Data

Olaoye_Somide
New Contributor

Hi Team,

We recently migrated event files from our previous S3 bucket to a new one. While utilizing Autoloader for batch ingestion, we've encountered an issue where the migrated data is being processed as new events. This leads to duplicate records in our Databricks Delta table.

While we understand Autoloader utilizes RocksDB for deduplication, we'd appreciate your insights on how to effectively ensure Autoloader ignores or skips events previously ingested from the old S3 bucket.

Thank you in advance for your assistance.

See the code below:

 

spark.conf.set("spark.databricks.cloudFiles.checkSourceChanged", False)

(
    spark.readStream.format("cloudFiles")
    .option("cloudFiles.format", "json")
    .option("cloudFiles.schemaLocation", schema_path)
    .option("cloudFiles.schemaEvolutionMode", "addNewColumns")
    .load(f"s3://{bucket_name}/{bucket_prefix}")
    .writeStream.option("checkpointLocation", checkpoint_path)
    .option("mergeSchema", "true")
    .trigger(availableNow=True)
    .toTable(f"{catalog_name}.{schema_name}.{delta_table_name}")
)

 

 

2 REPLIES 2

daniel_sahal
Esteemed Contributor

@Olaoye_Somide 

Changing the source means that Autoloader discovers the files as a new (technically - they are on a new location, so they are new indeed).

To overcome the issue you can use modifiedAfter property

Kaniz
Community Manager
Community Manager

Hey there! Thanks a bunch for being part of our awesome community! 🎉 

We love having you around and appreciate all your questions. Take a moment to check out the responses – you'll find some great info. Your input is valuable, so pick the best solution for you. And remember, if you ever need more help , we're here for you! 

Keep being awesome! 😊🚀

 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.