@@ -371,6 +371,42 @@ def test_upsert_with_identifier_fields(catalog: Catalog) -> None:
371371 assert upd .rows_inserted == 1
372372
373373
374+ def test_upsert_into_empty_table (catalog : Catalog ) -> None :
375+ identifier = "default.test_upsert_into_empty_table"
376+ _drop_table (catalog , identifier )
377+
378+ schema = Schema (
379+ NestedField (1 , "city" , StringType (), required = True ),
380+ NestedField (2 , "inhabitants" , IntegerType (), required = True ),
381+ # Mark City as the identifier field, also known as the primary-key
382+ identifier_field_ids = [1 ],
383+ )
384+
385+ tbl = catalog .create_table (identifier , schema = schema )
386+
387+ arrow_schema = pa .schema (
388+ [
389+ pa .field ("city" , pa .string (), nullable = False ),
390+ pa .field ("inhabitants" , pa .int32 (), nullable = False ),
391+ ]
392+ )
393+
394+ # Write some data
395+ df = pa .Table .from_pylist (
396+ [
397+ {"city" : "Amsterdam" , "inhabitants" : 921402 },
398+ {"city" : "San Francisco" , "inhabitants" : 808988 },
399+ {"city" : "Drachten" , "inhabitants" : 45019 },
400+ {"city" : "Paris" , "inhabitants" : 2103000 },
401+ ],
402+ schema = arrow_schema ,
403+ )
404+ upd = tbl .upsert (df )
405+
406+ assert upd .rows_updated == 0
407+ assert upd .rows_inserted == 4
408+
409+
374410def test_create_match_filter_single_condition () -> None :
375411 """
376412 Test create_match_filter with a composite key where the source yields exactly one unique key.
0 commit comments