Created
July 3, 2020 13:04
-
-
Save chetkhatri/1ec0e08e42b1ad4a38430621e0fb5020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object DedupWriter extends Serializable { | |
def upsertIntoDeduped(microBatchOutput: DataFrame, batchId: Long): Unit = { | |
DeltaTable.forPath("/mnt/somebucket/ip_index_deduped_updates.delta").as("out") | |
.merge( | |
microBatchOutput.as("in"), | |
// all columns match | |
) | |
.whenNotMatched.insertAll.execute | |
} | |
} | |
spark | |
.readStream | |
.format("delta") | |
.option("ignoreChanges", true) | |
.load("/mnt/aggregates/prod/some_table_that_receives_upserts.delta") | |
.writeStream | |
.outputMode("append") | |
.option("checkpointLocation", CHECKPOINT_PATH) | |
.foreachBatch(DedupWriter.upsertIntoDeduped _) | |
.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In Python there is no option of table