@@ -448,6 +448,9 @@ def __init__(self, type, name, project):
448448 self .creation_settings = {
449449 }
450450
451+ def set_name (self , name ):
452+ self .recipe_proto ["name" ] = name
453+
451454 def _build_ref (self , object_id , project_key = None ):
452455 if project_key is not None and project_key != self .project .project_key :
453456 return project_key + '.' + object_id
@@ -547,10 +550,10 @@ def with_existing_output(self, dataset_name, append=False):
547550 self ._with_output (dataset_name , append )
548551 return self
549552
550- def with_new_output (self , name , connection_id , typeOptionId = None , format_option_id = None , override_sql_schema = None , partitioning_option_id = None , append = False , object_type = 'DATASET' ):
553+ def with_new_output (self , name , connection_id , typeOptionId = None , format_option_id = None , override_sql_schema = None , partitioning_option_id = None , append = False , object_type = 'DATASET' , overwrite = False ):
551554 """
552555 Create a new dataset as output to the recipe-to-be-created. The dataset is not created immediately,
553- but when the recipe is created (ie in the build () method)
556+ but when the recipe is created (ie in the create () method)
554557
555558 :param str name: name of the dataset or identifier of the managed folder
556559 :param str connection_id: name of the connection to create the dataset on
@@ -565,9 +568,15 @@ def with_new_output(self, name, connection_id, typeOptionId=None, format_option_
565568 :param append: whether the recipe should append or overwrite the output when running
566569 (note: not available for all dataset types)
567570 :param str object_type: DATASET or MANAGED_FOLDER
571+ :param overwrite: If the dataset being created already exists, overwrite it (and delete data)
568572 """
569573 if object_type == 'DATASET' :
570574 assert self .create_output_dataset is None
575+
576+ dataset = self .project .get_dataset (name )
577+ if overwrite and dataset .exists ():
578+ dataset .delete (drop_data = True )
579+
571580 self .create_output_dataset = True
572581 self .output_dataset_settings = {'connectionId' :connection_id ,'typeOptionId' :typeOptionId ,'specificSettings' :{'formatOptionId' :format_option_id , 'overrideSQLSchema' :override_sql_schema },'partitioningOptionId' :partitioning_option_id }
573582 self ._with_output (name , append )
@@ -952,7 +961,7 @@ def with_new_output_dataset(self, name, connection,
952961 Use None for not partitioning the output, "FIRST_INPUT" to copy from the first input of the recipe,
953962 "dataset:XXX" to copy from a dataset name, or "folder:XXX" to copy from a folder id
954963 :param append: whether the recipe should append or overwrite the output when running (note: not available for all dataset types)
955- :param overwrite: If the object being created already exists, overwrite it
964+ :param overwrite: If the dataset being created already exists, overwrite it (and delete data)
956965 """
957966
958967 ch = self .project .new_managed_dataset_creation_helper (name )
0 commit comments