Skip to content

Commit

Permalink
add partition key marker to partition columns
Browse files Browse the repository at this point in the history
getredash#185

added to the front of the column name so they are in a consistent
ordinal position for each table

tests pass
  • Loading branch information
alison985 committed Aug 14, 2017
1 parent 84bbae9 commit f4d5830
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions redash/query_runner/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(self, configuration):
def get_schema(self, get_stats=False):
schema = {}
query = """
SELECT table_schema, table_name, column_name, data_type as column_type
SELECT table_schema, table_name, column_name, data_type as column_type, extra_info
FROM information_schema.columns
WHERE table_schema NOT IN ('information_schema')
"""
Expand All @@ -143,7 +143,12 @@ def get_schema(self, get_stats=False):
table_name = '{0}.{1}'.format(row['table_schema'], row['table_name'])
if table_name not in schema:
schema[table_name] = {'name': table_name, 'columns': []}
schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')

if row['extra_info'] == 'partition key':
schema[table_name]['columns'].append('[P] ' + row['column_name'] + ' (' + row['column_type'] + ')')
else:
schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')


return schema.values()

Expand Down
7 changes: 5 additions & 2 deletions redash/query_runner/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, configuration):
def get_schema(self, get_stats=False):
schema = {}
query = """
SELECT table_schema, table_name, column_name, data_type as column_type
SELECT table_schema, table_name, column_name, data_type as column_type, extra_info
FROM information_schema.columns
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
"""
Expand All @@ -104,7 +104,10 @@ def get_schema(self, get_stats=False):
if table_name not in schema:
schema[table_name] = {'name': table_name, 'columns': []}

schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')
if row['extra_info'] == 'partition key':
schema[table_name]['columns'].append('[P] ' + row['column_name'] + ' (' + row['column_type'] + ')')
else:
schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')

return schema.values()

Expand Down

0 comments on commit f4d5830

Please sign in to comment.