Skip to content

Commit

Permalink
Merge branch 'main' into re-request-data-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkim-codes authored Nov 4, 2024
2 parents 090c92e + c4e2356 commit a19e4c3
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .kokoro/coerce_logs.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .kokoro/conformance.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ export type ISetCell = btTypes.bigtable.v2.Mutation.ISetCell;
export type Bytes = string | Buffer;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Data = any;
/*
The Data type is expected to be in the following format:
{
columnFamily1: {
column1: Cell,
column2: Cell
},
columnFamily2: {
otherColumn1: Cell,
otherColumn2: Cell
}
}
Where the Cell data type has the following structure:
Uint8Array | string | {
value: Uint8Array|string,
timestamp: number|Long|string,
}
*/
export interface JsonObj {
[k: string]: string | JsonObj;
}
Expand Down
8 changes: 8 additions & 0 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ export interface MutateOptions {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Entry = any;
/*
The Entry type is expected to be in the following format:
{
key?: Uint8Array|string,
data?: Data, // The Data type is described in the Mutation class.
method?: typeof mutation.methods
}
*/

export type DeleteTableCallback = (
err: ServiceError | null,
Expand Down
85 changes: 85 additions & 0 deletions system-test/bigtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {Row} from '../src/row.js';
import {Table} from '../src/table.js';
import {RawFilter} from '../src/filter';
import {generateId, PREFIX} from './common';
import {Mutation} from '../src/mutation';

describe('Bigtable', () => {
const bigtable = new Bigtable();
Expand Down Expand Up @@ -1712,6 +1713,90 @@ describe('Bigtable', () => {
});
});
});

describe('mutateRows entries tests', () => {
const table = INSTANCE.table(generateId('table'));

afterEach(async () => {
await table.delete();
});

it('should only insert one row in the table with mutate', async () => {
// Create table
const tableOptions = {
families: ['columnFamily'],
};
await table.create(tableOptions);
// Add entries
const entry = {
columnFamily: {
column: 1,
},
};
const mutation = {
key: 'rowKey',
data: entry,
method: Mutation.methods.INSERT,
};
const gaxOptions = {maxRetries: 4};
await table.mutate(mutation, {gaxOptions});
// Get rows and compare
const [rows] = await table.getRows();
assert.strictEqual(rows.length, 1);
});

it('should insert one row in the table using mutate in a similar way to how the documentation says to use insert', async () => {
// Create table
const tableOptions = {
families: ['columnFamily'],
};
await table.create(tableOptions);
// Add entries
const mutation = {
key: 'rowKey',
data: {
columnFamily: {
column: 1,
},
},
method: Mutation.methods.INSERT,
};
const gaxOptions = {maxRetries: 4};
await table.mutate(mutation, {gaxOptions});
// Get rows and compare
const [rows] = await table.getRows();
assert.strictEqual(rows.length, 1);
});

it('should only insert one row in the table with insert as described by the GCP documentation', async () => {
// Create table
const tableOptions = {
families: ['follows'],
};
await table.create(tableOptions);
// Add entries
const greetings = ['Hello World!', 'Hello Bigtable!', 'Hello Node!'];
const rowsToInsert = greetings.map((greeting, index) => ({
key: `greeting${index}`,
data: {
follows: {
// 'follows' is the column family
someColumn: {
// Setting the timestamp allows the client to perform retries. If
// server-side time is used, retries may cause multiple cells to
// be generated.
timestamp: new Date(),
value: greeting,
},
},
},
}));
await table.insert(rowsToInsert);
// Get rows and compare
const [rows] = await table.getRows();
assert.strictEqual(rows.length, 3);
});
});
});

function createInstanceConfig(
Expand Down
1 change: 1 addition & 0 deletions testproxy/known_failures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestMutateRow_Generic_Headers\|TestMutateRow_Generic_DeadlineExceeded|TestMutateRows_Generic_CloseClient\|TestMutateRows_Retry_WithRoutingCookie\|TestReadModifyWriteRow_Generic_Headers\|TestReadModifyWriteRow_NoRetry_TransientError\|TestReadModifyWriteRow_Generic_DeadlineExceeded\|TestReadRow_Generic_DeadlineExceeded\|TestReadRow_Retry_WithRoutingCookie\|TestReadRow_Retry_WithRetryInfo\|TestReadRows_ReverseScans_FeatureFlag_Enabled\|TestReadRows_NoRetry_OutOfOrderError_Reverse\|TestReadRows_Retry_PausedScan\|TestReadRows_Retry_LastScannedRow\|TestReadRows_Retry_LastScannedRow_Reverse\|TestCheckAndMutateRow_NoRetry_TransientError\|TestCheckAndMutateRow_Generic_DeadlineExceeded

0 comments on commit a19e4c3

Please sign in to comment.