Skip to content

Commit a7fbd56

Browse files
committed
Hive: Add DO_NOT_UPDATE_STATS in alter_table
1 parent 34c8949 commit a7fbd56

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

pyiceberg/catalog/hive.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from hive_metastore.ttypes import (
3737
AlreadyExistsException,
3838
CheckLockRequest,
39+
EnvironmentContext,
3940
FieldSchema,
4041
InvalidOperationException,
4142
LockComponent,
@@ -135,6 +136,8 @@
135136
DEFAULT_LOCK_CHECK_MIN_WAIT_TIME = 0.1 # 100 milliseconds
136137
DEFAULT_LOCK_CHECK_MAX_WAIT_TIME = 60 # 1 min
137138
DEFAULT_LOCK_CHECK_RETRIES = 4
139+
DO_NOT_UPDATE_STATS = "DO_NOT_UPDATE_STATS"
140+
TRUE = "true"
138141

139142
logger = logging.getLogger(__name__)
140143

@@ -539,7 +542,12 @@ def commit_table(
539542
metadata_location=updated_staged_table.metadata_location,
540543
previous_metadata_location=current_table.metadata_location,
541544
)
542-
open_client.alter_table(dbname=database_name, tbl_name=table_name, new_tbl=hive_table)
545+
open_client.alter_table_with_environment_context(
546+
dbname=database_name,
547+
tbl_name=table_name,
548+
new_tbl=hive_table,
549+
environment_context=EnvironmentContext(properties={DO_NOT_UPDATE_STATS: TRUE}),
550+
)
543551
else:
544552
# Table does not exist, create it.
545553
hive_table = self._convert_iceberg_into_hive(
@@ -626,7 +634,12 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
626634
tbl = open_client.get_table(dbname=from_database_name, tbl_name=from_table_name)
627635
tbl.dbName = to_database_name
628636
tbl.tableName = to_table_name
629-
open_client.alter_table(dbname=from_database_name, tbl_name=from_table_name, new_tbl=tbl)
637+
open_client.alter_table_with_environment_context(
638+
dbname=from_database_name,
639+
tbl_name=from_table_name,
640+
new_tbl=tbl,
641+
environment_context=EnvironmentContext(properties={DO_NOT_UPDATE_STATS: TRUE}),
642+
)
630643
except NoSuchObjectException as e:
631644
raise NoSuchTableError(f"Table does not exist: {from_table_name}") from e
632645
except InvalidOperationException as e:

0 commit comments

Comments
 (0)