@@ -511,7 +511,7 @@ def test_upsert_without_identifier_fields(catalog: Catalog) -> None:
511511 tbl .upsert (df )
512512
513513
514- def test_upsert_struct_field_fails_in_join (catalog : Catalog ) -> None :
514+ def test_upsert_with_struct_field_as_non_join_key (catalog : Catalog ) -> None :
515515 identifier = "default.test_upsert_struct_field_fails"
516516 _drop_table (catalog , identifier )
517517
@@ -601,6 +601,73 @@ def test_upsert_struct_field_fails_in_join(catalog: Catalog) -> None:
601601 assert_upsert_result (res , expected_updated , expected_inserted )
602602
603603
604+ def test_upsert_with_struct_field_as_join_key (catalog : Catalog ) -> None :
605+ identifier = "default.test_upsert_with_struct_field_as_join_key"
606+ _drop_table (catalog , identifier )
607+
608+ schema = Schema (
609+ NestedField (1 , "id" , IntegerType (), required = True ),
610+ NestedField (
611+ 2 ,
612+ "nested_type" ,
613+ StructType (
614+ NestedField (3 , "sub1" , StringType (), required = True ),
615+ NestedField (4 , "sub2" , StringType (), required = True ),
616+ ),
617+ required = False ,
618+ ),
619+ identifier_field_ids = [1 ],
620+ )
621+
622+ tbl = catalog .create_table (identifier , schema = schema )
623+
624+ arrow_schema = pa .schema (
625+ [
626+ pa .field ("id" , pa .int32 (), nullable = False ),
627+ pa .field (
628+ "nested_type" ,
629+ pa .struct (
630+ [
631+ pa .field ("sub1" , pa .large_string (), nullable = False ),
632+ pa .field ("sub2" , pa .large_string (), nullable = False ),
633+ ]
634+ ),
635+ nullable = True ,
636+ ),
637+ ]
638+ )
639+
640+ initial_data = pa .Table .from_pylist (
641+ [
642+ {
643+ "id" : 1 ,
644+ "nested_type" : {"sub1" : "bla1" , "sub2" : "bla" },
645+ }
646+ ],
647+ schema = arrow_schema ,
648+ )
649+ tbl .append (initial_data )
650+
651+ update_data = pa .Table .from_pylist (
652+ [
653+ {
654+ "id" : 2 ,
655+ "nested_type" : {"sub1" : "bla1" , "sub2" : "bla" },
656+ },
657+ {
658+ "id" : 1 ,
659+ "nested_type" : {"sub1" : "bla1" , "sub2" : "bla" },
660+ },
661+ ],
662+ schema = arrow_schema ,
663+ )
664+
665+ with pytest .raises (
666+ pa .lib .ArrowNotImplementedError , match = "Keys of type struct<sub1: large_string not null, sub2: large_string not null>"
667+ ):
668+ _ = tbl .upsert (update_data , join_cols = ["nested_type" ])
669+
670+
604671def test_upsert_with_nulls (catalog : Catalog ) -> None :
605672 identifier = "default.test_upsert_with_nulls"
606673 _drop_table (catalog , identifier )
0 commit comments