Skip to content

Commit 5e8915a

Browse files
BigQuery: show column description(comment) on Schema Browser (#7538)
* BigQuery: add column description to Schema Browser * fix restyled prettier error * Remove column-description
1 parent b8ebf49 commit 5e8915a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

client/app/components/queries/SchemaBrowser.jsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ function SchemaItem({ item, expanded, onToggle, onSelect, ...props }) {
5959
mouseEnterDelay={0}
6060
mouseLeaveDelay={0}
6161
placement="topRight"
62-
arrowPointAtCenter>
63-
<PlainButton className="copy-to-editor" onClick={e => handleSelect(e, item.name)}>
62+
arrowPointAtCenter
63+
>
64+
<PlainButton className="copy-to-editor" onClick={(e) => handleSelect(e, item.name)}>
6465
<i className="fa fa-angle-double-right" aria-hidden="true" />
6566
</PlainButton>
6667
</Tooltip>
@@ -70,16 +71,22 @@ function SchemaItem({ item, expanded, onToggle, onSelect, ...props }) {
7071
{item.loading ? (
7172
<div className="table-open">Loading...</div>
7273
) : (
73-
map(item.columns, column => {
74+
map(item.columns, (column) => {
7475
const columnName = get(column, "name");
7576
const columnType = get(column, "type");
77+
const columnDescription = get(column, "description");
7678
return (
7779
<Tooltip
78-
title="Insert column name into query text"
80+
title={"Insert column name into query text" + (columnDescription ? "\n" + columnDescription : "")}
7981
mouseEnterDelay={0}
8082
mouseLeaveDelay={0}
81-
placement="rightTop">
82-
<PlainButton key={columnName} className="table-open-item" onClick={e => handleSelect(e, columnName)}>
83+
placement="rightTop"
84+
>
85+
<PlainButton
86+
key={columnName}
87+
className="table-open-item"
88+
onClick={(e) => handleSelect(e, columnName)}
89+
>
8390
<div>
8491
{columnName} {columnType && <span className="column-type">{columnType}</span>}
8592
</div>
@@ -168,7 +175,7 @@ export function SchemaList({ loading, schema, expandedFlags, onTableExpand, onIt
168175
}
169176

170177
export function applyFilterOnSchema(schema, filterString) {
171-
const filters = filter(filterString.toLowerCase().split(/\s+/), s => s.length > 0);
178+
const filters = filter(filterString.toLowerCase().split(/\s+/), (s) => s.length > 0);
172179

173180
// Empty string: return original schema
174181
if (filters.length === 0) {
@@ -181,21 +188,21 @@ export function applyFilterOnSchema(schema, filterString) {
181188
const columnFilter = filters[0];
182189
return filter(
183190
schema,
184-
item =>
191+
(item) =>
185192
includes(item.name.toLowerCase(), nameFilter) ||
186-
some(item.columns, column => includes(get(column, "name").toLowerCase(), columnFilter))
193+
some(item.columns, (column) => includes(get(column, "name").toLowerCase(), columnFilter))
187194
);
188195
}
189196

190197
// Two (or more) words: first matches table, seconds matches column
191198
const nameFilter = filters[0];
192199
const columnFilter = filters[1];
193200
return filter(
194-
map(schema, item => {
201+
map(schema, (item) => {
195202
if (includes(item.name.toLowerCase(), nameFilter)) {
196203
item = {
197204
...item,
198-
columns: filter(item.columns, column => includes(get(column, "name").toLowerCase(), columnFilter)),
205+
columns: filter(item.columns, (column) => includes(get(column, "name").toLowerCase(), columnFilter)),
199206
};
200207
return item.columns.length > 0 ? item : null;
201208
}
@@ -243,7 +250,7 @@ export default function SchemaBrowser({
243250
placeholder="Search schema..."
244251
aria-label="Search schema"
245252
disabled={schema.length === 0}
246-
onChange={event => handleFilterChange(event.target.value)}
253+
onChange={(event) => handleFilterChange(event.target.value)}
247254
/>
248255

249256
<Tooltip title="Refresh Schema">

redash/query_runner/big_query.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def get_schema(self, get_stats=False):
304304
datasets = self._get_project_datasets(project_id)
305305

306306
query_base = """
307-
SELECT table_schema, table_name, field_path, data_type
307+
SELECT table_schema, table_name, field_path, data_type, description
308308
FROM `{dataset_id}`.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS
309309
WHERE table_schema NOT IN ('information_schema')
310310
"""
@@ -329,7 +329,13 @@ def get_schema(self, get_stats=False):
329329
table_name = "{0}.{1}".format(row["table_schema"], row["table_name"])
330330
if table_name not in schema:
331331
schema[table_name] = {"name": table_name, "columns": []}
332-
schema[table_name]["columns"].append({"name": row["field_path"], "type": row["data_type"]})
332+
schema[table_name]["columns"].append(
333+
{
334+
"name": row["field_path"],
335+
"type": row["data_type"],
336+
"description": row["description"],
337+
}
338+
)
333339

334340
return list(schema.values())
335341

0 commit comments

Comments
 (0)