Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigtable Mutate rows optional parameter #1233

Merged
merged 2 commits into from
Aug 17, 2018
Merged
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
10 changes: 6 additions & 4 deletions Bigtable/src/DataClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,17 @@ public function __construct($instanceId, $tableId, array $config = [])
* $dataClient->mutateRows([$rowMutation]);
* ```
* @param array $rowMutations array of RowMutation object.
* @param array $options [optional] Configuration options.
* @return void
* @throws ApiException|BigtableDataOperationException if the remote call fails or operation fails
*/
public function mutateRows(array $rowMutations)
public function mutateRows(array $rowMutations, array $options = [])
{
$entries = [];
foreach ($rowMutations as $rowMutation) {
$entries[] = $rowMutation->getEntry();
}
$responseStream = $this->bigtableClient->mutateRows($this->tableName, $entries, $this->options);
$responseStream = $this->bigtableClient->mutateRows($this->tableName, $entries, $options + $this->options);
$rowMutationsFailedResponse = [];
$failureCode = Code::OK;
$message = 'partial failure';
Expand Down Expand Up @@ -161,10 +162,11 @@ public function mutateRows(array $rowMutations)
* $dataClient->upsert(['r1' => ['cf1' => ['cq1' => ['value'=>'value1', 'timeStamp' => 1534183334215000]]]]);
* ```
* @param array[] $rows array of row.
* @param array $options [optional] Configuration options.
* @return void
* @throws ApiException|BigtableDataOperationException if the remote call fails or operation fails
*/
public function upsert(array $rows)
public function upsert(array $rows, array $options = [])
{
$rowMutations = [];
foreach ($rows as $rowKey => $families) {
Expand All @@ -185,6 +187,6 @@ public function upsert(array $rows)
}
$rowMutations[] = $rowMutation;
}
$this->mutateRows($rowMutations);
$this->mutateRows($rowMutations, $options);
}
}
54 changes: 54 additions & 0 deletions Bigtable/tests/Unit/DataClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ public function testMutateRows()
$this->dataClient->mutateRows($this->rowMutations);
}

public function testMutateRowsOptionalConfiguration()
{
$this->serverStream->readAll()
->shouldBeCalled()
->willReturn(
$this->arrayAsGenerator([])
);
$options = [
'key1' => 'value1'
];
$this->bigtableClient->mutateRows(self::TABLE_NAME, $this->entries, $this->options + $options)
->shouldBeCalled()
->willReturn(
$this->serverStream->reveal()
);
$this->dataClient->mutateRows($this->rowMutations, $options);
}

public function testMutateRowsFailure()
{
$statuses = [];
Expand Down Expand Up @@ -215,6 +233,42 @@ public function testUpsert()
$this->dataClient->upsert($rows);
}

public function testUpsertOptionalConfiguration()
{
$this->serverStream->readAll()
->shouldBeCalled()
->willReturn(
$this->arrayAsGenerator([])
);
$options = [
'key1' => 'value1'
];
$this->bigtableClient->mutateRows(self::TABLE_NAME, $this->entries, $this->options + $options)
->shouldBeCalled()
->willReturn(
$this->serverStream->reveal()
);
$rows = [
'rk1' => [
'cf1' => [
'cq1' => [
'value' => 'value1',
'timeStamp' => self::TIMESTAMP
]
]
],
'rk2' => [
'cf2' => [
'cq2' => [
'value' => 'value2',
'timeStamp' => self::TIMESTAMP
]
]
]
];
$this->dataClient->upsert($rows, $options);
}

private function getMutateRowsResponse(array $status)
{
$mutateRowsResponses = [];
Expand Down