Skip to content

Commit 5209874

Browse files
authored
enable set hadoop ugi for hive catalog (#472)
* enable set ugi for hive catalog. * fix * Suggested changes * fix ruff-format Failed * fix failed and pass tests.
1 parent 5c6010b commit 5209874

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

mkdocs/docs/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Options:
3636
--catalog TEXT
3737
--verbose BOOLEAN
3838
--output [text|json]
39+
--ugi TEXT
3940
--uri TEXT
4041
--credential TEXT
4142
--help Show this message and exit.

mkdocs/docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ catalog:
148148
| Key | Example | Description |
149149
| ---------------------- | ----------------------- | -------------------------------------------------------------------------------------------------- |
150150
| uri | https://rest-catalog/ws | URI identifying the REST Server |
151+
| ugi | t-1234:secret | Hadoop UGI for Hive client. |
151152
| credential | t-1234:secret | Credential to use for OAuth2 credential flow when initializing the catalog |
152153
| token | FEW23.DFSDF.FSDF | Bearer token value to use for `Authorization` header |
153154
| rest.sigv4-enabled | true | Sign requests to the REST Server using AWS SigV4 protocol |

pyiceberg/catalog/hive.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,21 @@ class _HiveClient:
130130

131131
_transport: TTransport
132132
_client: Client
133+
_ugi: Optional[List[str]]
133134

134-
def __init__(self, uri: str):
135+
def __init__(self, uri: str, ugi: Optional[str] = None):
135136
url_parts = urlparse(uri)
136137
transport = TSocket.TSocket(url_parts.hostname, url_parts.port)
137138
self._transport = TTransport.TBufferedTransport(transport)
138139
protocol = TBinaryProtocol.TBinaryProtocol(transport)
139140

140141
self._client = Client(protocol)
142+
self._ugi = ugi.split(':') if ugi else None
141143

142144
def __enter__(self) -> Client:
143145
self._transport.open()
146+
if self._ugi:
147+
self._client.set_ugi(*self._ugi)
144148
return self._client
145149

146150
def __exit__(
@@ -233,7 +237,7 @@ class HiveCatalog(Catalog):
233237

234238
def __init__(self, name: str, **properties: str):
235239
super().__init__(name, **properties)
236-
self._client = _HiveClient(properties["uri"])
240+
self._client = _HiveClient(properties["uri"], properties.get("ugi"))
237241

238242
def _convert_hive_into_iceberg(self, table: HiveTable, io: FileIO) -> Table:
239243
properties: Dict[str, str] = table.parameters

pyiceberg/cli/console.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,22 @@ def wrapper(*args: Any, **kwargs: Any): # type: ignore
5959
@click.option("--catalog")
6060
@click.option("--verbose", type=click.BOOL)
6161
@click.option("--output", type=click.Choice(["text", "json"]), default="text")
62+
@click.option("--ugi")
6263
@click.option("--uri")
6364
@click.option("--credential")
6465
@click.pass_context
65-
def run(ctx: Context, catalog: Optional[str], verbose: bool, output: str, uri: Optional[str], credential: Optional[str]) -> None:
66+
def run(
67+
ctx: Context,
68+
catalog: Optional[str],
69+
verbose: bool,
70+
output: str,
71+
ugi: Optional[str],
72+
uri: Optional[str],
73+
credential: Optional[str],
74+
) -> None:
6675
properties = {}
76+
if ugi:
77+
properties["ugi"] = ugi
6778
if uri:
6879
properties["uri"] = uri
6980
if credential:

0 commit comments

Comments
 (0)