3030
3131import boto3
3232from botocore .config import Config
33- from mypy_boto3_glue .client import GlueClient
34- from mypy_boto3_glue .type_defs import (
35- ColumnTypeDef ,
36- DatabaseInputTypeDef ,
37- DatabaseTypeDef ,
38- StorageDescriptorTypeDef ,
39- TableInputTypeDef ,
40- TableTypeDef ,
41- )
4233
4334from pyiceberg .catalog import (
4435 BOTOCORE_SESSION ,
10192
10293if TYPE_CHECKING :
10394 import pyarrow as pa
95+ from mypy_boto3_glue .client import GlueClient
96+ from mypy_boto3_glue .type_defs import (
97+ ColumnTypeDef ,
98+ DatabaseInputTypeDef ,
99+ DatabaseTypeDef ,
100+ StorageDescriptorTypeDef ,
101+ TableInputTypeDef ,
102+ TableTypeDef ,
103+ )
104104
105105
106106# There is a unique Glue metastore in each AWS account and each AWS region. By default, GlueCatalog chooses the Glue
140140
141141
142142def _construct_parameters (
143- metadata_location : str , glue_table : Optional [TableTypeDef ] = None , prev_metadata_location : Optional [str ] = None
143+ metadata_location : str , glue_table : Optional [" TableTypeDef" ] = None , prev_metadata_location : Optional [str ] = None
144144) -> Properties :
145145 new_parameters = glue_table .get ("Parameters" , {}) if glue_table else {}
146146 new_parameters .update ({TABLE_TYPE : ICEBERG .upper (), METADATA_LOCATION : metadata_location })
@@ -190,15 +190,15 @@ def primitive(self, primitive: PrimitiveType) -> str:
190190 return GLUE_PRIMITIVE_TYPES [primitive_type ]
191191
192192
193- def _to_columns (metadata : TableMetadata ) -> List [ColumnTypeDef ]:
194- results : Dict [str , ColumnTypeDef ] = {}
193+ def _to_columns (metadata : TableMetadata ) -> List [" ColumnTypeDef" ]:
194+ results : Dict [str , " ColumnTypeDef" ] = {}
195195
196196 def _append_to_results (field : NestedField , is_current : bool ) -> None :
197197 if field .name in results :
198198 return
199199
200200 results [field .name ] = cast (
201- ColumnTypeDef ,
201+ " ColumnTypeDef" ,
202202 {
203203 "Name" : field .name ,
204204 "Type" : visit (field .field_type , _IcebergSchemaToGlueType ()),
@@ -230,10 +230,10 @@ def _construct_table_input(
230230 metadata_location : str ,
231231 properties : Properties ,
232232 metadata : TableMetadata ,
233- glue_table : Optional [TableTypeDef ] = None ,
233+ glue_table : Optional [" TableTypeDef" ] = None ,
234234 prev_metadata_location : Optional [str ] = None ,
235- ) -> TableInputTypeDef :
236- table_input : TableInputTypeDef = {
235+ ) -> " TableInputTypeDef" :
236+ table_input : " TableInputTypeDef" = {
237237 "Name" : table_name ,
238238 "TableType" : EXTERNAL_TABLE ,
239239 "Parameters" : _construct_parameters (metadata_location , glue_table , prev_metadata_location ),
@@ -249,8 +249,8 @@ def _construct_table_input(
249249 return table_input
250250
251251
252- def _construct_rename_table_input (to_table_name : str , glue_table : TableTypeDef ) -> TableInputTypeDef :
253- rename_table_input : TableInputTypeDef = {"Name" : to_table_name }
252+ def _construct_rename_table_input (to_table_name : str , glue_table : " TableTypeDef" ) -> " TableInputTypeDef" :
253+ rename_table_input : " TableInputTypeDef" = {"Name" : to_table_name }
254254 # use the same Glue info to create the new table, pointing to the old metadata
255255 assert glue_table ["TableType" ]
256256 rename_table_input ["TableType" ] = glue_table ["TableType" ]
@@ -264,16 +264,16 @@ def _construct_rename_table_input(to_table_name: str, glue_table: TableTypeDef)
264264 # It turns out the output of StorageDescriptor is not the same as the input type
265265 # because the Column can have a different type, but for now it seems to work, so
266266 # silence the type error.
267- rename_table_input ["StorageDescriptor" ] = cast (StorageDescriptorTypeDef , glue_table ["StorageDescriptor" ])
267+ rename_table_input ["StorageDescriptor" ] = cast (" StorageDescriptorTypeDef" , glue_table ["StorageDescriptor" ])
268268
269269 if "Description" in glue_table :
270270 rename_table_input ["Description" ] = glue_table ["Description" ]
271271
272272 return rename_table_input
273273
274274
275- def _construct_database_input (database_name : str , properties : Properties ) -> DatabaseInputTypeDef :
276- database_input : DatabaseInputTypeDef = {"Name" : database_name }
275+ def _construct_database_input (database_name : str , properties : Properties ) -> " DatabaseInputTypeDef" :
276+ database_input : " DatabaseInputTypeDef" = {"Name" : database_name }
277277 parameters = {}
278278 for k , v in properties .items ():
279279 if k == "Description" :
@@ -286,7 +286,7 @@ def _construct_database_input(database_name: str, properties: Properties) -> Dat
286286 return database_input
287287
288288
289- def _register_glue_catalog_id_with_glue_client (glue : GlueClient , glue_catalog_id : str ) -> None :
289+ def _register_glue_catalog_id_with_glue_client (glue : " GlueClient" , glue_catalog_id : str ) -> None :
290290 """
291291 Register the Glue Catalog ID (AWS Account ID) as a parameter on all Glue client methods.
292292
@@ -303,9 +303,9 @@ def add_glue_catalog_id(params: Dict[str, str], **kwargs: Any) -> None:
303303
304304
305305class GlueCatalog (MetastoreCatalog ):
306- glue : GlueClient
306+ glue : " GlueClient"
307307
308- def __init__ (self , name : str , client : Optional [GlueClient ] = None , ** properties : Any ):
308+ def __init__ (self , name : str , client : Optional [" GlueClient" ] = None , ** properties : Any ):
309309 """Glue Catalog.
310310
311311 You either need to provide a boto3 glue client, or one will be constructed from the properties.
@@ -317,7 +317,7 @@ def __init__(self, name: str, client: Optional[GlueClient] = None, **properties:
317317 """
318318 super ().__init__ (name , ** properties )
319319
320- if client :
320+ if client is not None :
321321 self .glue = client
322322 else :
323323 retry_mode_prop_value = get_first_property_value (properties , GLUE_RETRY_MODE )
@@ -344,7 +344,7 @@ def __init__(self, name: str, client: Optional[GlueClient] = None, **properties:
344344 if glue_catalog_id := properties .get (GLUE_ID ):
345345 _register_glue_catalog_id_with_glue_client (self .glue , glue_catalog_id )
346346
347- def _convert_glue_to_iceberg (self , glue_table : TableTypeDef ) -> Table :
347+ def _convert_glue_to_iceberg (self , glue_table : " TableTypeDef" ) -> Table :
348348 properties : Properties = glue_table ["Parameters" ]
349349
350350 assert glue_table ["DatabaseName" ]
@@ -380,15 +380,15 @@ def _convert_glue_to_iceberg(self, glue_table: TableTypeDef) -> Table:
380380 catalog = self ,
381381 )
382382
383- def _create_glue_table (self , database_name : str , table_name : str , table_input : TableInputTypeDef ) -> None :
383+ def _create_glue_table (self , database_name : str , table_name : str , table_input : " TableInputTypeDef" ) -> None :
384384 try :
385385 self .glue .create_table (DatabaseName = database_name , TableInput = table_input )
386386 except self .glue .exceptions .AlreadyExistsException as e :
387387 raise TableAlreadyExistsError (f"Table { database_name } .{ table_name } already exists" ) from e
388388 except self .glue .exceptions .EntityNotFoundException as e :
389389 raise NoSuchNamespaceError (f"Database { database_name } does not exist" ) from e
390390
391- def _update_glue_table (self , database_name : str , table_name : str , table_input : TableInputTypeDef , version_id : str ) -> None :
391+ def _update_glue_table (self , database_name : str , table_name : str , table_input : " TableInputTypeDef" , version_id : str ) -> None :
392392 try :
393393 self .glue .update_table (
394394 DatabaseName = database_name ,
@@ -403,7 +403,7 @@ def _update_glue_table(self, database_name: str, table_name: str, table_input: T
403403 f"Cannot commit { database_name } .{ table_name } because Glue detected concurrent update to table version { version_id } "
404404 ) from e
405405
406- def _get_glue_table (self , database_name : str , table_name : str ) -> TableTypeDef :
406+ def _get_glue_table (self , database_name : str , table_name : str ) -> " TableTypeDef" :
407407 try :
408408 load_table_response = self .glue .get_table (DatabaseName = database_name , Name = table_name )
409409 return load_table_response ["Table" ]
@@ -496,7 +496,7 @@ def commit_table(
496496 table_identifier = table .name ()
497497 database_name , table_name = self .identifier_to_database_and_table (table_identifier , NoSuchTableError )
498498
499- current_glue_table : Optional [TableTypeDef ]
499+ current_glue_table : Optional [" TableTypeDef" ]
500500 glue_table_version_id : Optional [str ]
501501 current_table : Optional [Table ]
502502 try :
@@ -702,7 +702,7 @@ def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
702702 NoSuchNamespaceError: If a namespace with the given name does not exist, or the identifier is invalid.
703703 """
704704 database_name = self .identifier_to_database (namespace , NoSuchNamespaceError )
705- table_list : List [TableTypeDef ] = []
705+ table_list : List [" TableTypeDef" ] = []
706706 next_token : Optional [str ] = None
707707 try :
708708 while True :
@@ -730,7 +730,7 @@ def list_namespaces(self, namespace: Union[str, Identifier] = ()) -> List[Identi
730730 if namespace :
731731 return []
732732
733- database_list : List [DatabaseTypeDef ] = []
733+ database_list : List [" DatabaseTypeDef" ] = []
734734 next_token : Optional [str ] = None
735735
736736 while True :
@@ -806,5 +806,5 @@ def view_exists(self, identifier: Union[str, Identifier]) -> bool:
806806 raise NotImplementedError
807807
808808 @staticmethod
809- def __is_iceberg_table (table : TableTypeDef ) -> bool :
809+ def __is_iceberg_table (table : " TableTypeDef" ) -> bool :
810810 return table .get ("Parameters" , {}).get (TABLE_TYPE , "" ).lower () == ICEBERG
0 commit comments