From 5a3726a82f07470ee09a444c13d6e75a87b6994b Mon Sep 17 00:00:00 2001 From: Alison Date: Fri, 28 Jul 2017 06:36:19 -0500 Subject: [PATCH] add column type info to query runners (re #152, #23) --- redash/query_runner/athena.py | 4 ++-- redash/query_runner/mysql.py | 5 +++-- redash/query_runner/pg.py | 4 ++-- redash/query_runner/presto.py | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/redash/query_runner/athena.py b/redash/query_runner/athena.py index 8e8ba8e67b..83bed0f884 100644 --- a/redash/query_runner/athena.py +++ b/redash/query_runner/athena.py @@ -156,7 +156,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') """ @@ -170,7 +170,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() diff --git a/redash/query_runner/mysql.py b/redash/query_runner/mysql.py index a2187d20c8..d4700d85c1 100644 --- a/redash/query_runner/mysql.py +++ b/redash/query_runner/mysql.py @@ -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'); """ @@ -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() diff --git a/redash/query_runner/pg.py b/redash/query_runner/pg.py index baee18be51..be48dcc7c4 100644 --- a/redash/query_runner/pg.py +++ b/redash/query_runner/pg.py @@ -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'); """ diff --git a/redash/query_runner/presto.py b/redash/query_runner/presto.py index d8b8a728ef..509e5b9b56 100644 --- a/redash/query_runner/presto.py +++ b/redash/query_runner/presto.py @@ -84,7 +84,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') """ @@ -102,7 +102,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()