Skip to content

Commit ccb09da

Browse files
authored
Set labels on BQ jobs. (#1016)
1 parent 6469ea7 commit ccb09da

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

api/commands/run.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ export class Runner {
385385
actionResult.status === dataform.ActionResult.ExecutionStatus.RUNNING &&
386386
!this.cancelled
387387
) {
388-
const taskStatus = await this.executeTask(client, task, actionResult);
388+
const taskStatus = await this.executeTask(client, task, actionResult, {
389+
bigquery: { labels: action.actionDescriptor?.bigqueryLabels }
390+
});
389391
if (taskStatus === dataform.TaskResult.ExecutionStatus.FAILED) {
390392
actionResult.status = dataform.ActionResult.ExecutionStatus.FAILED;
391393
} else if (taskStatus === dataform.TaskResult.ExecutionStatus.CANCELLED) {
@@ -442,7 +444,8 @@ export class Runner {
442444
private async executeTask(
443445
client: dbadapters.IDbClient,
444446
task: dataform.IExecutionTask,
445-
parentAction: dataform.IActionResult
447+
parentAction: dataform.IActionResult,
448+
options: { bigquery: { labels: { [label: string]: string } } }
446449
): Promise<dataform.TaskResult.ExecutionStatus> {
447450
const timer = Timer.start();
448451
const taskResult: dataform.ITaskResult = {
@@ -458,7 +461,8 @@ export class Runner {
458461
() =>
459462
client.execute(task.statement, {
460463
onCancel: handleCancel => this.eEmitter.on(CANCEL_EVENT, handleCancel),
461-
rowLimit: 1
464+
rowLimit: 1,
465+
bigquery: options.bigquery
462466
}),
463467
task.type === "operation" ? 0 : this.graph.projectConfig.idempotentActionRetries || 0
464468
);

api/dbadapters/bigquery.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ export class BigQueryDbAdapter implements IDbAdapter {
6060
interactive?: boolean;
6161
rowLimit?: number;
6262
byteLimit?: number;
63+
bigquery?: {
64+
labels?: { [label: string]: string };
65+
};
6366
} = { interactive: false, rowLimit: 1000, byteLimit: 1024 * 1024 }
6467
): Promise<IExecutionResult> {
68+
if (options?.interactive && options?.bigquery?.labels) {
69+
throw new Error("BigQuery job labels may not be set for interactive queries.");
70+
}
6571
return this.pool
6672
.addSingleTask({
6773
generator: () =>
@@ -72,7 +78,8 @@ export class BigQueryDbAdapter implements IDbAdapter {
7278
options?.params,
7379
options?.rowLimit,
7480
options?.byteLimit,
75-
options?.onCancel
81+
options?.onCancel,
82+
options?.bigquery?.labels
7683
)
7784
})
7885
.promise();
@@ -419,7 +426,8 @@ DELETE \`${CACHED_STATE_TABLE_NAME}\` WHERE target IN (${allActions
419426
params?: { [name: string]: any },
420427
rowLimit?: number,
421428
byteLimit?: number,
422-
onCancel?: OnCancel
429+
onCancel?: OnCancel,
430+
labels?: { [label: string]: string }
423431
) {
424432
let isCancelled = false;
425433
onCancel?.(() => (isCancelled = true));
@@ -429,7 +437,8 @@ DELETE \`${CACHED_STATE_TABLE_NAME}\` WHERE target IN (${allActions
429437
useLegacySql: false,
430438
jobPrefix: "dataform-",
431439
query,
432-
params
440+
params,
441+
labels
433442
});
434443
const resultStream = job[0].getQueryResultsStream();
435444
return new Promise<IExecutionResult>((resolve, reject) => {

api/dbadapters/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface IDbClient {
2828
interactive?: boolean;
2929
rowLimit?: number;
3030
byteLimit?: number;
31+
bigquery?: {
32+
labels?: { [label: string]: string };
33+
};
3134
}
3235
): Promise<IExecutionResult>;
3336
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@blueprintjs/core": "^3.22.3",
1010
"@blueprintjs/icons": "^3.13.0",
1111
"@blueprintjs/select": "^3.8.0",
12-
"@google-cloud/bigquery": "^5.1.0",
12+
"@google-cloud/bigquery": "^5.3.0",
1313
"@google-cloud/storage": "^5.1.1",
1414
"@mapbox/rehype-prism": "^0.4.0",
1515
"@nivo/bar": "^0.61.1",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,10 @@
10901090
classnames "^2.2"
10911091
tslib "~1.10.0"
10921092

1093-
"@google-cloud/bigquery@^5.1.0":
1094-
version "5.1.0"
1095-
resolved "https://registry.yarnpkg.com/@google-cloud/bigquery/-/bigquery-5.1.0.tgz#d960fe3317ba3d5e69cccc60b6230747f54727ac"
1096-
integrity sha512-n5RSnMaYATkfbAS+lMKQ5ELmCiA6j0nRQzXfcNS8X5pqC9ZANQ9jVpTcXyKXjuRh8vAi0Pp4+Sv6NJaYsMhVIg==
1093+
"@google-cloud/bigquery@^5.3.0":
1094+
version "5.3.0"
1095+
resolved "https://registry.yarnpkg.com/@google-cloud/bigquery/-/bigquery-5.3.0.tgz#87db58ed6538d0be5dd146901ffd636d6b9fead0"
1096+
integrity sha512-IxHd7dWJygQgExdnwS7D8zMswe3VG5akKSLTkdl5ky1Xn6VHiXg30c8zK99jqRafA7kU023W/+L9F9zIQp1qiA==
10971097
dependencies:
10981098
"@google-cloud/common" "^3.1.0"
10991099
"@google-cloud/paginator" "^3.0.0"

0 commit comments

Comments
 (0)