cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

MERGE in the delta table

Viren123
Contributor

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()

**************************************************************************

 imageimage.pngViren

1 REPLY 1

daniel_sahal
Esteemed Contributor

I think that you're mixing DataFrames spark vs. pandas.

Try creating dfSource in Spark instead of Pandas.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.