23
23
24
24
from pyiceberg .catalog .rest import RestCatalog
25
25
from pyiceberg .exceptions import NoSuchTableError
26
- from pyiceberg .expressions import EqualTo
26
+ from pyiceberg .expressions import AlwaysTrue , EqualTo
27
+ from pyiceberg .manifest import ManifestEntryStatus
27
28
from pyiceberg .schema import Schema
28
29
from pyiceberg .table .snapshots import Operation , Summary
29
30
from pyiceberg .types import IntegerType , NestedField
@@ -265,9 +266,7 @@ def test_delete_no_match(session_catalog: RestCatalog) -> None:
265
266
arrow_schema = pa .schema ([pa .field ("ints" , pa .int32 ())])
266
267
arrow_tbl = pa .Table .from_pylist (
267
268
[
268
- {
269
- 'ints' : 1 ,
270
- },
269
+ {'ints' : 1 },
271
270
{'ints' : 3 },
272
271
],
273
272
schema = arrow_schema ,
@@ -297,9 +296,7 @@ def test_delete_overwrite(session_catalog: RestCatalog) -> None:
297
296
arrow_schema = pa .schema ([pa .field ("ints" , pa .int32 ())])
298
297
arrow_tbl = pa .Table .from_pylist (
299
298
[
300
- {
301
- 'ints' : 1 ,
302
- },
299
+ {'ints' : 1 },
303
300
{'ints' : 2 },
304
301
],
305
302
schema = arrow_schema ,
@@ -321,9 +318,7 @@ def test_delete_overwrite(session_catalog: RestCatalog) -> None:
321
318
322
319
arrow_tbl_overwrite = pa .Table .from_pylist (
323
320
[
324
- {
325
- 'ints' : 3 ,
326
- },
321
+ {'ints' : 3 },
327
322
{'ints' : 4 },
328
323
],
329
324
schema = arrow_schema ,
@@ -337,3 +332,37 @@ def test_delete_overwrite(session_catalog: RestCatalog) -> None:
337
332
]
338
333
339
334
assert tbl .scan ().to_arrow ()['ints' ].to_pylist () == [3 , 4 , 1 ]
335
+
336
+
337
+ @pytest .mark .integration
338
+ def test_delete_truncate (session_catalog : RestCatalog ) -> None :
339
+ arrow_schema = pa .schema ([pa .field ("ints" , pa .int32 ())])
340
+ arrow_tbl = pa .Table .from_pylist (
341
+ [
342
+ {'ints' : 1 },
343
+ ],
344
+ schema = arrow_schema ,
345
+ )
346
+
347
+ iceberg_schema = Schema (NestedField (1 , "ints" , IntegerType ()))
348
+
349
+ tbl_identifier = "default.test_delete_overwrite"
350
+
351
+ try :
352
+ session_catalog .drop_table (tbl_identifier )
353
+ except NoSuchTableError :
354
+ pass
355
+
356
+ tbl = session_catalog .create_table (tbl_identifier , iceberg_schema )
357
+ tbl .append (arrow_tbl )
358
+
359
+ # Effectively a truncate
360
+ tbl .delete (delete_filter = AlwaysTrue ())
361
+
362
+ manifests = tbl .current_snapshot ().manifests (tbl .io )
363
+ assert len (manifests ) == 1
364
+
365
+ entries = manifests [0 ].fetch_manifest_entry (tbl .io , discard_deleted = False )
366
+ assert len (entries ) == 1
367
+
368
+ assert entries [0 ].status == ManifestEntryStatus .DELETED
0 commit comments