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

Readrows Filter and system test #1322

Merged
merged 7 commits into from
Oct 2, 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
27 changes: 26 additions & 1 deletion Bigtable/src/DataClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Google\ApiCore\ApiException;
use Google\ApiCore\Serializer;
use Google\Cloud\Bigtable\Exception\BigtableDataOperationException;
use Google\Cloud\Bigtable\Filter\FilterInterface;
use Google\Cloud\Bigtable\V2\BigtableClient as TableClient;
use Google\Cloud\Bigtable\V2\RowRange;
use Google\Cloud\Bigtable\V2\RowSet;
Expand Down Expand Up @@ -241,6 +242,10 @@ public function upsert(array $rows, array $options = [])
* associative array which may contain a start key
* (`startKeyClosed` or `startKeyOpen`) and/or an end key
* (`endKeyOpen` or `endKeyClosed`).
* @type FilterInterface $filter A filter used to take an input row and
* produce an alternate view of the row based on the specified rules.
* To learn more please see {@see Google\Cloud\Bigtable\Filter} which
* provides static factory methods for the various filter types.
* @type int $rowsLimit The number of rows to scan.
* }
* @return ChunkFormatter
Expand All @@ -249,14 +254,22 @@ public function readRows(array $options = [])
{
$rowKeys = $this->pluck('rowKeys', $options, false) ?: [];
$ranges = $this->pluck('rowRanges', $options, false) ?: [];
$filter = $this->pluck('filter', $options, false) ?: null;

array_walk($ranges, function (&$range) {
$range = $this->serializer->decodeMessage(
new RowRange(),
$range
);
});

if (!is_array($rowKeys)) {
throw new \InvalidArgumentException(
sprintf(
'Expected rowKeys to be of type array, instead got \'%s\'.',
gettype($rowKeys)
)
);
}
if ($ranges || $rowKeys) {
$options['rows'] = $this->serializer->decodeMessage(
new RowSet,
Expand All @@ -266,6 +279,18 @@ public function readRows(array $options = [])
]
);
}
if ($filter !== null) {

This comment was marked as spam.

if (!$filter instanceof FilterInterface) {
throw new \InvalidArgumentException(
sprintf(
'Expected filter to be of type \'%s\', instead got \'%s\'.',
FilterInterface::class,
gettype($filter)
)
);
}
$options['filter'] = $filter->toProto();
}

$serverStream = $this->bigtableClient->readRows(
$this->tableName,
Expand Down
10 changes: 5 additions & 5 deletions Bigtable/tests/System/DataClientMutateRowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testBasicWriteAndReadDataOperation()
]
]
];
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => 'rk1'])->readAll());
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk1']])->readAll());
$this->assertEquals($readRows, $rows);
}

Expand All @@ -70,7 +70,7 @@ public function testDeleteRow()
$rowMutation = new RowMutation('rk2');
$rowMutation->deleteRow();
self::$dataClient->mutateRows([$rowMutation]);
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => 'rk2'])->readAll());
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk2']])->readAll());
$this->assertEquals([], $rows);
}

Expand All @@ -96,7 +96,7 @@ public function testDeleteFromFamily()
$rowMutation = new RowMutation('rk3');
$rowMutation->deleteFromFamily('cf2');
self::$dataClient->mutateRows([$rowMutation]);
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => 'rk3'])->readAll());
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk3']])->readAll());
$expectedRows = [
'rk3' => [
'cf1' => [
Expand Down Expand Up @@ -131,7 +131,7 @@ public function testDeleteFromColumn()
$rowMutation = new RowMutation('rk4');
$rowMutation->deleteFromColumn('cf1', 'cq2');
self::$dataClient->mutateRows([$rowMutation]);
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => 'rk4'])->readAll());
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk4']])->readAll());
$expectedRows = [
'rk4' => [
'cf1' => [
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testDeleteFromColumnWithRange()
$rowMutation = new RowMutation('rk5');
$rowMutation->deleteFromColumn('cf1', 'cq2', ['start' => 21000, 'end' => 40000]);
self::$dataClient->mutateRows([$rowMutation]);
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => 'rk5'])->readAll());
$rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk5']])->readAll());
$expectedRows = [
'rk5' => [
'cf1' => [
Expand Down
2 changes: 1 addition & 1 deletion Bigtable/tests/System/DataClientReadRowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testReadRowsSingleKey()
$rows = iterator_to_array(
self::$dataClient->readRows(
[
'rowKeys' => 'rk2'
'rowKeys' => ['rk2']
]
)->readAll()
);
Expand Down
10 changes: 9 additions & 1 deletion Bigtable/tests/System/DataClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ private static function createTable()
$table = new Table();
$columnFamily = new ColumnFamily();
$table->setColumnFamilies([
'cf0' => $columnFamily,
'cf1' => $columnFamily,
'cf2' => $columnFamily
'cf2' => $columnFamily,
'cf3' => $columnFamily,
'cf4' => $columnFamily,
'cf5' => $columnFamily,
'cf6' => $columnFamily,
'cf7' => $columnFamily,
'cf8' => $columnFamily,
'cf9' => $columnFamily
]);
self::$tableAdminClient->createTable(
$formattedParent,
Expand Down
Loading