Skip to content

Commit 6631a1e

Browse files
committed
minor adjustments per pr feedback
1 parent 79bcb4d commit 6631a1e

6 files changed

Lines changed: 100 additions & 72 deletions

File tree

packages/bigquery/src/dataset.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ function Dataset(bigQuery, id) {
179179

180180
this.bigQuery = bigQuery;
181181

182+
// Catch all for read-modify-write cycle
183+
// https://cloud.google.com/bigquery/docs/api-performance#read-patch-write
182184
this.interceptors.push({
183185
request: function(reqOpts) {
184186
if (reqOpts.method === 'PATCH' && reqOpts.json.etag) {

packages/bigquery/src/table.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ function Table(dataset, id) {
221221
this.bigQuery = dataset.bigQuery;
222222
this.dataset = dataset;
223223

224+
// Catch all for read-modify-write cycle
225+
// https://cloud.google.com/bigquery/docs/api-performance#read-patch-write
224226
this.interceptors.push({
225227
request: function(reqOpts) {
226228
if (reqOpts.method === 'PATCH' && reqOpts.json.etag) {
@@ -384,11 +386,11 @@ Table.prototype.copy = function(destination, metadata, callback) {
384386
return;
385387
}
386388

387-
job.on('error', callback);
388-
389-
job.on('complete', function(metadata) {
390-
callback(null, metadata);
391-
});
389+
job
390+
.on('error', callback)
391+
.on('complete', function(metadata) {
392+
callback(null, metadata);
393+
});
392394
});
393395
};
394396

@@ -444,11 +446,11 @@ Table.prototype.copyFrom = function(sourceTables, metadata, callback) {
444446
return;
445447
}
446448

447-
job.on('error', callback);
448-
449-
job.on('complete', function(metadata) {
450-
callback(null, metadata);
451-
});
449+
job
450+
.on('error', callback)
451+
.on('complete', function(metadata) {
452+
callback(null, metadata);
453+
});
452454
});
453455
};
454456

@@ -671,11 +673,11 @@ Table.prototype.export = function(destination, options, callback) {
671673
return;
672674
}
673675

674-
job.on('error', callback);
675-
676-
job.on('complete', function(metadata) {
677-
callback(null, metadata);
678-
});
676+
job
677+
.on('error', callback)
678+
.on('complete', function(metadata) {
679+
callback(null, metadata);
680+
});
679681
});
680682
};
681683

@@ -851,11 +853,11 @@ Table.prototype.import = function(source, metadata, callback) {
851853
return;
852854
}
853855

854-
job.on('error', callback);
855-
856-
job.on('complete', function(metadata) {
857-
callback(null, metadata);
858-
});
856+
job
857+
.on('error', callback)
858+
.on('complete', function(metadata) {
859+
callback(null, metadata);
860+
});
859861
});
860862
};
861863

@@ -873,7 +875,8 @@ Table.prototype.import = function(source, metadata, callback) {
873875
* @param {object=} options - Configuration object.
874876
* @param {boolean} options.autoCreate - Automatically create the table if it
875877
* doesn't already exist. In order for this to succeed the `schema` option
876-
* must also be set.
878+
* must also be set. Note that this can take longer than 2 minutes to
879+
* complete.
877880
* @param {boolean} options.ignoreUnknownValues - Accept rows that contain
878881
* values that do not match the schema. The unknown values are ignored.
879882
* Default: `false`.

packages/bigquery/test/dataset.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,23 +292,27 @@ describe('BigQuery/Dataset', function() {
292292
ds.createTable(TABLE_ID, done);
293293
});
294294

295-
it('should not modify the original options object', function(done) {
296-
var options = {
297-
a: 'b',
298-
c: 'd'
299-
};
295+
it('should format the metadata', function(done) {
296+
var formatMetadata_ = Table.formatMetadata_;
297+
var formatted = {};
298+
var fakeOptions = {};
300299

301-
var originalOptions = extend({}, options);
300+
Table.formatMetadata_ = function(options) {
301+
assert.strictEqual(options, fakeOptions);
302+
return formatted;
303+
};
302304

303305
ds.request = function(reqOpts) {
304-
assert.notStrictEqual(reqOpts.json, options);
305-
assert.deepEqual(options, originalOptions);
306+
assert.strictEqual(reqOpts.json, formatted);
307+
308+
Table.formatMetadata_ = formatMetadata_;
306309
done();
307310
};
308311

309-
ds.createTable(TABLE_ID, options, assert.ifError);
312+
ds.createTable(TABLE_ID, fakeOptions, assert.ifError);
310313
});
311314

315+
312316
it('should create a schema object from a string', function(done) {
313317
ds.request = function(reqOpts) {
314318
assert.deepEqual(reqOpts.json.schema, SCHEMA_OBJECT);
@@ -642,14 +646,6 @@ describe('BigQuery/Dataset', function() {
642646
describe('startQuery', function() {
643647
var FAKE_QUERY = 'SELECT * FROM `table`';
644648

645-
it('should call through to bigQuery#startQuery', function(done) {
646-
ds.bigQuery.startQuery = function() {
647-
done();
648-
};
649-
650-
ds.startQuery();
651-
});
652-
653649
it('should extend the options', function(done) {
654650
var fakeOptions = {
655651
query: FAKE_QUERY,

packages/bigquery/test/index.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ describe('BigQuery', function() {
165165
{ name: 'name', type: 'STRING' },
166166
{ name: 'dob', type: 'TIMESTAMP' },
167167
{ name: 'has_claws', type: 'BOOLEAN' },
168-
{ name: 'hair_count', type: 'FLOAT' }
168+
{ name: 'has_fangs', type: 'BOOL' },
169+
{ name: 'hair_count', type: 'FLOAT' },
170+
{ name: 'teeth_count', type: 'FLOAT64' }
169171
]
170172
};
171173

@@ -211,14 +213,23 @@ describe('BigQuery', function() {
211213
{ v: 'Milo' },
212214
{ v: String(now.valueOf() / 1000) },
213215
{ v: 'false' },
216+
{ v: 'true' },
214217
{ v: '5.222330009847' },
218+
{ v: '30.2232138' },
215219
{
216220
v: [
217221
{
218222
v: '10'
219223
}
220224
]
221225
},
226+
{
227+
v: [
228+
{
229+
v: '2'
230+
}
231+
]
232+
},
222233
{ v: null },
223234
{ v: buffer.toString('base64') },
224235
{
@@ -253,8 +264,11 @@ describe('BigQuery', function() {
253264
type: 'fakeTimestamp'
254265
},
255266
has_claws: false,
267+
has_fangs: true,
256268
hair_count: 5.222330009847,
269+
teeth_count: 30.2232138,
257270
arr: [10],
271+
arr2: [2],
258272
nullable: null,
259273
buffer: buffer,
260274
objects: [
@@ -288,6 +302,12 @@ describe('BigQuery', function() {
288302
mode: 'REPEATED'
289303
});
290304

305+
schemaObject.fields.push({
306+
name: 'arr2',
307+
type: 'INT64',
308+
mode: 'REPEATED'
309+
});
310+
291311
schemaObject.fields.push({
292312
name: 'nullable',
293313
type: 'STRING',
@@ -1151,27 +1171,6 @@ describe('BigQuery', function() {
11511171

11521172
bq.query(QUERY_STRING, fakeOptions, assert.ifError);
11531173
});
1154-
1155-
it('should return errors from getQueryResults', function(done) {
1156-
var error = new Error('err');
1157-
1158-
var fakeJob = {
1159-
getQueryResults: function(options, callback) {
1160-
callback(error, null, FAKE_RESPONSE);
1161-
}
1162-
};
1163-
1164-
bq.startQuery = function(query, callback) {
1165-
callback(null, fakeJob, FAKE_RESPONSE);
1166-
};
1167-
1168-
bq.query(QUERY_STRING, function(err, rows, resp) {
1169-
assert.strictEqual(err, error);
1170-
assert.strictEqual(rows, null);
1171-
assert.strictEqual(resp, FAKE_RESPONSE);
1172-
done();
1173-
});
1174-
});
11751174
});
11761175

11771176
describe('startQuery', function() {

packages/bigquery/test/job.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ describe('BigQuery/Job', function() {
275275
};
276276

277277
job.getQueryResults(function(err, rows) {
278+
assert.ifError(err);
278279
assert.strictEqual(rows, mergedRows);
279280
done();
280281
});

packages/bigquery/test/table.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,10 @@ describe('BigQuery/Table', function() {
680680
makeWritableStreamOverride = function(stream, options) {
681681
var jobId = options.metadata.jobReference.jobId;
682682
assert.strictEqual(jobId, expectedJobId);
683+
684+
var config = options.metadata.configuration.load;
685+
assert.strictEqual(config.jobPrefix, undefined);
686+
683687
done();
684688
};
685689

@@ -1203,7 +1207,7 @@ describe('BigQuery/Table', function() {
12031207
});
12041208

12051209
it('should not include the schema in the insert request', function(done) {
1206-
table.request = function(reqOpts) {
1210+
table.request = function(reqOpts) {
12071211
assert.strictEqual(reqOpts.json.schema, undefined);
12081212
assert.strictEqual(reqOpts.json.autoCreate, undefined);
12091213
done();
@@ -1394,7 +1398,16 @@ describe('BigQuery/Table', function() {
13941398
callback(); // the done fn
13951399
};
13961400

1397-
table.startCopy(DEST_TABLE, done);
1401+
table.startCopy(DEST_TABLE, {}, done);
1402+
});
1403+
1404+
it('should optionally accept metadata', function(done) {
1405+
table.bigQuery.createJob = function(reqOpts, callback) {
1406+
assert.strictEqual(done, callback);
1407+
callback(); // the done fn
1408+
};
1409+
1410+
table.startCopy(DEST_TABLE,done);
13981411
});
13991412
});
14001413

@@ -1497,20 +1510,16 @@ describe('BigQuery/Table', function() {
14971510
callback(); // the done fn
14981511
};
14991512

1500-
table.startCopyFrom(SOURCE_TABLE, done);
1513+
table.startCopyFrom(SOURCE_TABLE, {}, done);
15011514
});
15021515

1503-
it('should pass an error to the callback', function(done) {
1504-
var error = new Error('Error.');
1505-
1516+
it('should optionally accept options', function(done) {
15061517
table.bigQuery.createJob = function(reqOpts, callback) {
1507-
callback(error);
1518+
assert.strictEqual(done, callback);
1519+
callback(); // the done fn
15081520
};
15091521

1510-
table.startCopyFrom(SOURCE_TABLE, function(err) {
1511-
assert.equal(err, error);
1512-
done();
1513-
});
1522+
table.startCopyFrom(SOURCE_TABLE, done);
15141523
});
15151524
});
15161525

@@ -1534,7 +1543,7 @@ describe('BigQuery/Table', function() {
15341543
table.bigQuery.createJob = function() {};
15351544
});
15361545

1537-
it('should send the correct API request', function(done) {
1546+
it('should call createJob correctly', function(done) {
15381547
table.bigQuery.createJob = function(reqOpts) {
15391548
assert.deepEqual(reqOpts.configuration.extract.sourceTable, {
15401549
datasetId: table.dataset.id,
@@ -1682,6 +1691,15 @@ describe('BigQuery/Table', function() {
16821691
callback(); // the done fn
16831692
};
16841693

1694+
table.startExport(FILE, {}, done);
1695+
});
1696+
1697+
it('should optionally accept options', function(done) {
1698+
table.bigQuery.createJob = function(reqOpts, callback) {
1699+
assert.strictEqual(done, callback);
1700+
callback(); // the done fn
1701+
};
1702+
16851703
table.startExport(FILE, done);
16861704
});
16871705
});
@@ -1838,6 +1856,15 @@ describe('BigQuery/Table', function() {
18381856
callback(); // the done fn
18391857
};
18401858

1859+
table.startImport(FILE, {}, done);
1860+
});
1861+
1862+
it('should optionally accept options', function(done) {
1863+
table.bigQuery.createJob = function(reqOpts, callback) {
1864+
assert.strictEqual(done, callback);
1865+
callback(); // the done fn
1866+
};
1867+
18411868
table.startImport(FILE, done);
18421869
});
18431870

0 commit comments

Comments
 (0)