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 2019/08/13 01:56:57 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #5565: [AIRFLOW-4899] Fix get_dataset_list from bigquery hook to return next…

mik-laj commented on a change in pull request #5565: [AIRFLOW-4899] Fix get_dataset_list from bigquery hook to return next…
URL: https://github.com/apache/airflow/pull/5565#discussion_r313194987
 
 

 ##########
 File path: airflow/contrib/hooks/bigquery_hook.py
 ##########
 @@ -1707,14 +1711,30 @@ def get_datasets_list(self, project_id=None):
         """
         dataset_project_id = project_id if project_id else self.project_id
 
-        try:
-            datasets_list = self.service.datasets().list(
-                projectId=dataset_project_id).execute(num_retries=self.num_retries)['datasets']
-            self.log.info("Datasets List: %s", datasets_list)
+        optional_params = {'all': all_datasets}
+        if max_results:
+            optional_params['maxResults'] = max_results
 
-        except HttpError as err:
-            raise AirflowException(
-                'BigQuery job failed. Error was: {}'.format(err.content))
+        datasets_list = []
+        while True:
+            try:
+                datasets_list_resp = self.service.datasets().list(
+                    projectId=dataset_project_id,
+                    **optional_params).execute(num_retries=self.num_retries)
+
+            except HttpError as err:
+                raise AirflowException(
+                    'Get datasets list failed. Error was: {}'.format(err.content))
+
+            datasets_list.extend(datasets_list_resp['datasets'])
+            next_page_token = datasets_list_resp.get('nextPageToken', None)
+
+            if next_page_token:
+                optional_params['PageToken'] = next_page_token
 
 Review comment:
   What do you think about using the list_next function here? This will simplify the code.
   Example: 
   https://github.com/apache/airflow/blob/master/airflow/contrib/hooks/gcp_transfer_hook.py#L201-L206
   
   It's worth using `@GoogleCloudBaseHook.catch_http_exception` decorator to handle library exception.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services