arminnajafi commented on code in PR #6646: URL: https://github.com/apache/iceberg/pull/6646#discussion_r1103866902
########## python/pyiceberg/catalog/dynamodb.py: ########## @@ -0,0 +1,776 @@ +# 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 uuid +from time import time +from typing import ( + Any, + Dict, + List, + Optional, + Set, + Union, +) + +import boto3 + +from pyiceberg.catalog import ( + ICEBERG, + METADATA_LOCATION, + PREVIOUS_METADATA_LOCATION, + TABLE_TYPE, + Catalog, + Identifier, + Properties, + PropertiesUpdateSummary, +) +from pyiceberg.exceptions import ( + ConditionalCheckFailedException, + GenericDynamoDbError, + ItemNotFound, + NamespaceAlreadyExistsError, + NamespaceNotEmptyError, + NoSuchIcebergTableError, + NoSuchNamespaceError, + NoSuchPropertyException, + NoSuchTableError, + TableAlreadyExistsError, + ValidationError, +) +from pyiceberg.io import load_file_io +from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec +from pyiceberg.schema import Schema +from pyiceberg.serializers import FromInputFile +from pyiceberg.table import Table +from pyiceberg.table.metadata import new_table_metadata +from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder +from pyiceberg.typedef import EMPTY_DICT + +DYNAMODB_CLIENT = "dynamodb" + +DYNAMODB_COL_IDENTIFIER = "identifier" +DYNAMODB_COL_NAMESPACE = "namespace" +DYNAMODB_COL_VERSION = "v" +DYNAMODB_COL_UPDATED_AT = "updated_at" +DYNAMODB_COL_CREATED_AT = "created_at" +DYNAMODB_NAMESPACE = "NAMESPACE" +DYNAMODB_NAMESPACE_GSI = "namespace-identifier" +DYNAMODB_PAY_PER_REQUEST = "PAY_PER_REQUEST" + +DYNAMODB_TABLE_NAME = "dynamodb_table_name" +DYNAMODB_TABLE_NAME_DEFAULT = "iceberg" + +PROPERTY_KEY_PREFIX = "p." + +ACTIVE = "ACTIVE" +ITEM = "Item" + + +class DynamoDbCatalog(Catalog): + def __init__(self, name: str, **properties: str): + super().__init__(name, **properties) + self.dynamodb = boto3.client(DYNAMODB_CLIENT) + self.dynamodb_table_name = self.properties.get(DYNAMODB_TABLE_NAME, DYNAMODB_TABLE_NAME_DEFAULT) + self._ensure_catalog_table_exists_or_create() + + def _ensure_catalog_table_exists_or_create(self) -> None: + if self._dynamodb_table_exists(): + return Review Comment: I think empty return is the same as return None. But I added it anyway to be more explicit. -- 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]
