(
query: string,
params?: { [name: string]: any },
rowLimit?: number,
byteLimit?: number,
onCancel?: OnCancel,
labels?: { [label: string]: string },
location?: string,
jobPrefix?: string,
dryRun?: boolean,
reservation?: string
)
| 399 | } |
| 400 | |
| 401 | private async createQueryJob( |
| 402 | query: string, |
| 403 | params?: { [name: string]: any }, |
| 404 | rowLimit?: number, |
| 405 | byteLimit?: number, |
| 406 | onCancel?: OnCancel, |
| 407 | labels?: { [label: string]: string }, |
| 408 | location?: string, |
| 409 | jobPrefix?: string, |
| 410 | dryRun?: boolean, |
| 411 | reservation?: string |
| 412 | ): Promise<IExecutionResult> { |
| 413 | let isCancelled = false; |
| 414 | onCancel?.(() => (isCancelled = true)); |
| 415 | |
| 416 | return retry( |
| 417 | async () => { |
| 418 | try { |
| 419 | const job = await this.getClient().createQueryJob( |
| 420 | this.prepareQueryOptions( |
| 421 | query, |
| 422 | rowLimit, |
| 423 | { |
| 424 | labels, |
| 425 | location, |
| 426 | jobPrefix, |
| 427 | dryRun, |
| 428 | reservation |
| 429 | }, |
| 430 | params |
| 431 | ) as any |
| 432 | ); |
| 433 | const resultStream = job[0].getQueryResultsStream(); |
| 434 | return new Promise<IExecutionResult>((resolve, reject) => { |
| 435 | if (isCancelled) { |
| 436 | resultStream.end(); |
| 437 | reject(new Error("Query cancelled.")); |
| 438 | return; |
| 439 | } |
| 440 | onCancel?.(() => { |
| 441 | resultStream.end(); |
| 442 | reject(new Error("Query cancelled.")); |
| 443 | }); |
| 444 | |
| 445 | const results = new LimitedResultSet({ |
| 446 | rowLimit, |
| 447 | byteLimit |
| 448 | }); |
| 449 | resultStream |
| 450 | .on("error", async (e: IBigQueryError) => { |
| 451 | // Dry run queries against BigQuery done by this package eagerly fail with |
| 452 | // "Not found: job". This is a workaround to avoid that. |
| 453 | // Example: https://github.com/googleapis/python-bigquery/issues/118. |
| 454 | if (dryRun && e.message?.includes("Not found: Job")) { |
| 455 | resolve({ rows: [], metadata: {} }); |
| 456 | return; |
| 457 | } |
| 458 |
no test coverage detected