-
Notifications
You must be signed in to change notification settings - Fork 202
Allow exporting of results for non-alert queries #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ import * as qsClient from './queryserver-client'; | |
import { isQuickQueryPath } from './quick-query'; | ||
import { compileDatabaseUpgradeSequence, hasNondestructiveUpgradeCapabilities, upgradeDatabaseExplicit } from './upgrades'; | ||
import { ensureMetadataIsComplete } from './query-results'; | ||
import { SELECT_QUERY_NAME } from './contextual/locationFinder'; | ||
import { DecodedBqrsChunk } from './pure/bqrs-cli-types'; | ||
|
||
/** | ||
* run-queries.ts | ||
|
@@ -216,6 +218,29 @@ export class QueryInfo { | |
return this.dilPath; | ||
} | ||
|
||
async exportCsvResults(qs: qsClient.QueryServerClient, csvPath: string, onFinish: () => void): Promise<void> { | ||
let stopDecoding = false; | ||
const out = fs.createWriteStream(csvPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the csv file already exists, then maybe no need to recreate it? Though if the operation is fast, not a big deal either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is already not being called if the file already exists (see this line) |
||
out.on('finish', onFinish); | ||
out.on('error', () => { | ||
if (!stopDecoding) { | ||
stopDecoding = true; | ||
void showAndLogErrorMessage(`Failed to write CSV results to ${csvPath}`); | ||
} | ||
}); | ||
let nextOffset: number | undefined = 0; | ||
while (nextOffset !== undefined && !stopDecoding) { | ||
const chunk: DecodedBqrsChunk = await qs.cliServer.bqrsDecode(this.resultsPaths.resultsPath, SELECT_QUERY_NAME, { | ||
pageSize: 100, | ||
offset: nextOffset, | ||
}); | ||
for (const tuple of chunk.tuples) | ||
out.write(tuple.join(',') + '\n'); | ||
nextOffset = chunk.next; | ||
} | ||
out.end(); | ||
} | ||
|
||
async ensureCsvProduced(qs: qsClient.QueryServerClient): Promise<string> { | ||
if (await this.hasCsv()) { | ||
return this.csvPath; | ||
|
Uh oh!
There was an error while loading. Please reload this page.