JonasJ-ap commented on code in PR #5870:
URL: https://github.com/apache/iceberg/pull/5870#discussion_r983099664


##########
python/pyiceberg/catalog/glue.py:
##########
@@ -0,0 +1,237 @@
+#  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 __future__ import annotations
+
+import getpass
+
+import boto3
+from datetime import datetime
+from typing import Union, Optional, List, Set, Dict
+
+from pyiceberg.catalog.hive import OWNER
+
+from pyiceberg.catalog import Catalog, PropertiesUpdateSummary
+from pyiceberg.schema import Schema
+from pyiceberg.table import Table
+from pyiceberg.table.partitioning import PartitionSpec, 
UNPARTITIONED_PARTITION_SPEC
+from pyiceberg.table.sorting import SortOrder, UNSORTED_SORT_ORDER, 
SortDirection
+from pyiceberg.typedef import Identifier, Properties, EMPTY_DICT
+from pyiceberg.types import NestedField
+
+
+class GlueCatalog(Catalog):
+
+    def __init__(self, name: str, properties: Properties):
+        self.client = boto3.client("glue")
+        self.sts_client = boto3.client("sts")
+        super().__init__(name, **properties)
+
+    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):
+        # TODO
+        pass
+
+    def _iceberg_to_glue(self, iceberg_table):
+        # TODO
+        pass
+
+    # tested on pre-existing database
+    def create_table(
+            self,
+            identifier: str | Identifier,
+            schema: Schema,
+            location: str | None = None,
+            partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
+            sort_order: SortOrder = UNSORTED_SORT_ORDER,
+            properties: Properties = EMPTY_DICT,
+    ) -> Table:
+        database_name, table_name = self.identifier_to_tuple(identifier)
+
+        now = datetime.now()
+
+        def _convert_column(field: NestedField):
+            d = {'Name': field.name, 'Type': str(field.field_type)}
+
+            if field.doc:
+                d['Comment'] = field.doc
+
+            return d
+
+        # Do all the metadata foo once the Hive PR has been merged
+        try:
+            create_table_response = self.client.create_table(
+                DatabaseName=database_name,
+                TableInput={
+                    'Name': table_name,
+                    'Description': 'string',  # To be fixed
+                    'Owner': properties[OWNER] if properties and OWNER in 
properties
+                    else 
boto3.client("sts").get_caller_identity().get("Account"),
+                    'LastAccessTime': now,
+                    'LastAnalyzedTime': now,
+                    'StorageDescriptor': {
+                        'Columns': list(map(_convert_column, schema.fields)),
+                        'Location': location or 's3://',  # To be fixed
+                        'BucketColumns': [
+                            'string',
+                        ],
+                        'SortColumns': [{
+                            schema.find_column_name(field.source_id),
+                            1 if field.direction == SortDirection.ASC else 0
+                        } for field in sort_order.fields]
+                    },
+                    'PartitionKeys': [
+                        {
+                            'Name': schema.find_column_name(spec.source_id),
+                            'Type': str(schema.find_type(spec.source_id)),
+                            'Comment': str(spec.transform)
+                        }
+                        for spec in partition_spec.fields],
+                    'TableType': 'EXTERNAL_TABLE',
+                    'Parameters': properties,

Review Comment:
   Thank you for your suggestions. I'll redesign my implementation following 
the logic in `hive.py`



-- 
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]

Reply via email to