MCPcopy Create free account
hub / github.com/dataform-co/dataform / createQueryJob

Method createQueryJob

cli/api/dbadapters/bigquery.ts:401–509  ·  view source on GitHub ↗
(
    query: string,
    params?: { [name: string]: any },
    rowLimit?: number,
    byteLimit?: number,
    onCancel?: OnCancel,
    labels?: { [label: string]: string },
    location?: string,
    jobPrefix?: string,
    dryRun?: boolean,
    reservation?: string
  )

Source from the content-addressed store, hash-verified

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

Callers 1

executeMethod · 0.95

Calls 8

getClientMethod · 0.95
prepareQueryOptionsMethod · 0.95
pushMethod · 0.95
retryFunction · 0.90
coerceAsErrorFunction · 0.90
createBigQueryErrorFunction · 0.85
endMethod · 0.80
getMetadataMethod · 0.80

Tested by

no test coverage detected