You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/09/12 14:05:16 UTC

[GitHub] xnuinside commented on a change in pull request #3876: [AIRFLOW-2887] Add to BigQueryBaseCursor methods for insert (create empty) dataset

xnuinside commented on a change in pull request #3876: [AIRFLOW-2887] Add to BigQueryBaseCursor methods for insert (create empty) dataset
URL: https://github.com/apache/incubator-airflow/pull/3876#discussion_r217045125
 
 

 ##########
 File path: airflow/contrib/hooks/bigquery_hook.py
 ##########
 @@ -1354,6 +1354,64 @@ def run_grant_dataset_view_access(self,
                 view_project, view_dataset, view_table, source_project, source_dataset)
             return source_dataset_resource
 
+    def insert_dataset(self, dataset_id="", project_id="", dataset_resource=None):
+        """
+        Insert a dataset of Big query in your project:
+        https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets/insert
+        :param project_id: The name of the project where we want to insert a dataset.
+        Not need to provide, if projectId in dataset_resource.
+        :type project_id: str
+        :param dataset_id: The id of dataset. Not need to provide,
+        if datasetId in dataset_resource.
+        :type dataset_id: str
+        :param dataset_resource: Dataset resource that must be provided
+            with request body. More info:
+            https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets#resource
+        :param dataset_resource: dict
+        :return:
+        """
+
+        if dataset_resource:
+            _validate_value('dataset_resource', dataset_resource, dict)
+        else:
+            dataset_resource = {}
+
+        if "datasetReference" not in dataset_resource:
+            dataset_resource["datasetReference"] = {}
+
+        if not dataset_resource["datasetReference"].get("datasetId") and not dataset_id:
+            raise ValueError("{} not provided datasetId. Impossible to insert Dataset")
+
+        dataset_reference = [(dataset_id, "datasetId", ""),
+                             (project_id, "projectId", self.project_id)]
+        for param_tuple in dataset_reference:
+            param, param_name, param_default = param_tuple
+            if param_name not in dataset_resource['datasetReference']:
 
 Review comment:
   done - https://github.com/apache/incubator-airflow/blob/760ac9b7b06c873fce4dbf46ba4a368ae931ed10/airflow/contrib/hooks/bigquery_hook.py#L1393

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services