Skip to content

Commit 1591b3b

Browse files
authored
Merge pull request #7 from evidence-dev/empty-query-fails
Empty query fails
2 parents c11e822 + 7826f83 commit 1591b3b

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sqltools-bigquery-driver",
33
"displayName": "BigQuery Driver for SQLTools",
44
"description": "Run Queries and Explore your BigQuery Database in VSCode",
5-
"version": "0.0.2",
5+
"version": "0.0.3",
66
"engines": {
77
"vscode": "^1.42.0"
88
},
Binary file not shown.

src/ls/driver.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,20 @@ export default class BigQueryDriver extends AbstractDriver<DriverLib, DriverOpti
9696

9797
const [rows] = await bigquery.query(options);
9898
const standardizedRows = await standardizeResult(rows);
99+
if (!Array.isArray(rows) || !rows.length) {
100+
resultsAgg.push({
101+
cols: ['No rows returned'],
102+
connId: this.getId(),
103+
messages: [{ date: new Date(), message: `Query executed successfully but no data was returned` }],
104+
results: [],
105+
// back to string
106+
query: query[0],
107+
requestId: opt.requestId,
108+
resultId: generateId(),
109+
})
110+
} else {
99111
resultsAgg.push({
100-
cols: Object.keys(standardizedRows[0]),
112+
cols: standardizedRows && standardizedRows.length && Object.keys(standardizedRows[0]),
101113
connId: this.getId(),
102114
messages: [{ date: new Date(), message: `Query executed successfully` }],
103115
results: standardizedRows,
@@ -106,7 +118,7 @@ export default class BigQueryDriver extends AbstractDriver<DriverLib, DriverOpti
106118
requestId: opt.requestId,
107119
resultId: generateId(),
108120
});
109-
121+
}
110122
return resultsAgg;
111123
}
112124

src/ls/queries.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ const fetchTablesAndViews = (
4545
type: ContextValue,
4646
tableType: string
4747
): IBaseQueries['fetchTables'] => queryFactory`
48-
-- check if there are any tables or views
49-
IF (
50-
SELECT COUNT(*)
51-
FROM ${p=>p.schema}.INFORMATION_SCHEMA.TABLES
52-
WHERE table_type IN ${tableType}
53-
) > 0
54-
-- if there are, return them
55-
THEN
5648
SELECT
5749
table_name AS label,
5850
table_name AS table,
@@ -61,10 +53,6 @@ THEN
6153
FROM ${p=>p.schema}.INFORMATION_SCHEMA.TABLES
6254
WHERE table_type IN ${tableType}
6355
ORDER BY table_name;
64-
-- otherwise return null
65-
ELSE
66-
SELECT NULL;
67-
END IF;
6856
`;
6957

7058
const fetchTables: IBaseQueries['fetchTables'] = fetchTablesAndViews(ContextValue.TABLE,`('BASE TABLE', 'EXTERNAL')`);

src/ls/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const standardizeResult = async (result: any[]): Promise<any[]> => {
66
for (const [key, value] of Object.entries(row)) {
77
if (typeof value === 'object') {
88
if (value) {
9-
if (value.value) {
10-
standardized[key] = value.value;
9+
if (value['value']) {
10+
standardized[key] = value['value'];
1111
} else {
1212
//This is a bigQuery specific workaround for https://github.com/evidence-dev/evidence/issues/792
1313
try {

0 commit comments

Comments
 (0)