diff --git a/mkdocs/docs/cli.md b/mkdocs/docs/cli.md index 695011a6ef..28e44955d7 100644 --- a/mkdocs/docs/cli.md +++ b/mkdocs/docs/cli.md @@ -36,6 +36,7 @@ Options: --catalog TEXT --verbose BOOLEAN --output [text|json] +--ugi TEXT --uri TEXT --credential TEXT --help Show this message and exit. diff --git a/mkdocs/docs/configuration.md b/mkdocs/docs/configuration.md index 8acc0a98cb..d69b9851d3 100644 --- a/mkdocs/docs/configuration.md +++ b/mkdocs/docs/configuration.md @@ -148,6 +148,7 @@ catalog: | Key | Example | Description | | ---------------------- | ----------------------- | -------------------------------------------------------------------------------------------------- | | uri | https://rest-catalog/ws | URI identifying the REST Server | +| ugi | t-1234:secret | Hadoop UGI for Hive client. | | credential | t-1234:secret | Credential to use for OAuth2 credential flow when initializing the catalog | | token | FEW23.DFSDF.FSDF | Bearer token value to use for `Authorization` header | | rest.sigv4-enabled | true | Sign requests to the REST Server using AWS SigV4 protocol | diff --git a/pyiceberg/catalog/hive.py b/pyiceberg/catalog/hive.py index 4d4370fc46..c24355f6fb 100644 --- a/pyiceberg/catalog/hive.py +++ b/pyiceberg/catalog/hive.py @@ -130,17 +130,21 @@ class _HiveClient: _transport: TTransport _client: Client + _ugi: Optional[List[str]] - def __init__(self, uri: str): + def __init__(self, uri: str, ugi: Optional[str] = None): url_parts = urlparse(uri) transport = TSocket.TSocket(url_parts.hostname, url_parts.port) self._transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) self._client = Client(protocol) + self._ugi = ugi.split(':') if ugi else None def __enter__(self) -> Client: self._transport.open() + if self._ugi: + self._client.set_ugi(*self._ugi) return self._client def __exit__( @@ -233,7 +237,7 @@ class HiveCatalog(Catalog): def __init__(self, name: str, **properties: str): super().__init__(name, **properties) - self._client = _HiveClient(properties["uri"]) + self._client = _HiveClient(properties["uri"], properties.get("ugi")) def _convert_hive_into_iceberg(self, table: HiveTable, io: FileIO) -> Table: properties: Dict[str, str] = table.parameters diff --git a/pyiceberg/cli/console.py b/pyiceberg/cli/console.py index 095c1ef6dc..0fbda10960 100644 --- a/pyiceberg/cli/console.py +++ b/pyiceberg/cli/console.py @@ -59,11 +59,22 @@ def wrapper(*args: Any, **kwargs: Any): # type: ignore @click.option("--catalog") @click.option("--verbose", type=click.BOOL) @click.option("--output", type=click.Choice(["text", "json"]), default="text") +@click.option("--ugi") @click.option("--uri") @click.option("--credential") @click.pass_context -def run(ctx: Context, catalog: Optional[str], verbose: bool, output: str, uri: Optional[str], credential: Optional[str]) -> None: +def run( + ctx: Context, + catalog: Optional[str], + verbose: bool, + output: str, + ugi: Optional[str], + uri: Optional[str], + credential: Optional[str], +) -> None: properties = {} + if ugi: + properties["ugi"] = ugi if uri: properties["uri"] = uri if credential: