cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group