Avoiding Duplicate Ingestion with Autoloader and Migrated S3 Data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 03:21 AM
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}")
)
- Labels:
-
Delta Lake
-
Spark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 02:00 AM
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

