Skip to content

Commit ff149e8

Browse files
committed
fix: add metadata_properties to _construct_parameters when update hive table
1 parent da88b8d commit ff149e8

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

pyiceberg/catalog/hive.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,18 @@ def _construct_hive_storage_descriptor(
211211
DEFAULT_PROPERTIES = {TableProperties.PARQUET_COMPRESSION: TableProperties.PARQUET_COMPRESSION_DEFAULT}
212212

213213

214-
def _construct_parameters(metadata_location: str, previous_metadata_location: Optional[str] = None) -> Dict[str, Any]:
214+
def _construct_parameters(
215+
metadata_location: str, previous_metadata_location: Optional[str] = None, metadata_properties: Optional[Properties] = None
216+
) -> Dict[str, Any]:
215217
properties = {PROP_EXTERNAL: "TRUE", PROP_TABLE_TYPE: "ICEBERG", PROP_METADATA_LOCATION: metadata_location}
216218
if previous_metadata_location:
217219
properties[PROP_PREVIOUS_METADATA_LOCATION] = previous_metadata_location
218220

221+
if metadata_properties:
222+
for key, value in metadata_properties.items():
223+
if key not in properties:
224+
properties[key] = str(value)
225+
219226
return properties
220227

221228

@@ -360,7 +367,7 @@ def _convert_iceberg_into_hive(self, table: Table) -> HiveTable:
360367
property_as_bool(self.properties, HIVE2_COMPATIBLE, HIVE2_COMPATIBLE_DEFAULT),
361368
),
362369
tableType=EXTERNAL_TABLE,
363-
parameters=_construct_parameters(table.metadata_location),
370+
parameters=_construct_parameters(metadata_location=table.metadata_location, metadata_properties=table.properties),
364371
)
365372

366373
def _create_hive_table(self, open_client: Client, hive_table: HiveTable) -> None:
@@ -541,6 +548,7 @@ def commit_table(
541548
hive_table.parameters = _construct_parameters(
542549
metadata_location=updated_staged_table.metadata_location,
543550
previous_metadata_location=current_table.metadata_location,
551+
metadata_properties=updated_staged_table.properties,
544552
)
545553
open_client.alter_table_with_environment_context(
546554
dbname=database_name,

tests/integration/test_reads.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
pyarrow_to_schema,
4949
)
5050
from pyiceberg.schema import Schema
51-
from pyiceberg.table import Table
51+
from pyiceberg.table import Table, update_table_metadata
5252
from pyiceberg.types import (
5353
BinaryType,
5454
BooleanType,
@@ -59,6 +59,7 @@
5959
TimestampType,
6060
)
6161
from pyiceberg.utils.concurrent import ExecutorFactory
62+
from pyiceberg.table.update import SetPropertiesUpdate, RemovePropertiesUpdate
6263

6364
DEFAULT_PROPERTIES = {"write.parquet.compression-codec": "zstd"}
6465

@@ -111,6 +112,23 @@ def test_table_properties(catalog: Catalog) -> None:
111112
table.transaction().set_properties(property_name=None).commit_transaction()
112113
assert "None type is not a supported value in properties: property_name" in str(exc_info.value)
113114

115+
if isinstance(catalog, HiveCatalog):
116+
table.transaction().set_properties({"abc": "def", "p1": "123"}).commit_transaction()
117+
118+
hive_client: _HiveClient = _HiveClient(catalog.properties["uri"])
119+
120+
with hive_client as open_client:
121+
hive_table = open_client.get_table(*TABLE_NAME)
122+
assert hive_table.parameters.get("abc") == "def"
123+
assert hive_table.parameters.get("p1") == "123"
124+
assert hive_table.parameters.get("not_exist_parameter") is None
125+
126+
table.transaction().remove_properties("abc").commit_transaction()
127+
128+
with hive_client as open_client:
129+
hive_table = open_client.get_table(*TABLE_NAME)
130+
assert hive_table.parameters.get("abc") is None
131+
114132

115133
@pytest.mark.integration
116134
@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")])

0 commit comments

Comments
 (0)