cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Avoiding Duplicate Ingestion with Autoloader and Migrated S3 Data

Olaoye_Somide
New Contributor III

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}")
)

 

 

1 REPLY 1

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

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group