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 1 commit
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
Next Next commit
feat: add support for TPC Universes
  • Loading branch information
alvarowolfx committed Feb 8, 2024
commit 05406d3534935174a8ab0c7194185bd29beeca01
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@google-cloud/bigquery": "^7.3.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
Original file line number Diff line number Diff line change
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";

Check failure on line 338 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"googleapis.com"` with `'googleapis.com'`

Check warning on line 338 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
const servicePath = "bigquery";

Check failure on line 339 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"bigquery";····` with `'bigquery';`

Check warning on line 339 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check failure on line 339 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed

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

const EMULATOR_HOST = process.env.BIGQUERY_EMULATOR_HOST;

let apiEndpoint = `https://${servicePath}.${universeDomain}`;

Check failure on line 347 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`

Check failure on line 347 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed

Check failure on line 348 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`

Check failure on line 348 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
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(){

Check failure on line 491 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
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) {

Check failure on line 502 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`

Check failure on line 502 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
return url.replace(/\/+$/, ''); // Remove trailing slashes
}

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

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

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