Skip to content
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
4 changes: 2 additions & 2 deletions mkdocs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,12 +746,12 @@ catalog:

| Key | Example | Description |
|------------------------------| ------- | ------------------------------------ |
| hive.hive2-compatible | true | Using Hive 2.x compatibility mode |
| hive.hive2-compatible | true | Set to `true` when using a Hive 2.x metastore |
| hive.kerberos-authentication | true | Using authentication via Kerberos |
| hive.kerberos-service-name | hive | Kerberos service name (default hive) |
| ugi | t-1234:secret | Hadoop UGI for Hive client. |

When using Hive 2.x, make sure to set the compatibility flag:
Hive 3 and newer need no extra configuration. When using a Hive 2.x metastore, set the compatibility flag:

```yaml
catalog:
Expand Down
13 changes: 11 additions & 2 deletions pyiceberg/catalog/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from hive_metastore.ttypes import (
AlreadyExistsException,
CheckLockRequest,
DataOperationType,
EnvironmentContext,
FieldSchema,
GetTableRequest,
Expand Down Expand Up @@ -383,7 +384,7 @@ def _create_hive_table(self, open_client: Client, hive_table: HiveTable) -> None
raise TableAlreadyExistsError(f"Table {hive_table.dbName}.{hive_table.tableName} already exists") from e

def _fetch_hive_table(self, open_client: Client, database_name: str, table_name: str) -> HiveTable:
# Hive 4.0.1 removed get_table, and Hive 2 does not have get_table_req
# Hive 4.0.1 removed get_table, and Hive 2.2 and older do not have get_table_req
if self._hive2_compatible:
return open_client.get_table(dbname=database_name, tbl_name=table_name)
return open_client.get_table_req(GetTableRequest(dbName=database_name, tblName=table_name)).table
Expand Down Expand Up @@ -506,8 +507,16 @@ def load_view(self, identifier: str | Identifier) -> View:
raise NotImplementedError

def _create_lock_request(self, database_name: str, table_name: str) -> LockRequest:
# Iceberg commits are not executed within a Hive transaction, so the lock component uses operationType=NO_TXN.
# Setting it explicitly also matters for Hive 2.1, which rejects a lock component left at the default UNSET
# operation type.
lock_component: LockComponent = LockComponent(
level=LockLevel.TABLE, type=LockType.EXCLUSIVE, dbname=database_name, tablename=table_name, isTransactional=True
level=LockLevel.TABLE,
type=LockType.EXCLUSIVE,
dbname=database_name,
tablename=table_name,
operationType=DataOperationType.NO_TXN,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot add unit test since the infra is using hive 4.x

i did test this locally with a hive 2.1 setup

isTransactional=True,
)

lock_request: LockRequest = LockRequest(component=[lock_component], user=getpass.getuser(), hostname=socket.gethostname())
Expand Down
Loading