Skip to content

Hive: update hive storage descriptor after commit schema change #2036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dev/hive/core-site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@
<name>fs.s3a.path.style.access</name>
<value>true</value>
</property>
<property>
<name>hive.metastore.disallow.incompatible.col.type.changes</name>
<value>false</value>
</property>

</configuration>
6 changes: 6 additions & 0 deletions pyiceberg/catalog/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ def commit_table(
metadata_location=updated_staged_table.metadata_location,
previous_metadata_location=current_table.metadata_location,
)
# Update hive's schema and properties
hive_table.sd = _construct_hive_storage_descriptor(
updated_staged_table.schema(),
updated_staged_table.location(),
property_as_bool(updated_staged_table.properties, HIVE2_COMPATIBLE, HIVE2_COMPATIBLE_DEFAULT),
)
open_client.alter_table_with_environment_context(
dbname=database_name,
tbl_name=table_name,
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/test_writes/test_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,30 @@ def test_hive_catalog_storage_descriptor(
assert spark.sql("SELECT * FROM hive.default.test_storage_descriptor").count() == 3


@pytest.mark.integration
@pytest.mark.parametrize("format_version", [1, 2])
def test_hive_catalog_storage_descriptor_has_changed(
session_catalog_hive: HiveCatalog,
pa_schema: pa.Schema,
arrow_table_with_null: pa.Table,
spark: SparkSession,
format_version: int,
) -> None:
tbl = _create_table(
session_catalog_hive, "default.test_storage_descriptor", {"format-version": format_version}, [arrow_table_with_null]
)

with tbl.transaction() as tx:
with tx.update_schema() as schema:
schema.update_column("string_long", doc="this is string_long")
schema.update_column("binary", doc="this is binary")

with session_catalog_hive._client as open_client:
hive_table = session_catalog_hive._get_hive_table(open_client, "default", "test_storage_descriptor")
assert "this is string_long" in str(hive_table.sd)
assert "this is binary" in str(hive_table.sd)


@pytest.mark.integration
@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")])
def test_sanitize_character_partitioned(catalog: Catalog) -> None:
Expand Down
Loading