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

[Athena] Fix: missing databases (apply pagination) #2503

Merged
merged 6 commits into from
Dec 24, 2018
Merged
Changes from 3 commits
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
10 changes: 6 additions & 4 deletions redash/query_runner/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,20 @@ def __get_schema_from_glue(self):
region_name=self.configuration['region']
)
schema = {}
paginator = client.get_paginator('get_tables')
database_paginator = client.get_paginator('get_databases')
table_paginator = client.get_paginator('get_tables')
databases = (database for databases in database_paginator.paginate()
for database in databases['DatabaseList'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something in these 2 lines doesn't look right. are you sure this is what you wanted?

Copy link
Contributor Author

@ialeinikov ialeinikov May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to paginate over both databases and tables.
A database paginator returns a list of lists, in the l#130 I flatten it inside a generator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would suffice to just indent the double for-loops differently to make it more clear?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the change into two for-loops. But don't we need to remove lines 130-131 now?


for database in client.get_databases()['DatabaseList']:
iterator = paginator.paginate(DatabaseName=database['Name'])
for database in databases:
iterator = table_paginator.paginate(DatabaseName=database['Name'])
for table in iterator.search('TableList[]'):
table_name = '%s.%s' % (database['Name'], table['Name'])
if table_name not in schema:
column = [columns['Name'] for columns in table['StorageDescriptor']['Columns']]
schema[table_name] = {'name': table_name, 'columns': column}
for partition in table['PartitionKeys']:
schema[table_name]['columns'].append(partition['Name'])

return schema.values()

def get_schema(self, get_stats=False):
Expand Down