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
Also:

Fix bug 1529388 - don't include column type in autocomplete results. (#832)
  • Loading branch information
alison985 authored and Allen Short committed Mar 26, 2019
1 parent f8fd885 commit 5b7f4eb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions client/app/components/keywordBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function buildKeywordsFromSchema(schema) {
});
tableColumnKeywords[table.name] = buildTableColumnKeywords(table);
table.columns.forEach((c) => {
if (c.length > 0) {
c = c.split('(')[0];
}
columnKeywords[c] = 'Column';
});
});
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/queries/schema-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function SchemaBrowserCtrl($rootScope, $scope) {
};

this.itemSelected = ($event, hierarchy) => {
$rootScope.$broadcast('query-editor.command', 'paste', hierarchy.join('.'));
$rootScope.$broadcast('query-editor.command', 'paste', hierarchy.join('.').split('(')[0]);
$event.preventDefault();
$event.stopPropagation();
};
Expand Down
4 changes: 2 additions & 2 deletions redash/query_runner/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,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 @@ -163,7 +163,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 @@ -106,7 +106,8 @@ def _get_tables(self, schema):
query = """
SELECT col.table_schema as table_schema,
col.table_name as table_name,
col.column_name as column_name
col.column_name as column_name,
col.column_type as column_type
FROM `information_schema`.`columns` col
WHERE col.table_schema NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys');
"""
Expand All @@ -127,7 +128,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
5 changes: 4 additions & 1 deletion redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ 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):
'''
Expand All @@ -149,6 +149,7 @@ def _get_tables(self, schema):
query = """
SELECT s.nspname as table_schema,
c.relname as table_name,
t.typname as column_type,
a.attname as column_name
FROM pg_class c
JOIN pg_namespace s
Expand All @@ -158,6 +159,8 @@ def _get_tables(self, schema):
ON a.attrelid = c.oid
AND a.attnum > 0
AND NOT a.attisdropped
JOIN pg_type t
ON a.atttypid = t.oid
WHERE c.relkind IN ('r', 'v', 'm', 'f', 'p')
"""

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 @@ -78,7 +78,7 @@ def type(cls):
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 @@ -96,7 +96,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 5b7f4eb

Please sign in to comment.