@@ -714,6 +714,57 @@ def test_upsert_with_nulls(catalog: Catalog) -> None:
714714 )
715715
716716
717+ def test_upsert_after_schema_add_column (catalog : Catalog ) -> None :
718+ identifier = "default.test_upsert_after_schema_add_column"
719+ _drop_table (catalog , identifier )
720+
721+ schema = Schema (
722+ NestedField (1 , "id" , IntegerType (), required = True ),
723+ NestedField (2 , "name" , StringType (), required = True ),
724+ identifier_field_ids = [1 ],
725+ )
726+
727+ tbl = catalog .create_table (identifier , schema = schema )
728+
729+ initial = pa .Table .from_pylist (
730+ [{"id" : 1 , "name" : "Alice" }],
731+ schema = pa .schema (
732+ [
733+ pa .field ("id" , pa .int32 (), nullable = False ),
734+ pa .field ("name" , pa .string (), nullable = False ),
735+ ]
736+ ),
737+ )
738+ tbl .append (initial )
739+
740+ with tbl .update_schema () as update_schema :
741+ update_schema .add_column ("country" , StringType ())
742+ tbl = tbl .refresh ()
743+
744+ source = pa .Table .from_pylist (
745+ [
746+ {"id" : 1 , "name" : "Alice" , "country" : "NL" },
747+ {"id" : 2 , "name" : "Bob" , "country" : "US" },
748+ ],
749+ schema = pa .schema (
750+ [
751+ pa .field ("id" , pa .int32 (), nullable = False ),
752+ pa .field ("name" , pa .string (), nullable = False ),
753+ pa .field ("country" , pa .string (), nullable = True ),
754+ ]
755+ ),
756+ )
757+
758+ upd = tbl .upsert (source , ["id" ])
759+
760+ assert upd .rows_updated == 1
761+ assert upd .rows_inserted == 1
762+ assert sorted (tbl .scan ().to_arrow ().to_pylist (), key = lambda row : row ["id" ]) == [
763+ {"id" : 1 , "name" : "Alice" , "country" : "NL" },
764+ {"id" : 2 , "name" : "Bob" , "country" : "US" },
765+ ]
766+
767+
717768def test_transaction (catalog : Catalog ) -> None :
718769 """Test the upsert within a Transaction. Make sure that if something fails the entire Transaction is
719770 rolled back."""
0 commit comments