Skip to content

Commit 33170e7

Browse files
Overhauled BigQuery client, project and region functionality to provide a better user experience
1 parent 9931281 commit 33170e7

File tree

4 files changed

+434
-8
lines changed

4 files changed

+434
-8
lines changed

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@
147147
"command": "vscode-dataform-tools.selectWorkspaceFolder",
148148
"category": "Dataform",
149149
"title": "Select workspace folder"
150+
},
151+
{
152+
"command": "vscode-dataform-tools.showBigQueryConfig",
153+
"category": "Dataform",
154+
"title": "Show BigQuery configuration"
150155
}
151156
],
152157
"languages": [
@@ -300,7 +305,13 @@
300305
"vscode-dataform-tools.gcpProjectId": {
301306
"type": "string",
302307
"default": null,
303-
"markdownDescription": "GCP project ID to use for BigQuery queries. When not provided, the project ID will be inferred from your enviroment typically same as `gcloud config list project`",
308+
"markdownDescription": "GCP project ID to use for BigQuery queries. When not provided, the project ID will be resolved in the following order: 1) workflow_settings.yaml (defaultProject), 2) Environment variables (GOOGLE_CLOUD_PROJECT, etc.), 3) gcloud config, 4) This setting",
309+
"pattern": "^[a-z0-9-]+$"
310+
},
311+
"vscode-dataform-tools.gcpRegion": {
312+
"type": "string",
313+
"default": null,
314+
"markdownDescription": "GCP region/location to use for BigQuery queries (e.g., 'us-central1', 'europe-west2'). When not provided, the region will be resolved in the following order: 1) workflow_settings.yaml (defaultLocation), 2) Environment variables (GOOGLE_CLOUD_REGION, etc.), 3) gcloud config, 4) This setting. See https://cloud.google.com/bigquery/docs/locations for supported values.",
304315
"pattern": "^[a-z0-9-]+$"
305316
}
306317
}
@@ -355,4 +366,4 @@
355366
"react-select": "^5.10.0",
356367
"typescript": "^5.7.3"
357368
}
358-
}
369+
}

src/bigqueryClient.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as vscode from 'vscode';
22
import { BigQuery } from '@google-cloud/bigquery';
3+
import { resolveBigQueryConfig, getConfigSourceSummary } from './bigqueryConfigResolver';
4+
import { logger } from './logger';
35

46
let bigquery: BigQuery | undefined;
57
let authenticationCheckInterval: NodeJS.Timeout | undefined;
@@ -8,18 +10,37 @@ let isAuthenticated: boolean = false;
810

911
export async function createBigQueryClient(): Promise<string | undefined> {
1012
try {
11-
const projectId = vscode.workspace.getConfiguration('vscode-dataform-tools').get('gcpProjectId');
12-
// default state will be projectId as null and the projectId will be inferred from what the user has set using gcloud cli
13-
// @ts-ignore
14-
bigquery = new BigQuery({ projectId });
13+
const { config, sources } = await resolveBigQueryConfig();
14+
const sourceSummary = getConfigSourceSummary(sources);
15+
16+
logger.info(`Creating BigQuery client with config: ${JSON.stringify(config)}`);
17+
logger.info(`Configuration sources: ${sourceSummary}`);
18+
19+
// Create BigQuery client with resolved config
20+
const clientOptions: any = {};
21+
if (config.projectId) {
22+
clientOptions.projectId = config.projectId;
23+
}
24+
if (config.location) {
25+
clientOptions.location = config.location;
26+
}
27+
28+
bigquery = new BigQuery(clientOptions);
1529
await verifyAuthentication();
16-
vscode.window.showInformationMessage('BigQuery client created successfully.');
30+
31+
const statusMessage = config.projectId
32+
? `BigQuery client created successfully for project: ${config.projectId}${config.location ? ` in ${config.location}` : ''}`
33+
: 'BigQuery client created successfully with default project';
34+
35+
vscode.window.showInformationMessage(statusMessage);
36+
logger.info(`${statusMessage} (${sourceSummary})`);
1737
return undefined;
1838
} catch (error: any) {
1939
bigquery = undefined;
2040
isAuthenticated = false;
2141
const errorMessage = `Error creating BigQuery client: ${error?.message}`;
2242
vscode.window.showErrorMessage(errorMessage);
43+
logger.error(errorMessage, error);
2344
return errorMessage;
2445
}
2546
}
@@ -88,4 +109,11 @@ export async function handleBigQueryError(error: any): Promise<void> {
88109
await createBigQueryClient();
89110
}
90111
throw error;
112+
}
113+
114+
/**
115+
* Gets the current BigQuery configuration for debugging/display purposes
116+
*/
117+
export async function getCurrentBigQueryConfig() {
118+
return await resolveBigQueryConfig();
91119
}

0 commit comments

Comments
 (0)