@@ -868,6 +868,8 @@ class BigQueryCreateEmptyTableOperator(BaseOperator):
868
868
Service Account Token Creator IAM role to the directly preceding identity, with first
869
869
account from the list granting this role to the originating account (templated).
870
870
:type impersonation_chain: Union[str, Sequence[str]]
871
+ :param exists_ok: If ``True``, ignore "already exists" errors when creating the table.
872
+ :type exists_ok: bool
871
873
"""
872
874
873
875
template_fields = (
@@ -905,6 +907,7 @@ def __init__(
905
907
location : Optional [str ] = None ,
906
908
cluster_fields : Optional [List [str ]] = None ,
907
909
impersonation_chain : Optional [Union [str , Sequence [str ]]] = None ,
910
+ exists_ok : bool = False ,
908
911
** kwargs ,
909
912
) -> None :
910
913
super ().__init__ (** kwargs )
@@ -926,6 +929,7 @@ def __init__(
926
929
self .cluster_fields = cluster_fields
927
930
self .table_resource = table_resource
928
931
self .impersonation_chain = impersonation_chain
932
+ self .exists_ok = exists_ok
929
933
930
934
def execute (self , context ) -> None :
931
935
bq_hook = BigQueryHook (
@@ -960,7 +964,7 @@ def execute(self, context) -> None:
960
964
materialized_view = self .materialized_view ,
961
965
encryption_configuration = self .encryption_configuration ,
962
966
table_resource = self .table_resource ,
963
- exists_ok = False ,
967
+ exists_ok = self . exists_ok ,
964
968
)
965
969
self .log .info (
966
970
'Table %s.%s.%s created successfully' , table .project , table .dataset_id , table .table_id
@@ -1357,6 +1361,8 @@ class BigQueryCreateEmptyDatasetOperator(BaseOperator):
1357
1361
Service Account Token Creator IAM role to the directly preceding identity, with first
1358
1362
account from the list granting this role to the originating account (templated).
1359
1363
:type impersonation_chain: Union[str, Sequence[str]]
1364
+ :param exists_ok: If ``True``, ignore "already exists" errors when creating the dataset.
1365
+ :type exists_ok: bool
1360
1366
**Example**: ::
1361
1367
1362
1368
create_new_dataset = BigQueryCreateEmptyDatasetOperator(
@@ -1389,6 +1395,7 @@ def __init__(
1389
1395
bigquery_conn_id : Optional [str ] = None ,
1390
1396
delegate_to : Optional [str ] = None ,
1391
1397
impersonation_chain : Optional [Union [str , Sequence [str ]]] = None ,
1398
+ exists_ok : bool = False ,
1392
1399
** kwargs ,
1393
1400
) -> None :
1394
1401
@@ -1408,6 +1415,7 @@ def __init__(
1408
1415
self .dataset_reference = dataset_reference if dataset_reference else {}
1409
1416
self .delegate_to = delegate_to
1410
1417
self .impersonation_chain = impersonation_chain
1418
+ self .exists_ok = exists_ok
1411
1419
1412
1420
super ().__init__ (** kwargs )
1413
1421
@@ -1425,7 +1433,7 @@ def execute(self, context) -> None:
1425
1433
dataset_id = self .dataset_id ,
1426
1434
dataset_reference = self .dataset_reference ,
1427
1435
location = self .location ,
1428
- exists_ok = False ,
1436
+ exists_ok = self . exists_ok ,
1429
1437
)
1430
1438
except Conflict :
1431
1439
dataset_id = self .dataset_reference .get ("datasetReference" , {}).get ("datasetId" , self .dataset_id )
0 commit comments