@@ -302,11 +302,18 @@ def _convert_glue_to_iceberg(self, glue_table: TableTypeDef) -> Table:
302302 catalog = self ,
303303 )
304304
305- def _create_glue_table (self , database_name : str , table_name : str , table_input : TableInputTypeDef ) -> None :
305+ def _create_glue_table (
306+ self ,
307+ database_name : str ,
308+ table_name : str ,
309+ table_input : TableInputTypeDef ,
310+ fail_if_exists : bool = True ,
311+ ) -> None :
306312 try :
307313 self .glue .create_table (DatabaseName = database_name , TableInput = table_input )
308314 except self .glue .exceptions .AlreadyExistsException as e :
309- raise TableAlreadyExistsError (f"Table { database_name } .{ table_name } already exists" ) from e
315+ if fail_if_exists :
316+ raise TableAlreadyExistsError (f"Table { database_name } .{ table_name } already exists" ) from e
310317 except self .glue .exceptions .EntityNotFoundException as e :
311318 raise NoSuchNamespaceError (f"Database { database_name } does not exist" ) from e
312319
@@ -340,6 +347,7 @@ def create_table(
340347 partition_spec : PartitionSpec = UNPARTITIONED_PARTITION_SPEC ,
341348 sort_order : SortOrder = UNSORTED_SORT_ORDER ,
342349 properties : Properties = EMPTY_DICT ,
350+ fail_if_exists : bool = True ,
343351 ) -> Table :
344352 """
345353 Create an Iceberg table.
@@ -351,6 +359,7 @@ def create_table(
351359 partition_spec: PartitionSpec for the table.
352360 sort_order: SortOrder for the table.
353361 properties: Table properties that can be a string based dictionary.
362+ fail_if_exists: If True, raise an error if the table already exists.
354363
355364 Returns:
356365 Table: the created table instance.
@@ -374,7 +383,9 @@ def create_table(
374383
375384 table_input = _construct_table_input (table_name , metadata_location , properties , metadata )
376385 database_name , table_name = self .identifier_to_database_and_table (identifier )
377- self ._create_glue_table (database_name = database_name , table_name = table_name , table_input = table_input )
386+ self ._create_glue_table (
387+ database_name = database_name , table_name = table_name , table_input = table_input , fail_if_exists = fail_if_exists
388+ )
378389
379390 return self .load_table (identifier = identifier )
380391
0 commit comments