GeezerVison is showing github.com — fix#47 Respect decode: false option when cell value is split between … · googleapis/google-cloud-node@d650514
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: handwritten/bigtable/src/chunktransformer.js +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -346,9 +346,21 @@ ChunkTransformer.prototype.processCellInProgress = function(chunk) { | 346 | 346 | if (chunk.resetRow) { | 347 | 347 | return this.reset(); | 348 | 348 | } | 349 | | - this.qualifier.value += Mutation.convertFromBytes(chunk.value, { | | 349 | + const chunkQualifierValue = Mutation.convertFromBytes(chunk.value, { | 350 | 350 | userOptions: this.options, | 351 | 351 | }); | | 352 | + | | 353 | + if ( | | 354 | + chunkQualifierValue instanceof Buffer && | | 355 | + this.qualifier.value instanceof Buffer | | 356 | + ) { | | 357 | + this.qualifier.value = Buffer.concat([ | | 358 | + this.qualifier.value, | | 359 | + chunkQualifierValue, | | 360 | + ]); | | 361 | + } else { | | 362 | + this.qualifier.value += chunkQualifierValue; | | 363 | + } | 352 | 364 | this.moveToNextState(chunk); | 353 | 365 | }; | 354 | 366 |
| |
Collapse file Copy file name to clipboardExpand all lines: handwritten/bigtable/test/chunktransformer.js +59Lines changed: 59 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -737,6 +737,65 @@ describe('Bigtable/ChunkTransformer', function() { | 737 | 737 | 'state mismatch' | 738 | 738 | ); | 739 | 739 | }); | | 740 | + it('should concat buffer when decode option is false', function() { | | 741 | + chunkTransformer = new ChunkTransformer({decode: false}); | | 742 | + processCellInProgressSpy = sinon.spy( | | 743 | + chunkTransformer, | | 744 | + 'processCellInProgress' | | 745 | + ); | | 746 | + resetSpy = sinon.spy(chunkTransformer, 'reset'); | | 747 | + commitSpy = sinon.spy(chunkTransformer, 'commit'); | | 748 | + destroySpy = sinon.spy(chunkTransformer, 'destroy'); | | 749 | + chunkTransformer.qualifier = { | | 750 | + value: Buffer.from('value'.toString('base64'), 'base64'), | | 751 | + size: 0, | | 752 | + timestamp: 0, | | 753 | + labels: [], | | 754 | + }; | | 755 | + chunkTransformer.qualifiers = [chunkTransformer.qualifier]; | | 756 | + chunkTransformer.family = { | | 757 | + qualifier: chunkTransformer.qualifiers, | | 758 | + }; | | 759 | + chunkTransformer.row = { | | 760 | + key: 'key', | | 761 | + data: { | | 762 | + family: chunkTransformer.family, | | 763 | + }, | | 764 | + }; | | 765 | + const chunk = { | | 766 | + commitRow: false, | | 767 | + value: Buffer.from('value'.toString('base64'), 'base64'), | | 768 | + valueSize: 0, | | 769 | + }; | | 770 | + chunkTransformer.processCellInProgress(chunk); | | 771 | + assert(!resetSpy.called, 'invalid call to reset'); | | 772 | + assert(!commitSpy.called, 'invalid call to commit'); | | 773 | + assert.equal(rows.length, 0, 'wrong call to push'); | | 774 | + const expectedState = { | | 775 | + key: 'key', | | 776 | + data: { | | 777 | + family: { | | 778 | + qualifier: [ | | 779 | + { | | 780 | + value: Buffer.concat([ | | 781 | + Buffer.from('value'.toString('base64'), 'base64'), | | 782 | + Buffer.from('value'.toString('base64'), 'base64'), | | 783 | + ]), | | 784 | + size: 0, | | 785 | + timestamp: 0, | | 786 | + labels: [], | | 787 | + }, | | 788 | + ], | | 789 | + }, | | 790 | + }, | | 791 | + }; | | 792 | + assert.deepEqual(chunkTransformer.row, expectedState, 'row mismatch'); | | 793 | + assert.equal( | | 794 | + chunkTransformer.state, | | 795 | + RowStateEnum.ROW_IN_PROGRESS, | | 796 | + 'state mismatch' | | 797 | + ); | | 798 | + }); | 740 | 799 | }); | 741 | 800 | describe('_flush', function() { | 742 | 801 | var _flushSpy; | |
|