turbaszek commented on code in PR #24416:
URL: https://github.com/apache/airflow/pull/24416#discussion_r897322128
##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2167,16 +2156,30 @@ def execute(self, context: Any):
f"Or, if you want to reattach in this scenario add
{job.state} to `reattach_states`"
)
- if "query" in job.to_api_repr()["configuration"]:
- if "destinationTable" in
job.to_api_repr()["configuration"]["query"]:
- table =
job.to_api_repr()["configuration"]["query"]["destinationTable"]
- BigQueryTableLink.persist(
- context=context,
- task_instance=self,
- dataset_id=table["datasetId"],
- project_id=table["projectId"],
- table_id=table["tableId"],
- )
+ job_types = {
+ LoadJob._JOB_TYPE: ["sourceTable", "destinationTable"],
+ CopyJob._JOB_TYPE: ["sourceTable", "destinationTable"],
+ ExtractJob._JOB_TYPE: ["sourceTable"],
+ QueryJob._JOB_TYPE: ["destinationTable"],
+ }
+
+ if self.project_id:
+ for job_type, tables_prop in job_types.items():
+ if job_type in job.to_api_repr()["configuration"]:
+ for table_prop in tables_prop:
+ if table_prop in
job.to_api_repr()["configuration"][job_type]:
+ table =
job.to_api_repr()["configuration"][job_type][table_prop]
Review Comment:
Do we need to write `job.to_api_repr()["configuration"]` 3 times? Could you
please introduce a variable for this value?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]