@@ -89,7 +89,7 @@ def test_update_sort_order(catalog: Catalog, format_version: str, table_schema_s
8989 (pytest .lazy_fixture ("session_catalog_hive" ), "2" ),
9090 ],
9191)
92- def test_update_existing_sort_order (catalog : Catalog , format_version : str , table_schema_simple : Schema ) -> None :
92+ def test_increment_existing_sort_order_id (catalog : Catalog , format_version : str , table_schema_simple : Schema ) -> None :
9393 simple_table = _simple_table (catalog , table_schema_simple , format_version )
9494 simple_table .update_sort_order ().asc ("foo" , IdentityTransform (), NullOrder .NULLS_FIRST ).commit ()
9595 assert simple_table .sort_order () == SortOrder (
@@ -107,3 +107,34 @@ def test_update_existing_sort_order(catalog: Catalog, format_version: str, table
107107 SortField (source_id = 2 , transform = IdentityTransform (), direction = SortDirection .DESC , null_order = NullOrder .NULLS_FIRST ),
108108 order_id = 2 ,
109109 )
110+
111+
112+ @pytest .mark .integration
113+ @pytest .mark .parametrize (
114+ "catalog, format_version" ,
115+ [
116+ (pytest .lazy_fixture ("session_catalog" ), "1" ),
117+ (pytest .lazy_fixture ("session_catalog_hive" ), "1" ),
118+ (pytest .lazy_fixture ("session_catalog" ), "2" ),
119+ (pytest .lazy_fixture ("session_catalog_hive" ), "2" ),
120+ ],
121+ )
122+ def test_update_existing_sort_order (catalog : Catalog , format_version : str , table_schema_simple : Schema ) -> None :
123+ simple_table = _simple_table (catalog , table_schema_simple , format_version )
124+ simple_table .update_sort_order ().asc ("foo" , IdentityTransform (), NullOrder .NULLS_FIRST ).commit ()
125+ assert simple_table .sort_order () == SortOrder (
126+ SortField (source_id = 1 , transform = IdentityTransform (), direction = SortDirection .ASC , null_order = NullOrder .NULLS_FIRST ),
127+ order_id = 1 ,
128+ )
129+ simple_table .update_sort_order ().asc ("foo" , IdentityTransform (), NullOrder .NULLS_LAST ).desc (
130+ "bar" , IdentityTransform (), NullOrder .NULLS_FIRST
131+ ).commit ()
132+ # Go back to the first sort order
133+ simple_table .update_sort_order ().asc ("foo" , IdentityTransform (), NullOrder .NULLS_FIRST ).commit ()
134+ assert (
135+ len (simple_table .sort_orders ()) == 3
136+ ) # line 133 should not create a new sort order since it is the same as the first one
137+ assert simple_table .sort_order () == SortOrder (
138+ SortField (source_id = 1 , transform = IdentityTransform (), direction = SortDirection .ASC , null_order = NullOrder .NULLS_FIRST ),
139+ order_id = 1 ,
140+ )
0 commit comments