Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get BigQuery datasets in over 50 datasets environment #5667

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix get bigquery datasets case over than 50 datasets
  • Loading branch information
katsugeneration committed Dec 6, 2021
commit a649757177544877629706a6be65a3cd9d41a074
20 changes: 17 additions & 3 deletions redash/query_runner/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,27 @@ def _get_columns_schema_column(self, column):

return columns

def _get_project_datasets(self, project_id):
result = []
service = self._get_bigquery_service()

datasets = service.datasets().list(projectId=project_id).execute()
result.extend(datasets.get("datasets", []))
nextPageToken=datasets.get('nextPageToken', None)

while nextPageToken is not None:
datasets = service.datasets().list(projectId=project_id, pageToken=nextPageToken).execute()
result.extend(datasets.get("datasets", []))
nextPageToken=datasets.get('nextPageToken', None)

return result

def get_schema(self, get_stats=False):
if not self.configuration.get("loadSchema", False):
return []

service = self._get_bigquery_service()
project_id = self._get_project_id()
datasets = service.datasets().list(projectId=project_id).execute()
datasets = self._get_project_datasets(project_id)

query_base = """
SELECT table_schema, table_name, column_name
Expand All @@ -283,7 +297,7 @@ def get_schema(self, get_stats=False):

schema = {}
queries = []
for dataset in datasets.get("datasets", []):
for dataset in datasets:
dataset_id = dataset["datasetReference"]["datasetId"]
query = query_base.format(dataset_id=dataset_id)
queries.append(query)
Expand Down