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