Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,12 @@ export class BigQuery extends Service {
);
} else if (typeName === 'STRUCT') {
queryParameter.parameterValue!.structValues = Object.keys(value).reduce(
(structValues, prop) => {
(
structValues: {
[key: string]: bigquery.IQueryParameterValue;
},
prop: string
) => {
let nestedQueryParameter;
if (providedType) {
nestedQueryParameter = BigQuery.valueToQueryParameter_(
Expand All @@ -1209,8 +1214,9 @@ export class BigQuery extends Service {
} else {
nestedQueryParameter = BigQuery.valueToQueryParameter_(value[prop]);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(structValues as any)[prop] = nestedQueryParameter.parameterValue;
if (nestedQueryParameter.parameterValue !== undefined) {
structValues[prop] = nestedQueryParameter.parameterValue;
}
return structValues;
},
{}
Expand Down Expand Up @@ -1525,11 +1531,9 @@ export class BigQuery extends Service {
delete query.params;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const reqOpts: any = {
configuration: {
query,
},
const reqOpts: JobOptions = {};
reqOpts.configuration = {
query,
};

if (typeof query.jobTimeoutMs === 'number') {
Expand Down Expand Up @@ -1800,7 +1804,7 @@ export class BigQuery extends Service {
if (options.projectId) {
reqOpts.projectId = options.projectId;
}
this.request(reqOpts, (err, resp) => {
this.request(reqOpts, (err, resp: bigquery.IDatasetList) => {
if (err) {
callback!(err, null, null, resp);
return;
Expand All @@ -1814,7 +1818,6 @@ export class BigQuery extends Service {
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const datasets = (resp.datasets || []).map(
(dataset: bigquery.IDataset) => {
const dsOpts: DatasetOptions = {
Expand Down Expand Up @@ -1932,7 +1935,8 @@ export class BigQuery extends Service {
}
const jobs = (resp.jobs || []).map((jobObject: bigquery.IJob) => {
const job = this.job(jobObject.jobReference!.jobId!, {
location: jobObject.jobReference!.location!,
location: jobObject.jobReference?.location,
projectId: jobObject.jobReference?.projectId,
});
job.metadata = jobObject!;
return job;
Expand Down Expand Up @@ -1962,6 +1966,7 @@ export class BigQuery extends Service {
if (this.location) {
options = extend({location: this.location}, options);
}
options = extend({projectId: this.projectId}, options);
return new Job(this, id, options);
}

Expand Down
13 changes: 5 additions & 8 deletions src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,7 @@ class Dataset extends ServiceObject {
const callback =
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
const body = Table.formatMetadata_(options as TableMetadata);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(body as any).tableReference = {
body.tableReference = {
datasetId: this.id,
projectId: this.projectId,
tableId: id,
Expand Down Expand Up @@ -1163,7 +1162,7 @@ class Dataset extends ServiceObject {
uri: '/tables',
qs: options,
},
(err, resp) => {
(err, resp: bigquery.ITableList) => {
if (err) {
callback!(err, null, null, resp);
return;
Expand All @@ -1176,11 +1175,9 @@ class Dataset extends ServiceObject {
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const tables = (resp.tables || []).map((tableObject: any) => {
const table = this.table(tableObject.tableReference.tableId, {
location: tableObject.location,
});
const tables = (resp.tables || []).map(tableObject => {
const tableRef = tableObject.tableReference!;
const table = this.table(tableRef.tableId!);
table.metadata = tableObject;
return table;
});
Expand Down
5 changes: 2 additions & 3 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
RequestCallback,
JobRequest,
} from '.';
import {JobMetadata} from './job';
import {JobMetadata, JobOptions} from './job';
import bigquery from './types';

// This is supposed to be a @google-cloud/storage `File` type. The storage npm
Expand Down Expand Up @@ -424,8 +424,7 @@ class Model extends ServiceObject {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body: any = {
const body: JobOptions = {
configuration: {
extract: extend(true, options, {
sourceModel: {
Expand Down
41 changes: 19 additions & 22 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
} from '.';
import {GoogleErrorBody} from '@google-cloud/common/build/src/util';
import {Duplex, Writable} from 'stream';
import {JobMetadata} from './job';
import {JobMetadata, JobOptions} from './job';
import bigquery from './types';
import {IntegerTypeCastOptions} from './bigquery';
import {RowQueue} from './rowQueue';
Expand Down Expand Up @@ -923,8 +923,7 @@ class Table extends ServiceObject {
const callback =
typeof metadataOrCallback === 'function' ? metadataOrCallback : cb;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body: any = {
const body: JobOptions = {
configuration: {
copy: extend(true, metadata, {
destinationTable: {
Expand Down Expand Up @@ -1045,8 +1044,7 @@ class Table extends ServiceObject {
const callback =
typeof metadataOrCallback === 'function' ? metadataOrCallback : cb;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body: any = {
const body: JobOptions = {
configuration: {
copy: extend(true, metadata, {
destinationTable: {
Expand Down Expand Up @@ -1218,8 +1216,7 @@ class Table extends ServiceObject {
delete options.gzip;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body: any = {
const body: JobOptions = {
configuration: {
extract: extend(true, options, {
sourceTable: {
Expand Down Expand Up @@ -1399,15 +1396,13 @@ class Table extends ServiceObject {
return [jobResponse, jobResponse.metadata];
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body: any = {
configuration: {
load: {
destinationTable: {
projectId: this.dataset.projectId,
datasetId: this.dataset.id,
tableId: this.id,
},
const body: JobOptions = {};
body.configuration = {
load: {
destinationTable: {
projectId: this.dataset.projectId,
datasetId: this.dataset.id,
tableId: this.id,
},
},
};
Expand Down Expand Up @@ -1438,7 +1433,9 @@ class Table extends ServiceObject {
// to CSV.
const format = FORMATS[path.extname(src.name).substr(1).toLowerCase()];
if (!metadata.sourceFormat && format) {
body.configuration.load.sourceFormat = format;
if (body.configuration && body.configuration.load) {
body.configuration.load.sourceFormat = format;
}
}
return 'gs://' + src.bucket.name + '/' + src.name;
}),
Expand Down Expand Up @@ -1550,11 +1547,11 @@ class Table extends ServiceObject {
uri: `${this.bigQuery.apiEndpoint}/upload/bigquery/v2/projects/${this.dataset.projectId}/jobs`,
},
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(data: any) => {
const job = this.bigQuery.job(data.jobReference.jobId, {
location: data.jobReference.location,
projectId: data.jobReference.projectId,
(data: JobMetadata) => {
const jobRef = data.jobReference!;
const job = this.bigQuery.job(jobRef.jobId!, {
location: jobRef.location,
projectId: jobRef.projectId,
});
job.metadata = data;
dup.emit('job', job);
Expand Down
23 changes: 18 additions & 5 deletions test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe('BigQuery', () => {
const PROJECT_ID = 'test-project';
const ANOTHER_PROJECT_ID = 'another-test-project';
const LOCATION = 'asia-northeast1';
const ANOTHER_LOCATION = 'us-central1';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let BigQueryCached: any;
Expand Down Expand Up @@ -2667,6 +2668,7 @@ describe('BigQuery', () => {
jobReference: {
jobId: JOB_ID,
location: LOCATION,
projectId: PROJECT_ID,
},
},
],
Expand All @@ -2682,7 +2684,10 @@ describe('BigQuery', () => {
assert(job instanceof FakeJob);
assert.strictEqual(args[0], bq);
assert.strictEqual(args[1], JOB_ID);
assert.deepStrictEqual(args[2], {location: LOCATION});
assert.deepStrictEqual(args[2], {
location: LOCATION,
projectId: PROJECT_ID,
});
done();
});
});
Expand Down Expand Up @@ -2766,19 +2771,27 @@ describe('BigQuery', () => {

it('should pass the options object', () => {
const options = {a: 'b'};
const expectedOptions = extend({projectId: PROJECT_ID}, options);
const job = bq.job(JOB_ID, options);

assert.strictEqual(job.calledWith_[2], options);
assert.deepStrictEqual(job.calledWith_[2], expectedOptions);
});

it('should pass in the user specified location', () => {
it('should pass in the user specified location and project', () => {
const bq = new BigQuery({
projectId: PROJECT_ID,
location: LOCATION,
});

const options = {a: 'b'};
const expectedOptions = Object.assign({location: LOCATION}, options);
const options = {
a: 'b',
location: ANOTHER_LOCATION,
projectId: ANOTHER_PROJECT_ID,
};
const expectedOptions = Object.assign(
{location: ANOTHER_LOCATION, projectId: ANOTHER_PROJECT_ID},
options
);

const job = bq.job(JOB_ID, options);
const args = job.calledWith_;
Expand Down
2 changes: 2 additions & 0 deletions test/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ describe('BigQuery/Dataset', () => {
};

beforeEach(() => {
ds = new Dataset(BIGQUERY, DATASET_ID, {location: LOCATION});
ds.request = (reqOpts: DecorateRequestOptions, callback: Function) => {
callback(null, apiResponse);
};
Expand All @@ -929,6 +930,7 @@ describe('BigQuery/Dataset', () => {
assert(table instanceof Table);
assert.strictEqual(table.id, tableId);
assert.strictEqual(table.location, LOCATION);
assert.strictEqual(table.projectId, BIGQUERY.location);
assert.strictEqual(apiResponse_, apiResponse);
done();
}
Expand Down