shruti thakar
shruti thakar

Reputation: 11

'DeltaMergeBuilder' object has no attribute 'WhenNotMatchedInsert'

while doing merge with deltatable getting below error.

'DeltaMergeBuilder' object has no attribute 'WhenNotMatchedInsert'

from delta.tables import *
delta_df = DeltaTable.forPath(spark,"dbfs:/user/hive/warehouse/FileStore/tables/stream_write2")

delta_df.alias("t").merge(
df.alias("s"),
"target.empid=source.empid").whenMatchedUpdate(set =
{
"name":"source.name",
"city":"source.city",
"country":"source.country",
"contactno":"source.contactno"
}
).WhenNotMatchedInsert(Values =
{
"empid":"source.empid",
"name":"source.name",
"city":"source.city",
"country":"source.country",
"contactno":"source.contactno"
}
)
.execute()

error:

AttributeError: 'DeltaMergeBuilder' object has no attribute 'WhenNotMatchedInsert'

AttributeError                            Traceback (most recent call last)
<command-3810732791373279> in <cell line: 1>()
1 delta_df.alias("t").merge(
2 df.alias("s"),
3 "target.empid=source.empid").whenMatchedUpdate(set =
4 {
5 "name":"source.name",

AttributeError: 'DeltaMergeBuilder' object has no attribute 'WhenNotMatchedInsert'
Command took 0.21 seconds -- byat 1/5/2023, 6:09:03 PM on Cluster

I am working on upsert in delta table but getting below error.

Upvotes: 1

Views: 1603

Answers (1)

Alex Ott
Alex Ott

Reputation: 87154

The error is simple - your function name is using upper case W, but it should be lower-case: whenNotMatchedInsert

Upvotes: 1

Related Questions