Skip to content

Commit 41544f2

Browse files
vijay-qlogicGautamSharda
authored andcommitted
resolved name vs. id issue for family.js (#186)
* resolved name vs. id issue for family.js * added code review updates
1 parent 15acf11 commit 41544f2

5 files changed

Lines changed: 53 additions & 48 deletions

File tree

handwritten/bigtable/src/family.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FamilyError extends Error {
3434
*
3535
* @class
3636
* @param {Table} table
37-
* @param {string} name
37+
* @param {string} id
3838
*
3939
* @example
4040
* const Bigtable = require('@google-cloud/bigtable');
@@ -44,17 +44,14 @@ class FamilyError extends Error {
4444
* const family = table.family('follows');
4545
*/
4646
class Family {
47-
constructor(table, name) {
47+
constructor(table, id) {
4848
this.bigtable = table.bigtable;
4949
this.table = table;
5050

51-
this.id = Family.formatName_(table.name, name);
51+
const name = Family.formatName_(table.name, id);
5252

53-
/**
54-
* @name Family#familyName
55-
* @type {string}
56-
*/
57-
this.familyName = name.split('/').pop();
53+
this.id = name.split('/').pop();
54+
this.name = name;
5855
}
5956

6057
/**
@@ -63,7 +60,7 @@ class Family {
6360
* @private
6461
*
6562
* @param {string} tableName The full formatted table name.
66-
* @param {string} name The column family name.
63+
* @param {string} id The column family unique-identifier.
6764
* @returns {string}
6865
*
6966
* @example
@@ -73,12 +70,12 @@ class Family {
7370
* );
7471
* // 'projects/p/zones/z/clusters/c/tables/t/columnFamilies/my-family'
7572
*/
76-
static formatName_(tableName, name) {
77-
if (name.includes('/')) {
78-
return name;
73+
static formatName_(tableName, id) {
74+
if (id.includes('/')) {
75+
return id;
7976
}
8077

81-
return `${tableName}/columnFamilies/${name}`;
78+
return `${tableName}/columnFamilies/${id}`;
8279
}
8380

8481
/**
@@ -184,7 +181,7 @@ class Family {
184181
options = {};
185182
}
186183

187-
this.table.createFamily(this.familyName, options, callback);
184+
this.table.createFamily(this.id, options, callback);
188185
}
189186

190187
/**
@@ -221,7 +218,7 @@ class Family {
221218
name: this.table.name,
222219
modifications: [
223220
{
224-
id: this.familyName,
221+
id: this.id,
225222
drop: true,
226223
},
227224
],
@@ -361,7 +358,7 @@ class Family {
361358
}
362359

363360
for (let i = 0, l = families.length; i < l; i++) {
364-
if (families[i].id === this.id) {
361+
if (families[i].name === this.name) {
365362
this.metadata = families[i].metadata;
366363
callback(null, this.metadata);
367364
return;
@@ -414,7 +411,7 @@ class Family {
414411
}
415412

416413
const mod = {
417-
id: this.familyName,
414+
id: this.id,
418415
update: {},
419416
};
420417

@@ -436,7 +433,7 @@ class Family {
436433
},
437434
(...args) => {
438435
if (args[1]) {
439-
this.metadata = args[1].columnFamilies[this.familyName];
436+
this.metadata = args[1].columnFamilies[this.id];
440437
args.splice(1, 0, this.metadata);
441438
}
442439

handwritten/bigtable/src/table.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Table {
166166
*
167167
* @throws {error} If a name is not provided.
168168
*
169-
* @param {string} name The name of column family.
169+
* @param {string} id The unique identifier of column family.
170170
* @param {object} [options] Configuration object.
171171
* @param {object} [options.gaxOptions] Request configuration options, outlined
172172
* here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
@@ -228,18 +228,18 @@ class Table {
228228
* },
229229
* };
230230
*/
231-
createFamily(name, options, callback) {
231+
createFamily(id, options, callback) {
232232
if (is.function(options)) {
233233
callback = options;
234234
options = {};
235235
}
236236

237-
if (!name) {
238-
throw new Error('A name is required to create a family.');
237+
if (!id) {
238+
throw new Error('An id is required to create a family.');
239239
}
240240

241241
const mod = {
242-
id: name,
242+
id: id,
243243
create: {},
244244
};
245245

@@ -695,18 +695,18 @@ class Table {
695695
*
696696
* @throws {error} If a name is not provided.
697697
*
698-
* @param {string} name The family name.
698+
* @param {string} id The family unique identifier.
699699
* @returns {Family}
700700
*
701701
* @example
702702
* const family = table.family('my-family');
703703
*/
704-
family(name) {
705-
if (!name) {
706-
throw new Error('A family name must be provided.');
704+
family(id) {
705+
if (!id) {
706+
throw new Error('A family id must be provided.');
707707
}
708708

709-
return new Family(this, name);
709+
return new Family(this, id);
710710
}
711711

712712
/**

handwritten/bigtable/system-test/bigtable.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,11 @@ describe('Bigtable', function() {
375375
});
376376

377377
describe('column families', function() {
378-
var FAMILY_NAME = 'presidents';
378+
var FAMILY_ID = 'presidents';
379379
var FAMILY;
380380

381381
before(function(done) {
382-
FAMILY = TABLE.family(FAMILY_NAME);
382+
FAMILY = TABLE.family(FAMILY_ID);
383383
FAMILY.create(done);
384384
});
385385

@@ -388,18 +388,26 @@ describe('Bigtable', function() {
388388
assert.ifError(err);
389389
assert.strictEqual(families.length, 3);
390390
assert(families[0] instanceof Family);
391-
assert.strictEqual(families[0].name, FAMILY.name);
391+
assert.notEqual(
392+
-1,
393+
families
394+
.map(f => {
395+
return f.id;
396+
})
397+
.indexOf(FAMILY.id)
398+
);
392399
done();
393400
});
394401
});
395402

396403
it('should get a family', function(done) {
397-
var family = TABLE.family(FAMILY_NAME);
404+
var family = TABLE.family(FAMILY_ID);
398405

399406
family.get(function(err, family) {
400407
assert.ifError(err);
401408
assert(family instanceof Family);
402409
assert.strictEqual(family.name, FAMILY.name);
410+
assert.strictEqual(family.id, FAMILY.id);
403411
done();
404412
});
405413
});

handwritten/bigtable/test/family.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var fakeUtil = extend({}, util, {
3232
});
3333

3434
describe('Bigtable/Family', function() {
35-
var FAMILY_NAME = 'family-test';
35+
var FAMILY_ID = 'family-test';
3636
var TABLE = {
3737
bigtable: {},
3838
id: 'my-table',
@@ -41,9 +41,9 @@ describe('Bigtable/Family', function() {
4141
createFamily: util.noop,
4242
};
4343

44-
var FAMILY_ID = format('{t}/columnFamilies/{f}', {
44+
var FAMILY_NAME = format('{t}/columnFamilies/{f}', {
4545
t: TABLE.name,
46-
f: FAMILY_NAME,
46+
f: FAMILY_ID,
4747
});
4848

4949
var Family;
@@ -83,21 +83,21 @@ describe('Bigtable/Family', function() {
8383

8484
it('should extract the family name', function() {
8585
var family = new Family(TABLE, FAMILY_ID);
86-
assert.strictEqual(family.familyName, FAMILY_NAME);
86+
assert.strictEqual(family.name, FAMILY_NAME);
8787
});
8888
});
8989

9090
describe('formatName_', function() {
9191
it('should format the column family name', function() {
92-
var formatted = Family.formatName_(TABLE.name, FAMILY_NAME);
92+
var formatted = Family.formatName_(TABLE.name, FAMILY_ID);
9393

94-
assert.strictEqual(formatted, FAMILY_ID);
94+
assert.strictEqual(formatted, FAMILY_NAME);
9595
});
9696

9797
it('should not re-format the name', function() {
9898
var formatted = Family.formatName_(TABLE.name, FAMILY_ID);
9999

100-
assert.strictEqual(formatted, FAMILY_ID);
100+
assert.strictEqual(formatted, FAMILY_NAME);
101101
});
102102
});
103103

@@ -214,8 +214,8 @@ describe('Bigtable/Family', function() {
214214
it('should call createFamily from table', function(done) {
215215
var options = {};
216216

217-
family.table.createFamily = function(name, options_, callback) {
218-
assert.strictEqual(name, family.familyName);
217+
family.table.createFamily = function(id, options_, callback) {
218+
assert.strictEqual(id, family.id);
219219
assert.strictEqual(options_, options);
220220
callback(); // done()
221221
};
@@ -243,7 +243,7 @@ describe('Bigtable/Family', function() {
243243
name: family.table.name,
244244
modifications: [
245245
{
246-
id: family.familyName,
246+
id: family.id,
247247
drop: true,
248248
},
249249
],
@@ -528,7 +528,7 @@ describe('Bigtable/Family', function() {
528528
assert.strictEqual(config.reqOpts.name, TABLE.name);
529529
assert.deepEqual(config.reqOpts.modifications, [
530530
{
531-
id: FAMILY_NAME,
531+
id: FAMILY_ID,
532532
update: {},
533533
},
534534
]);
@@ -564,7 +564,7 @@ describe('Bigtable/Family', function() {
564564
name: TABLE.name,
565565
modifications: [
566566
{
567-
id: family.familyName,
567+
id: family.id,
568568
update: {
569569
gcRule: formattedRule,
570570
},

handwritten/bigtable/test/table.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ describe('Bigtable/Table', function() {
270270
describe('createFamily', function() {
271271
var COLUMN_ID = 'my-column';
272272

273-
it('should throw if a name is not provided', function() {
273+
it('should throw if a id is not provided', function() {
274274
assert.throws(function() {
275275
table.createFamily();
276-
}, /A name is required to create a family\./);
276+
}, /An id is required to create a family\./);
277277
});
278278

279279
it('should provide the proper request options', function(done) {
@@ -1188,10 +1188,10 @@ describe('Bigtable/Table', function() {
11881188
describe('family', function() {
11891189
var FAMILY_ID = 'test-family';
11901190

1191-
it('should throw if a name is not provided', function() {
1191+
it('should throw if an id is not provided', function() {
11921192
assert.throws(function() {
11931193
table.family();
1194-
}, /A family name must be provided\./);
1194+
}, /A family id must be provided\./);
11951195
});
11961196

11971197
it('should create a family with the proper arguments', function() {

0 commit comments

Comments
 (0)