Skip to content

Commit 64e9a60

Browse files
committed
add docs and refactor
1 parent 26ecfe7 commit 64e9a60

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

pyiceberg/catalog/hive.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -551,23 +551,30 @@ def commit_table(
551551

552552
if hive_table and current_table:
553553
# Table exists, update it.
554-
new_parameters = _construct_parameters(
554+
555+
# Note on table properties:
556+
# - Iceberg table properties are stored in both HMS and Iceberg metadata JSON.
557+
# - Updates are reflected in both locations
558+
# - Existing HMS table properties (set by external systems like Hive/Spark) are preserved.
559+
#
560+
# While it is possible to modify HMS table properties through this API, it is not recommended:
561+
# - New/Updated HMS table properties will also be stored in Iceberg metadata (even though it's HMS-specific)
562+
# - HMS properties cannot be deleted since they are not visible to Iceberg
563+
# - Mixing HMS-specific properties in Iceberg metadata can cause confusion
564+
new_iceberg_properties = _construct_parameters(
555565
metadata_location=updated_staged_table.metadata_location,
556566
previous_metadata_location=current_table.metadata_location,
557567
metadata_properties=updated_staged_table.properties,
558568
)
559-
560569
# Detect properties that were removed from Iceberg metadata
561-
removed_keys = current_table.properties.keys() - updated_staged_table.properties.keys()
562-
563-
# Sync HMS parameters: Iceberg metadata is the source of truth, HMS parameters are
564-
# a projection of Iceberg state plus any HMS-only properties.
565-
# Start with existing HMS params, remove deleted Iceberg properties, then apply Iceberg values.
566-
merged_params = dict(hive_table.parameters or {})
567-
for key in removed_keys:
568-
merged_params.pop(key, None)
569-
merged_params.update(new_parameters)
570-
hive_table.parameters = merged_params
570+
deleted_iceberg_properties = current_table.properties.keys() - updated_staged_table.properties.keys()
571+
572+
# Merge: preserve HMS-only properties, remove deleted Iceberg properties, apply new Iceberg properties
573+
existing_hms_parameters = dict(hive_table.parameters or {})
574+
for key in deleted_iceberg_properties:
575+
existing_hms_parameters.pop(key, None)
576+
existing_hms_parameters.update(new_iceberg_properties)
577+
hive_table.parameters = existing_hms_parameters
571578

572579
# Update hive's schema and properties
573580
hive_table.sd = _construct_hive_storage_descriptor(

0 commit comments

Comments
 (0)