Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaaym committed Oct 18, 2018
1 parent 0aa47f5 commit 57f9aa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
23 changes: 10 additions & 13 deletions Bigtable/src/DataClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ private function convertToArray(Row $row)
* Example:
* ```
* $rowKeyStream = $dataClient->sampleRowKeys();
* $rowKeys = iterator_to_array($rowKeyStream);
*
* print_r($rowKeys);
* foreach ($rowKeyStream as $rowKey) {
* print_r($rowKey) . PHP_EOL;
* }
* ```
*
* @param array $options [optional] Configuration options.
* @return \Generator
* @return \Generator<array> A list of associative arrays, each with the keys `rowKey` and `offset`.
* @throws ApiException if the remote call fails or operation fails
*/
public function sampleRowKeys(array $options = [])
Expand All @@ -429,14 +429,11 @@ public function sampleRowKeys(array $options = [])
$options + $this->options
);

$callable = (function () use ($stream) {
foreach ($stream->readAll() as $response) {
yield [
'rowKey' => $response->getRowKey(),
'offset' => $response->getOffsetBytes()
];
};
});
return $callable();
foreach ($stream->readAll() as $response) {
yield [
'rowKey' => $response->getRowKey(),
'offset' => $response->getOffsetBytes()
];
}
}
}
13 changes: 2 additions & 11 deletions Bigtable/tests/Snippet/DataClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,6 @@ public function testSampleRowKeys()
$sampleRowKeyResponses[] = (new SampleRowKeysResponse)
->setRowKey('rk1')
->setOffsetBytes(1);
$sampleRowKeyResponses[] = (new SampleRowKeysResponse)
->setRowKey('rk2')
->setOffsetBytes(2);

$this->serverStream->readAll()
->shouldBeCalled()
Expand All @@ -374,14 +371,8 @@ public function testSampleRowKeys()
$snippet->addLocal('dataClient', $this->dataClient);
$res = $snippet->invoke('rowKeys');
$expectedRowKeys = [
[
'rowKey' => 'rk1',
'offset' => 1
],
[
'rowKey' => 'rk2',
'offset' => 2
]
'rowKey' => 'rk1',
'offset' => 1
];
$this->assertEquals(
print_r($expectedRowKeys, true),
Expand Down

0 comments on commit 57f9aa3

Please sign in to comment.