https://delta.io logo
s

shareef shaik

06/20/2023, 7:57 AM
I can only see append and overwrite modes in writing to delta table. but I cant find anything to upsert to existing delta table without having to overwrite the table completely.
w

Will Jones

06/20/2023, 2:31 PM
We don’t support update yet, but it has been started. We do support overwriting individual partitions, though.
s

shareef shaik

06/21/2023, 2:30 PM
Thanks Will for the response. When you say individual partition overwrite, do you mean this -- write_deltalake(table, df2, partition_filters=[('y', '=', 'b')], mode="overwrite") ?
👍 1
w

Will Jones

06/21/2023, 2:44 PM
Yes, that’s it
s

shareef shaik

06/22/2023, 8:49 AM
example which was given in the documentation, is somehow not working as expected.
Copy code
from deltalake.writer import write_deltalake
>>> df = pd.DataFrame({'x': [1, 2, 3], 'y': ['a', 'a', 'b']})
>>> write_deltalake('path/to/table', df, partition_by=['y'])

>>> table = DeltaTable('path/to/table')
>>> df2 = pd.DataFrame({'x': [100], 'y': ['b']})
>>> write_deltalake(table, df2, partition_filters=[('y', '=', 'b')], mode="overwrite")

>>> table.to_pandas()
     x  y
0    1  a
1    2  a
2  100  b
in this example as it should overwrite the file of partition y, but this is not updating the partition file .
can you please help
w

Will Jones

06/22/2023, 2:37 PM
The code you are showing seems to have the correct result. Are you getting different data at the end?