mobuchowski commented on code in PR #31293:
URL: https://github.com/apache/airflow/pull/31293#discussion_r1200452737


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -1177,14 +1178,56 @@ def execute(self, context: Context):
             ]
         else:
             raise AirflowException(f"argument 'sql' of type {type(str)} is 
neither a string nor an iterable")
-        context["task_instance"].xcom_push(key="job_id", value=job_id)
+        context["task_instance"].xcom_push(key="job_id", value=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):
+        try:
+            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
+        except ImportError:
+            return None
+
+        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:
+                stats = 
BigQueryDatasetsProvider(client=client).get_facets(job_id=job_id)
+                print(stats)
+                for input in stats.inputs:
+                    input = input.to_openlineage_dataset()
+                    inputs[input.name] = input
+                if stats.output:
+                    output = stats.output.to_openlineage_dataset()
+                    outputs[output.name] = output
+                for key, value in stats.run_facets.items():
+                    run_facets[key] = value

Review Comment:
   Errors are properties of a particular run of a job, not job itself. One run 
can succeed, and second not. 



-- 
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]

Reply via email to