Skip to content

Commit

Permalink
Fetch collections when api key is access limited
Browse files Browse the repository at this point in the history
When the rockset api key does not have full access to all workspaces the collection fetching fails.
  • Loading branch information
MaxBer committed Dec 12, 2023
1 parent 66ef942 commit 9c67460
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions redash/query_runner/rockset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def list_collections(self, workspace="commons"):

def collection_columns(self, workspace, collection):
response = self.query('DESCRIBE "{}"."{}" OPTION(max_field_depth=1)'.format(workspace, collection))
return sorted(set([x["field"][0] for x in response["results"]]))
if "results" in response:
return sorted(set([x["field"][0] for x in response["results"]]))

def query(self, sql):
query_path = "queries"
Expand Down Expand Up @@ -100,10 +101,12 @@ def _get_tables(self, schema):
for workspace in self.api.list_workspaces():
for collection in self.api.list_collections(workspace):
table_name = collection if workspace == "commons" else "{}.{}".format(workspace, collection)
schema[table_name] = {
"name": table_name,
"columns": self.api.collection_columns(workspace, collection),
}
columns = self.api.collection_columns(workspace, collection)

Check warning on line 104 in redash/query_runner/rockset.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/rockset.py#L104

Added line #L104 was not covered by tests
if columns:
schema[table_name] = {

Check warning on line 106 in redash/query_runner/rockset.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/rockset.py#L106

Added line #L106 was not covered by tests
"name": table_name,
"columns": columns,
}
return sorted(schema.values(), key=lambda x: x["name"])

def run_query(self, query, user):
Expand Down

0 comments on commit 9c67460

Please sign in to comment.