jackye1995 commented on code in PR #5870: URL: https://github.com/apache/iceberg/pull/5870#discussion_r983721926
########## python/pyiceberg/catalog/glue.py: ########## @@ -0,0 +1,202 @@ +# 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. + + +import getpass +import uuid + +import boto3 +from datetime import datetime +from typing import Union, Optional, List, Set, Dict + +from pyiceberg.catalog.hive import OWNER + +from pyiceberg.exceptions import ( + NamespaceAlreadyExistsError, + NamespaceNotEmptyError, + NoSuchNamespaceError, + NoSuchTableError, + TableAlreadyExistsError, +) + +from pyiceberg.catalog import ( + Catalog, + Identifier, + Properties, + PropertiesUpdateSummary, +) +from pyiceberg.io import FileIO, load_file_io +from pyiceberg.schema import Schema +from pyiceberg.serializers import FromInputFile, ToOutputFile +from pyiceberg.table import Table +from pyiceberg.table.metadata import TableMetadata, new_table_metadata +from pyiceberg.table.partitioning import PartitionSpec, UNPARTITIONED_PARTITION_SPEC +from pyiceberg.table.sorting import SortOrder, UNSORTED_SORT_ORDER, SortDirection +from pyiceberg.typedef import EMPTY_DICT + +from pyiceberg.types import NestedField + +METADATA_LOCATION = "metadata_location" +ICEBERG = "iceberg" + + +class GlueCatalog(Catalog): + + def __init__(self, name: str, **properties: Properties): + super().__init__(name, **properties) + self.client = boto3.client("glue") + self.sts_client = boto3.client("sts") + + + def _check_response(self, response: Dict[str, Dict[str, str]]): + if response['ResponseMetadata']['HTTPStatusCode'] != 200: + raise ValueError(f"Got unexpected status code {response['HttpStatusCode']}") + + def _glue_to_iceberg(self, glue_table, io: FileIO) -> Table: + properties: Dict[str, str] = glue_table["Parameters"] + + if "table_type" not in properties: + raise NoSuchTableError( + f"Property table_type missing, could not determine type: {glue_table['DatabaseName']}.{glue_table['Name']}") + glue_table_type = properties.get("table_type") + if glue_table_type.lower() != ICEBERG: + raise NoSuchTableError( + f"Property table_type is {glue_table_type}, expected {ICEBERG}: {glue_table['DatabaseName']}.{glue_table['Name']}") + if prop_meta_location := properties.get(METADATA_LOCATION): + metadata_location = prop_meta_location + else: + raise NoSuchTableError(f"Table property {METADATA_LOCATION} is missing") + + file = io.new_input(metadata_location) + metadata = FromInputFile.table_metadata(file) + return Table( + identifier=(glue_table['DatabaseName'], glue_table['Name']), + metadata=metadata, + metadata_location=metadata_location + ) + + def _iceberg_to_glue(self, iceberg_table): + # TODO + pass + + def _construct_parameters(self, metadata_location: str) -> Dict[str, str]: + properties = {"table_type": "ICEBERG", "metadata_location": metadata_location} Review Comment: Constants that should be defined similar to https://github.com/apache/iceberg/blob/master/python/pyiceberg/catalog/hive.py#L147. I know there are a few duplicates, once we have those in place we can then discuss what could be extracted to a base. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
