MERGE in the delta table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 08:29 AM
Hello,
I would like to UPDATE the data in the delta table. For the same MERGE option came to my attention.
However my below code ends up with errors as shown at the end. Kindly advice what am I missing here. Thank you.
************************************************************************
from delta.tables import *
import pandas as pd
dfsource = pd.DataFrame({'BRI': {0: 'abc'},
'run_datetime': {0: '2022-12-05 16:33:22.324'}
})
tabletoupdate = DeltaTable.forName(spark, 'eda_rw.eda_log_bridge_run')
tabletoupdate.alias('target') \
.merge(
dfsource,
'target.BRI = dfsource.BRI'
'target.run_datetime = dfsource.run_datetime'
) \
.whenMatchedUpdate(set =
{
"BRI": "dfsource.BRI",
"run_datetime": "dfsource.run_datetime"
}
) \
.whenNotMatchedInsert(values =
{
"BRI": "dfsource.BRI",
"run_datetime": "dfsource.run_datetime"
}
) \
.execute()
**************************************************************************
Viren
- Labels:
-
Delta
-
Delta table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 05:25 AM
I think that you're mixing DataFrames spark vs. pandas.
Try creating dfSource in Spark instead of Pandas.

