Skip to content
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

feat: add support for TPC Universes #1333

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/package.json
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@google-cloud/bigquery": "^7.4.0",
"@google-cloud/storage": "^7.0.0",
"google-auth-library": "^9.0.0",
"google-auth-library": "^9.6.0",
"readline-promise": "^1.0.4",
"yargs": "^17.0.0"
},
Expand Down
25 changes: 24 additions & 1 deletion src/bigquery.ts
Expand Up @@ -227,6 +227,12 @@
* Defaults to `bigquery.googleapis.com`.
*/
apiEndpoint?: string;

/**
* The Trusted Cloud Domain (TPC) DNS of the service used to make requests.
* Defaults to `googleapis.com`.
*/
universeDomain?: string;
}

export interface IntegerTypeCastOptions {
Expand Down Expand Up @@ -311,27 +317,35 @@
*/
export class BigQuery extends Service {
location?: string;
private _universeDomain: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use:

Suggested change
private _universeDomain: string;
#universeDomain: string;

To make it truly private.


createQueryStream(options?: Query | string): ResourceStream<RowMetadata> {

Check warning on line 322 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<RowMetadata>({}, () => {});
}

getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset> {

Check warning on line 327 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Dataset>({}, () => {});
}

getJobsStream(options?: GetJobsOptions): ResourceStream<Job> {

Check warning on line 332 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Job>({}, () => {});
}

constructor(options: BigQueryOptions = {}) {
let apiEndpoint = 'https://bigquery.googleapis.com';
let universeDomain = 'googleapis.com';
const servicePath = 'bigquery';

if (options.universeDomain) {
universeDomain = BigQuery.sanitizeDomain(options.universeDomain);
}

const EMULATOR_HOST = process.env.BIGQUERY_EMULATOR_HOST;

let apiEndpoint = `https://${servicePath}.${universeDomain}`;
alvarowolfx marked this conversation as resolved.
Show resolved Hide resolved

if (typeof EMULATOR_HOST === 'string') {
apiEndpoint = BigQuery.sanitizeEndpoint(EMULATOR_HOST);
}
Expand Down Expand Up @@ -361,6 +375,7 @@

super(config, options);

this._universeDomain = universeDomain;
this.location = options.location;
/**
* Run a query scoped to your project as a readable object stream.
Expand Down Expand Up @@ -473,10 +488,18 @@
});
}

get universeDomain() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: In the future we may want to check via Auth’s universe domain getter; which is async.

return this._universeDomain;
}

private static sanitizeEndpoint(url: string) {
if (!PROTOCOL_REGEX.test(url)) {
url = `https://${url}`;
}
return this.sanitizeDomain(url);
}

private static sanitizeDomain(url: string) {
return url.replace(/\/+$/, ''); // Remove trailing slashes
}

Expand Down
16 changes: 16 additions & 0 deletions test/bigquery.ts
Expand Up @@ -263,6 +263,22 @@ describe('BigQuery', () => {
assert.strictEqual(calledWith.apiEndpoint, 'https://some.fake.endpoint');
});

it('should allow overriding TPC universe', () => {
const universeDomain = 'fake-tpc-env.example.com/';
bq = new BigQuery({
universeDomain: universeDomain,
});
const calledWith = bq.calledWith_[0];
assert.strictEqual(
calledWith.baseUrl,
'https://bigquery.fake-tpc-env.example.com/bigquery/v2'
);
assert.strictEqual(
calledWith.apiEndpoint,
'https://bigquery.fake-tpc-env.example.com'
);
});

it('should capture any user specified location', () => {
const bq = new BigQuery({
projectId: PROJECT_ID,
Expand Down