@@ -135,6 +135,47 @@ def test_hive_properties(catalog: Catalog) -> None:
135135 assert hive_table .parameters .get ("abc" ) is None
136136
137137
138+ @pytest .mark .integration
139+ @pytest .mark .parametrize ("catalog" , [pytest .lazy_fixture ("session_catalog_hive" )])
140+ def test_hive_preserves_hms_specific_properties (catalog : Catalog ) -> None :
141+ """Test that HMS-specific table properties are preserved during table commits.
142+
143+ This verifies that HMS-specific properties (like 'table_category') that are
144+ not managed by Iceberg are preserved during commits, rather than being lost.
145+
146+ Regression test for: https://github.com/apache/iceberg-python/issues/2064
147+ """
148+ table = create_table (catalog )
149+
150+ # Directly add HMS-specific properties using Hive client
151+ # This simulates properties set by external systems (like data contracts)
152+ hive_client : _HiveClient = _HiveClient (catalog .properties ["uri" ])
153+ with hive_client as open_client :
154+ hive_table = open_client .get_table (* TABLE_NAME )
155+ # Add HMS-specific properties that aren't managed by Iceberg
156+ hive_table .parameters ["table_category" ] = "production"
157+ hive_table .parameters ["data_owner" ] = "data_team"
158+ open_client .alter_table (TABLE_NAME [0 ], TABLE_NAME [1 ], hive_table )
159+
160+ with hive_client as open_client :
161+ hive_table = open_client .get_table (* TABLE_NAME )
162+ assert hive_table .parameters .get ("table_category" ) == "production"
163+ assert hive_table .parameters .get ("data_owner" ) == "data_team"
164+
165+ table .transaction ().set_properties ({"iceberg_property" : "new_value" }).commit_transaction ()
166+
167+ # Verify that HMS-specific properties are STILL present after commit
168+ with hive_client as open_client :
169+ hive_table = open_client .get_table (* TABLE_NAME )
170+ # HMS-specific properties should be preserved
171+ assert hive_table .parameters .get ("table_category" ) == "production" , \
172+ "HMS property 'table_category' was lost during commit!"
173+ assert hive_table .parameters .get ("data_owner" ) == "data_team" , \
174+ "HMS property 'data_owner' was lost during commit!"
175+ # Iceberg properties should also be present
176+ assert hive_table .parameters .get ("iceberg_property" ) == "new_value"
177+
178+
138179@pytest .mark .integration
139180@pytest .mark .parametrize ("catalog" , [pytest .lazy_fixture ("session_catalog_hive" ), pytest .lazy_fixture ("session_catalog" )])
140181def test_table_properties_dict (catalog : Catalog ) -> None :
0 commit comments