You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by tu...@apache.org on 2020/06/30 12:01:08 UTC

[airflow] branch master updated: Add template_ext to BigQueryInsertJobOperator (#9568)

This is an automated email from the ASF dual-hosted git repository.

turbaszek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new e33f1a1  Add template_ext to BigQueryInsertJobOperator (#9568)
e33f1a1 is described below

commit e33f1a12d72ac234e4897f44b326a332acf85901
Author: Tomek Urbaszek <tu...@gmail.com>
AuthorDate: Tue Jun 30 14:00:44 2020 +0200

    Add template_ext to BigQueryInsertJobOperator (#9568)
---
 airflow/providers/google/cloud/operators/bigquery.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/airflow/providers/google/cloud/operators/bigquery.py b/airflow/providers/google/cloud/operators/bigquery.py
index 5d633f9..ea02ca4 100644
--- a/airflow/providers/google/cloud/operators/bigquery.py
+++ b/airflow/providers/google/cloud/operators/bigquery.py
@@ -1664,6 +1664,7 @@ class BigQueryInsertJobOperator(BaseOperator):
     """
 
     template_fields = ("configuration", "job_id")
+    template_ext = (".json", )
     ui_color = BigQueryUIColors.QUERY.value
 
     def __init__(
@@ -1685,6 +1686,12 @@ class BigQueryInsertJobOperator(BaseOperator):
         self.gcp_conn_id = gcp_conn_id
         self.delegate_to = delegate_to
 
+    def prepare_template(self) -> None:
+        # If .json is passed then we have to read the file
+        if isinstance(self.configuration, str) and self.configuration.endswith('.json'):
+            with open(self.configuration, 'r') as file:
+                self.configuration = json.loads(file.read())
+
     def execute(self, context: Any):
         hook = BigQueryHook(
             gcp_conn_id=self.gcp_conn_id,