Skip to content

Commit

Permalink
add column type info to query runners (re #152, #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
alison985 authored and Allen Short committed Dec 12, 2017
1 parent 25a4ff1 commit 259ba8a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions redash/query_runner/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_schema(self, get_stats=False):

schema = {}
query = """
SELECT table_schema, table_name, column_name
SELECT table_schema, table_name, column_name, data_type as column_type
FROM information_schema.columns
WHERE table_schema NOT IN ('information_schema')
"""
Expand All @@ -168,7 +168,7 @@ 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'])
schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')

return schema.values()

Expand Down
5 changes: 3 additions & 2 deletions redash/query_runner/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def _get_tables(self, schema):
query = """
SELECT col.table_schema,
col.table_name,
col.column_name
col.column_name,
col.column_type
FROM `information_schema`.`columns` col
WHERE col.table_schema NOT IN ('information_schema', 'performance_schema', 'mysql');
"""
Expand All @@ -136,7 +137,7 @@ def _get_tables(self, schema):
if table_name not in schema:
schema[table_name] = {'name': table_name, 'columns': []}

schema[table_name]['columns'].append(row['column_name'])
schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')

return schema.values()

Expand Down
4 changes: 2 additions & 2 deletions redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def _get_definitions(self, schema, query):
if table_name not in schema:
schema[table_name] = {'name': table_name, 'columns': []}

schema[table_name]['columns'].append(row['column_name'])
schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')

def _get_tables(self, schema):
query = """
SELECT table_schema, table_name, column_name
SELECT table_schema, table_name, column_name, udt_name as column_type
FROM information_schema.columns
WHERE table_schema NOT IN ('pg_catalog', 'information_schema');
"""
Expand Down
4 changes: 2 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
SELECT table_schema, table_name, column_name, data_type as column_type
FROM information_schema.columns
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
"""
Expand All @@ -104,7 +104,7 @@ 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'])
schema[table_name]['columns'].append(row['column_name'] + ' (' + row['column_type'] + ')')

return schema.values()

Expand Down

0 comments on commit 259ba8a

Please sign in to comment.