@@ -186,7 +186,7 @@ def test_merge_scenario_skip_upd_row(catalog: Catalog) -> None:
186186
187187 res = table .upsert (df = source_df , join_cols = ["order_id" ])
188188
189- expected_updated = 2
189+ expected_updated = 1
190190 expected_inserted = 1
191191
192192 assert_upsert_result (res , expected_updated , expected_inserted )
@@ -222,7 +222,7 @@ def test_merge_scenario_date_as_key(catalog: Catalog) -> None:
222222
223223 res = table .upsert (df = source_df , join_cols = ["order_date" ])
224224
225- expected_updated = 2
225+ expected_updated = 1
226226 expected_inserted = 1
227227
228228 assert_upsert_result (res , expected_updated , expected_inserted )
@@ -258,7 +258,7 @@ def test_merge_scenario_string_as_key(catalog: Catalog) -> None:
258258
259259 res = table .upsert (df = source_df , join_cols = ["order_id" ])
260260
261- expected_updated = 2
261+ expected_updated = 1
262262 expected_inserted = 1
263263
264264 assert_upsert_result (res , expected_updated , expected_inserted )
@@ -371,25 +371,16 @@ def test_upsert_with_identifier_fields(catalog: Catalog) -> None:
371371
372372 expected_operations = [Operation .APPEND , Operation .OVERWRITE , Operation .APPEND , Operation .APPEND ]
373373
374- assert upd .rows_updated == 2
374+ assert upd .rows_updated == 1
375375 assert upd .rows_inserted == 1
376376
377377 assert [snap .summary .operation for snap in tbl .snapshots () if snap .summary is not None ] == expected_operations
378378
379- # This will update all 3 rows
379+ # This should be a no-op
380380 upd = tbl .upsert (df )
381381
382- assert upd .rows_updated == 3
382+ assert upd .rows_updated == 0
383383 assert upd .rows_inserted == 0
384- expected_operations = [
385- Operation .APPEND ,
386- Operation .OVERWRITE ,
387- Operation .APPEND ,
388- Operation .APPEND ,
389- Operation .DELETE ,
390- Operation .OVERWRITE ,
391- Operation .APPEND ,
392- ]
393384
394385 assert [snap .summary .operation for snap in tbl .snapshots () if snap .summary is not None ] == expected_operations
395386
@@ -561,7 +552,7 @@ def test_upsert_struct_field_fails_in_join(catalog: Catalog) -> None:
561552 [
562553 {
563554 "id" : 1 ,
564- "nested_type" : {"sub1" : "1_sub1_init " , "sub2" : "1sub2_init " },
555+ "nested_type" : {"sub1" : "bla1 " , "sub2" : "bla " },
565556 }
566557 ],
567558 schema = arrow_schema ,
@@ -572,32 +563,43 @@ def test_upsert_struct_field_fails_in_join(catalog: Catalog) -> None:
572563 [
573564 {
574565 "id" : 2 ,
575- "nested_type" : {"sub1" : "2_sub1_new " , "sub2" : "2_sub2_new " },
566+ "nested_type" : {"sub1" : "bla1 " , "sub2" : "bla " },
576567 },
577568 {
578569 "id" : 1 ,
579- "nested_type" : {"sub1" : "1sub1_init " , "sub2" : "1sub2_new " },
570+ "nested_type" : {"sub1" : "bla1 " , "sub2" : "bla2 " },
580571 },
581- # TODO: struct changes should cause _check_pyarrow_schema_compatible to fail. Introduce a new `sub3` attribute
582- # {
583- # "id": 1,
584- # "nested_type": {"sub3": "1sub3_init", "sub2": "1sub2_new"},
585- # },
586572 ],
587573 schema = arrow_schema ,
588574 )
589575
590- upd = tbl .upsert (update_data , join_cols = ["id" ])
576+ res = tbl .upsert (update_data , join_cols = ["id" ])
591577
592- # Row needs to be updated even tho it's not changed.
593- # When pyarrow isn't able to compare rows, just update everything
594- assert upd .rows_updated == 1
595- assert upd .rows_inserted == 1
578+ expected_updated = 1
579+ expected_inserted = 1
596580
597- assert tbl .scan ().to_arrow ().to_pylist () == [
598- {"id" : 2 , "nested_type" : {"sub1" : "2_sub1_new" , "sub2" : "2_sub2_new" }},
599- {"id" : 1 , "nested_type" : {"sub1" : "1sub1_init" , "sub2" : "1sub2_new" }},
600- ]
581+ assert_upsert_result (res , expected_updated , expected_inserted )
582+
583+ update_data = pa .Table .from_pylist (
584+ [
585+ {
586+ "id" : 2 ,
587+ "nested_type" : {"sub1" : "bla1" , "sub2" : "bla" },
588+ },
589+ {
590+ "id" : 1 ,
591+ "nested_type" : {"sub1" : "bla1" , "sub2" : "bla2" },
592+ },
593+ ],
594+ schema = arrow_schema ,
595+ )
596+
597+ res = tbl .upsert (update_data , join_cols = ["id" ])
598+
599+ expected_updated = 0
600+ expected_inserted = 0
601+
602+ assert_upsert_result (res , expected_updated , expected_inserted )
601603
602604
603605def test_upsert_with_nulls (catalog : Catalog ) -> None :
0 commit comments