I have a case class as follows:
case class UniqueException(
ExceptionId:String,
LastUpdateTime:Timestamp,
IsDisplayed:Boolean,
Message:String,
ExceptionType:String,
ExceptionMessage:String,
FullException:String
)
This is used to generate a Delta table.
Following conditions need to be met:
- A new UniqueException needs to be inserted if the ExceptionId of the UniqueException is new to the delta table.
- An existing UniqueException needs be updated if the ExceptionId of the incoming UniqueException exists already in the delta table and LastUpdateTime of the incoming UniqueException is greater than by 14 days.
- If the LastUpdateTime is less than 14 days, then the incoming UniqueException should not be updated if the ExceptionId of the incoming UniqueException exists already in the delta table.
I wrote the following code, but it doesn't satisfy the above cases.
val dfUniqueException = DeltaTable.forPath(outputFolder)
dfUniqueException.as("existing")
.merge(dfNewExceptions.as("new"), "new.ExceptionId = existing.ExceptionId and new.LastUpdateTime > date_add(existing.LastUpdateTime, 14")
.whenMatched().updateAll()
.whenNotMatched().insertAll()
.execute()
Any idea how the above conditions can be fulfilled with a single merge statement?