@@ -512,6 +512,41 @@ def test_add_column(table_v2: Table) -> None:
512
512
assert apply_schema .highest_field_id == 4
513
513
514
514
515
+ def test_update_column (table_v1 : Table , table_v2 : Table ) -> None :
516
+ """
517
+ Table should be able to update existing property `doc`
518
+ Table should also be able to update property `required`, if the field is not an identifier field.
519
+ """
520
+ COMMENT2 = "comment2"
521
+ for table in [table_v1 , table_v2 ]:
522
+ original_schema = table .schema ()
523
+ # update existing doc to a new doc
524
+ assert original_schema .find_field ("y" ).doc == "comment"
525
+ new_schema = table .transaction ().update_schema ().update_column ("y" , doc = COMMENT2 )._apply ()
526
+ assert new_schema .find_field ("y" ).doc == COMMENT2 , "failed to update existing field doc"
527
+
528
+ # update existing doc to an emtpy string
529
+ assert new_schema .find_field ("y" ).doc == COMMENT2
530
+ new_schema2 = table .transaction ().update_schema ().update_column ("y" , doc = "" )._apply ()
531
+ assert new_schema2 .find_field ("y" ).doc == "" , "failed to remove existing field doc"
532
+
533
+ # update required to False
534
+ assert original_schema .find_field ("z" ).required is True
535
+ new_schema3 = table .transaction ().update_schema ().update_column ("z" , required = False )._apply ()
536
+ assert new_schema3 .find_field ("z" ).required is False , "failed to update existing field required"
537
+
538
+ # assert the above two updates also works with union_by_name
539
+ assert (
540
+ table .update_schema ().union_by_name (new_schema )._apply () == new_schema
541
+ ), "failed to update existing field doc with union_by_name"
542
+ assert (
543
+ table .update_schema ().union_by_name (new_schema2 )._apply () == new_schema2
544
+ ), "failed to remove existing field doc with union_by_name"
545
+ assert (
546
+ table .update_schema ().union_by_name (new_schema3 )._apply () == new_schema3
547
+ ), "failed to update existing field required with union_by_name"
548
+
549
+
515
550
def test_add_primitive_type_column (table_v2 : Table ) -> None :
516
551
primitive_type : Dict [str , PrimitiveType ] = {
517
552
"boolean" : BooleanType (),
0 commit comments