mobuchowski commented on code in PR #31293:
URL: https://github.com/apache/airflow/pull/31293#discussion_r1269284476
##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -1197,19 +1198,80 @@ def execute(self, context: Context):
else:
raise AirflowException(f"argument 'sql' of type {type(str)} is
neither a string nor an iterable")
job_id_params = {
- "job_id": job_id,
+ "job_id": self.job_id,
"project_id": self.hook.project_id,
"location": self.location if self.location else "US",
}
context["task_instance"].xcom_push(key="job_id_params",
value=job_id_params)
- return job_id
+ return self.job_id
def on_kill(self) -> None:
super().on_kill()
if self.hook is not None:
self.log.info("Cancelling running query")
self.hook.cancel_job(self.hook.running_job_id)
+ def get_openlineage_facets_on_complete(self, task_instance):
+ """
+ Retrieve OpenLineage data for a COMPLETE BigQuery job.
+
+ This method retrieves statistics for the specified job_ids using the
BigQueryDatasetsProvider.
+ It calls BigQuery API, retrieving input and output dataset info from
it, as well as run-level
+ usage statistics.
+
+ Run facets should contain:
+ - ExternalQueryRunFacet
+ - BigQueryJobRunFacet
+
+ Job facets should contain:
+ - SqlJobFacet
+
+ Input datasets should contain facets:
+ - DataSourceDatasetFacet
+ - SchemaDatasetFacet
+
+ Output datasets should contain facets:
+ - DataSourceDatasetFacet
+ - SchemaDatasetFacet
+ - OutputStatisticsOutputDatasetFacet
+ """
+ from openlineage.client.facet import SqlJobFacet
+ from openlineage.common.provider.bigquery import
BigQueryDatasetsProvider
+
+ from airflow.providers.openlineage.extractors import OperatorLineage
+ from airflow.providers.openlineage.utils.utils import normalize_sql
+
+ if not self.job_id:
+ return OperatorLineage()
+
+ client = self.hook.get_client(project_id=self.hook.project_id)
+ if isinstance(self.job_id, list):
+ inputs, outputs, run_facets = {}, {}, {}
+ for job_id in self.job_id:
Review Comment:
Done.
--
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]