File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -3554,6 +3554,7 @@ def to_iceberg(
3554
3554
* ,
3555
3555
catalog_properties : dict [str , Any ] | None = None ,
3556
3556
location : str | None = None ,
3557
+ append : bool = False ,
3557
3558
snapshot_properties : dict [str , str ] | None = None ,
3558
3559
) -> None :
3559
3560
"""
@@ -3575,6 +3576,8 @@ def to_iceberg(
3575
3576
The properties that are used next to the catalog configuration.
3576
3577
location : str, optional
3577
3578
Location for the table.
3579
+ append : bool, default False
3580
+ If ``True``, append data to the table, instead of replacing the content.
3578
3581
snapshot_properties : dict of {str: str}, optional
3579
3582
Custom properties to be added to the snapshot summary
3580
3583
@@ -3596,6 +3599,7 @@ def to_iceberg(
3596
3599
catalog_name ,
3597
3600
catalog_properties = catalog_properties ,
3598
3601
location = location ,
3602
+ append = append ,
3599
3603
snapshot_properties = snapshot_properties ,
3600
3604
)
3601
3605
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ def to_iceberg(
102
102
* ,
103
103
catalog_properties : dict [str , Any ] | None = None ,
104
104
location : str | None = None ,
105
+ append : bool = False ,
105
106
snapshot_properties : dict [str , str ] | None = None ,
106
107
) -> None :
107
108
"""
@@ -119,6 +120,8 @@ def to_iceberg(
119
120
The properties that are used next to the catalog configuration.
120
121
location : str, optional
121
122
Location for the table.
123
+ append : bool, default False
124
+ If ``True``, append data to the table, instead of replacing the content.
122
125
snapshot_properties : dict of {str: str}, optional
123
126
Custom properties to be added to the snapshot summary
124
127
@@ -142,4 +145,7 @@ def to_iceberg(
142
145
)
143
146
if snapshot_properties is None :
144
147
snapshot_properties = {}
145
- table .append (arrow_table , snapshot_properties = snapshot_properties )
148
+ if append :
149
+ table .append (arrow_table , snapshot_properties = snapshot_properties )
150
+ else :
151
+ table .overwrite (arrow_table , snapshot_properties = snapshot_properties )
Original file line number Diff line number Diff line change @@ -178,7 +178,7 @@ def test_write_by_catalog_name(self, catalog):
178
178
)
179
179
tm .assert_frame_equal (result , df )
180
180
181
- def test_write_existing_table (self , catalog ):
181
+ def test_write_existing_table_with_append_true (self , catalog ):
182
182
original = read_iceberg (
183
183
"ns.my_table" ,
184
184
catalog_properties = {"uri" : catalog .uri },
@@ -194,9 +194,29 @@ def test_write_existing_table(self, catalog):
194
194
"ns.my_table" ,
195
195
catalog_properties = {"uri" : catalog .uri },
196
196
location = catalog .warehouse ,
197
+ append = True ,
197
198
)
198
199
result = read_iceberg (
199
200
"ns.my_table" ,
200
201
catalog_properties = {"uri" : catalog .uri },
201
202
)
202
203
tm .assert_frame_equal (result , expected )
204
+
205
+ def test_write_existing_table_with_append_false (self , catalog ):
206
+ df = pd .DataFrame (
207
+ {
208
+ "A" : [1 , 2 , 3 ],
209
+ "B" : ["foo" , "foo" , "foo" ],
210
+ }
211
+ )
212
+ df .to_iceberg (
213
+ "ns.my_table" ,
214
+ catalog_properties = {"uri" : catalog .uri },
215
+ location = catalog .warehouse ,
216
+ append = False ,
217
+ )
218
+ result = read_iceberg (
219
+ "ns.my_table" ,
220
+ catalog_properties = {"uri" : catalog .uri },
221
+ )
222
+ tm .assert_frame_equal (result , df )
You can’t perform that action at this time.
0 commit comments