@@ -227,6 +227,7 @@ def __init__(
227227 job_id : str | None = None ,
228228 force_rerun : bool = True ,
229229 reattach_states : set [str ] | None = None ,
230+ project_id : str | None = None ,
230231 ** kwargs ,
231232 ) -> None :
232233
@@ -249,6 +250,7 @@ def __init__(
249250
250251 # BQ config
251252 self .destination_project_dataset_table = destination_project_dataset_table
253+ self .project_id = project_id
252254 self .schema_fields = schema_fields
253255 if source_format .upper () not in ALLOWED_FORMATS :
254256 raise ValueError (
@@ -306,7 +308,7 @@ def _submit_job(
306308 # Submit a new job without waiting for it to complete.
307309 return hook .insert_job (
308310 configuration = self .configuration ,
309- project_id = hook .project_id ,
311+ project_id = self .project_id ,
310312 location = self .location ,
311313 job_id = job_id ,
312314 timeout = self .result_timeout ,
@@ -507,9 +509,9 @@ def _find_max_value_in_column(self):
507509 raise RuntimeError (f"The { select_command } returned no rows!" )
508510
509511 def _create_empty_table (self ):
510- project_id , dataset_id , table_id = self .hook .split_tablename (
512+ self . project_id , dataset_id , table_id = self .hook .split_tablename (
511513 table_input = self .destination_project_dataset_table ,
512- default_project_id = self .hook . project_id or "" ,
514+ default_project_id = self .project_id or self . hook . project_id ,
513515 )
514516
515517 external_config_api_repr = {
@@ -556,7 +558,7 @@ def _create_empty_table(self):
556558
557559 # build table definition
558560 table = Table (
559- table_ref = TableReference .from_string (self .destination_project_dataset_table , project_id )
561+ table_ref = TableReference .from_string (self .destination_project_dataset_table , self . project_id )
560562 )
561563 table .external_data_configuration = external_config
562564 if self .labels :
@@ -573,15 +575,18 @@ def _create_empty_table(self):
573575
574576 self .log .info ("Creating external table: %s" , self .destination_project_dataset_table )
575577 self .hook .create_empty_table (
576- table_resource = table_obj_api_repr , project_id = project_id , location = self .location , exists_ok = True
578+ table_resource = table_obj_api_repr ,
579+ project_id = self .project_id ,
580+ location = self .location ,
581+ exists_ok = True ,
577582 )
578583 self .log .info ("External table created successfully: %s" , self .destination_project_dataset_table )
579584 return table_obj_api_repr
580585
581586 def _use_existing_table (self ):
582- destination_project , destination_dataset , destination_table = self .hook .split_tablename (
587+ self . project_id , destination_dataset , destination_table = self .hook .split_tablename (
583588 table_input = self .destination_project_dataset_table ,
584- default_project_id = self .hook . project_id or "" ,
589+ default_project_id = self .project_id or self . hook . project_id ,
585590 var_name = "destination_project_dataset_table" ,
586591 )
587592
@@ -601,7 +606,7 @@ def _use_existing_table(self):
601606 "autodetect" : self .autodetect ,
602607 "createDisposition" : self .create_disposition ,
603608 "destinationTable" : {
604- "projectId" : destination_project ,
609+ "projectId" : self . project_id ,
605610 "datasetId" : destination_dataset ,
606611 "tableId" : destination_table ,
607612 },
0 commit comments