Skip to content

Commit fe7eb07

Browse files
committed
Don't choose a non-existent result set for csv viewing
If the `#select` resultset doesn't exist, arbitrarily choose the first result set when viewing csv results. This will almost certainly be the correct result set. In the future, we could offer a popup if there are multiple result sets available, but let's wait on that until someone actually asks for it.
1 parent c10da7f commit fe7eb07

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

extensions/ql-vscode/src/run-queries.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,14 @@ export class QueryEvaluationInfo {
352352
void showAndLogErrorMessage(`Failed to write CSV results to ${csvPath}`);
353353
}
354354
});
355+
const resultSet = await this.chooseResultSet(qs);
356+
if (!resultSet) {
357+
void showAndLogWarningMessage('Query has no result set.');
358+
return;
359+
}
355360
let nextOffset: number | undefined = 0;
356361
while (nextOffset !== undefined && !stopDecoding) {
357-
const chunk: DecodedBqrsChunk = await qs.cliServer.bqrsDecode(this.resultsPaths.resultsPath, SELECT_QUERY_NAME, {
362+
const chunk: DecodedBqrsChunk = await qs.cliServer.bqrsDecode(this.resultsPaths.resultsPath, resultSet, {
358363
pageSize: 100,
359364
offset: nextOffset,
360365
});
@@ -369,6 +374,22 @@ export class QueryEvaluationInfo {
369374
out.end();
370375
}
371376

377+
/**
378+
* Choose the name of the result set to run. If the `#select` set exists, use that. Otherwise,
379+
* arbitrarily choose the first set. Most of the time, this will be correct.
380+
*
381+
* If the query has no result sets, then return undefined.
382+
*/
383+
async chooseResultSet(qs: qsClient.QueryServerClient) {
384+
const resultSets = (await qs.cliServer.bqrsInfo(this.resultsPaths.resultsPath, 0))['result-sets'];
385+
if (!resultSets.length) {
386+
return undefined;
387+
}
388+
if (resultSets.find(r => r.name === SELECT_QUERY_NAME)) {
389+
return SELECT_QUERY_NAME;
390+
}
391+
return resultSets[0].name;
392+
}
372393
/**
373394
* Returns the path to the CSV alerts interpretation of this query results. If CSV results have
374395
* not yet been produced, this will return first create the CSV results and then return the path.

0 commit comments

Comments
 (0)