Fokko commented on code in PR #5391: URL: https://github.com/apache/iceberg/pull/5391#discussion_r933979347
########## python/pyiceberg/catalog/hive.py: ########## @@ -0,0 +1,262 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from getpass import getuser +from time import time +from typing import ( + List, + Optional, + Set, + Union, +) +from urllib.parse import urlparse + +from hive_metastore.ThriftHiveMetastore import Client +from hive_metastore.ttypes import AlreadyExistsException +from hive_metastore.ttypes import Database as HiveDatabase +from hive_metastore.ttypes import ( + FieldSchema, + InvalidOperationException, + MetaException, + NoSuchObjectException, + SerDeInfo, + StorageDescriptor, +) +from hive_metastore.ttypes import Table as HiveTable +from thrift.protocol import TBinaryProtocol +from thrift.transport import TSocket, TTransport + +from pyiceberg.catalog import Identifier, Properties +from pyiceberg.catalog.base import Catalog +from pyiceberg.exceptions import ( + AlreadyExistsError, + NamespaceNotEmptyError, + NoSuchNamespaceError, + NoSuchTableError, +) +from pyiceberg.schema import Schema +from pyiceberg.table.base import Table +from pyiceberg.table.partitioning import PartitionSpec +from pyiceberg.types import ( + BinaryType, + BooleanType, + DateType, + DecimalType, + DoubleType, + FixedType, + FloatType, + IcebergType, + IntegerType, + ListType, + LongType, + MapType, + StringType, + StructType, + TimestampType, + TimeType, + UUIDType, +) + +hive_types = { + BooleanType: "boolean", + IntegerType: "int", + LongType: "bigint", + FloatType: "float", + DoubleType: "double", + DateType: "date", + TimeType: "string", + TimestampType: "timestamp", + StringType: "string", + UUIDType: "string", + BinaryType: "binary", + FixedType: "binary", + DecimalType: None, + StructType: None, + ListType: None, + MapType: None, +} + + +class _HiveClient: + _transport: TTransport + _client: Client + + def __init__(self, url: str): + url_parts = urlparse(url) + transport = TSocket.TSocket(url_parts.hostname, url_parts.port) + self._transport = TTransport.TBufferedTransport(transport) + protocol = TBinaryProtocol.TBinaryProtocol(transport) + + self._client = Client(protocol) + + def __enter__(self) -> Client: + self._transport.open() + return self._client + + def __exit__(self, exc_type, exc_val, exc_tb): + self._transport.close() + + +class HiveCatalog(Catalog): + _client: _HiveClient + + def __init__(self, name: str, properties: Properties, url: str): Review Comment: Updated, but still `urlparse` :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org