From 874f5af6fe3f3dfb02d7a18b3dd558a7bad577d6 Mon Sep 17 00:00:00 2001 From: ajaaym <34161822+ajaaym@users.noreply.github.com> Date: Tue, 2 Oct 2018 15:38:19 -0400 Subject: [PATCH] Readrows Filter and system test (#1322) * System test for filter * update doc * throw exception if rowKeys is not array in readRows * Simplified some fitler test * use dataprovider for filter system test * formatting * address feedback --- Bigtable/src/DataClient.php | 27 +- .../tests/System/DataClientMutateRowsTest.php | 10 +- .../tests/System/DataClientReadRowsTest.php | 2 +- Bigtable/tests/System/DataClientTest.php | 10 +- Bigtable/tests/System/FilterTest.php | 451 ++++++++++++++++++ Bigtable/tests/System/data/data.json | 14 + Bigtable/tests/Unit/DataClientTest.php | 28 ++ .../Filter/Builder/QualifierFilterTest.php | 4 +- Bigtable/tests/Unit/FilterTest.php | 1 - 9 files changed, 536 insertions(+), 11 deletions(-) create mode 100644 Bigtable/tests/System/FilterTest.php create mode 100644 Bigtable/tests/System/data/data.json diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index 61a46cd4ffd5..dc33e4e2e036 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -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; @@ -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 @@ -249,6 +254,7 @@ 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( @@ -256,7 +262,14 @@ public function readRows(array $options = []) $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, @@ -266,6 +279,18 @@ public function readRows(array $options = []) ] ); } + if ($filter !== null) { + 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, diff --git a/Bigtable/tests/System/DataClientMutateRowsTest.php b/Bigtable/tests/System/DataClientMutateRowsTest.php index 1a18c9bf872b..9d9d0b6b207e 100644 --- a/Bigtable/tests/System/DataClientMutateRowsTest.php +++ b/Bigtable/tests/System/DataClientMutateRowsTest.php @@ -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); } @@ -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); } @@ -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' => [ @@ -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' => [ @@ -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' => [ diff --git a/Bigtable/tests/System/DataClientReadRowsTest.php b/Bigtable/tests/System/DataClientReadRowsTest.php index 5412dd8b6268..d6fd237454ed 100644 --- a/Bigtable/tests/System/DataClientReadRowsTest.php +++ b/Bigtable/tests/System/DataClientReadRowsTest.php @@ -115,7 +115,7 @@ public function testReadRowsSingleKey() $rows = iterator_to_array( self::$dataClient->readRows( [ - 'rowKeys' => 'rk2' + 'rowKeys' => ['rk2'] ] )->readAll() ); diff --git a/Bigtable/tests/System/DataClientTest.php b/Bigtable/tests/System/DataClientTest.php index 8642f505895e..ff23b5e6c350 100644 --- a/Bigtable/tests/System/DataClientTest.php +++ b/Bigtable/tests/System/DataClientTest.php @@ -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, diff --git a/Bigtable/tests/System/FilterTest.php b/Bigtable/tests/System/FilterTest.php new file mode 100644 index 000000000000..cc86380c1d46 --- /dev/null +++ b/Bigtable/tests/System/FilterTest.php @@ -0,0 +1,451 @@ +mutateRows(self::$rowMutations); + } + + private static function createExpectedRows($insertRows) + { + $expectedRows = $insertRows; + foreach ($expectedRows as &$row) { + foreach ($row as &$family) { + foreach ($family as &$qualifier) { + $qualifier['labels'] = ''; + $qualifier = [$qualifier]; + } + } + } + return $expectedRows; + } + + /** + * @dataProvider filterProvider + */ + public function testFilter($args, $expectedRows, $message) + { + $rows = iterator_to_array( + self::$dataClient->readRows($args)->readAll() + ); + $this->assertEquals($expectedRows, $rows, $message); + } + + public function filterProvider() + { + $text = file_get_contents(__DIR__ . '/data/data.json'); + $data = explode(PHP_EOL, $text); + $insertRows = []; + foreach ($data as $row) { + $row = json_decode($row, true); + foreach ($row as $rowKey => $family) { + $rowMutation = new RowMutation($rowKey); + $insertRows[$rowKey] = $family; + foreach ($family as $familyName => $qualifier) { + foreach ($qualifier as $qualifierName => $value) { + $rowMutation->upsert($familyName, $qualifierName, $value['value'], $value['timeStamp']); + } + } + self::$rowMutations[] = $rowMutation; + } + } + $expectedRows = self::createExpectedRows($insertRows); + return [ + [ + [ + 'rowKeys' => ['rk1'], + 'filter' => Filter::chain() + ->addFilter(Filter::family()->exactMatch('cf1')) + ->addFilter(Filter::value()->exactMatch('value1')) + ], + [ + 'rk1' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk1']['cf1']['cq1'] + ] + ] + ], + 'testChain failed' + ], + [ + [ + 'filter' => Filter::condition(Filter::key()->exactMatch('rk1')) + ->then(Filter::family()->exactMatch('cf1')) + ], + [ + 'rk1' => [ + 'cf1' => $expectedRows['rk1']['cf1'] + ] + ], + 'testConditionThen failed' + ], + [ + [ + 'filter' => Filter::condition(Filter::qualifier()->exactMatch('cq20')) + ->otherwise(Filter::key()->exactMatch('rk1')) + ], + [ + 'rk1' => $expectedRows['rk1'] + ], + 'testConditionOtherwise failed' + ], + [ + [ + 'rowKeys' => ['rk1'], + 'filter' => Filter::family()->exactMatch('cf1') + ], + [ + 'rk1' => [ + 'cf1' => $expectedRows['rk1']['cf1'] + ] + ], + 'testFamilyExactMatch failed' + ], + [ + [ + 'rowKeys' => ['rk1'], + 'filter' => Filter::family()->regex('cf[12]+') + ], + [ + 'rk1' => [ + 'cf1' => $expectedRows['rk1']['cf1'], + 'cf2' => $expectedRows['rk1']['cf2'], + ] + ], + 'testFamilyRegex failed' + ], + [ + [ + 'rowKeys' => ['rk5'], + 'filter' => Filter::interleave() + ->addFilter(Filter::qualifier()->exactMatch('cq1')) + ->addFilter(Filter::qualifier()->exactMatch('cq2')) + ], + [ + 'rk5' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk5']['cf1']['cq1'], + 'cq2' => $expectedRows['rk5']['cf1']['cq2'] + ] + ] + ], + 'testInterleave failed' + ], + [ + [ + 'filter' => Filter::key()->exactMatch('rk1') + ], + [ + 'rk1' => $expectedRows['rk1'] + ], + 'testKeyExactMatch failed' + ], + [ + [ + 'filter' => Filter::key()->regex('rk[12]+') + ], + [ + 'rk1' => $expectedRows['rk1'], + 'rk2' => $expectedRows['rk2'] + ], + 'testKeyRegex failed' + ], + [ + [ + 'rowKeys' => ['rk1', 'rk2'], + 'filter' => Filter::limit()->cellsPerRow(2) + ], + [ + 'rk1' => [ + 'cf0' => [ + 'cq0' => $expectedRows['rk1']['cf0']['cq0'], + 'cq1' => $expectedRows['rk1']['cf0']['cq1'] + ] + ], + 'rk2' => [ + 'cf0' => [ + 'cq0' => $expectedRows['rk2']['cf0']['cq0'], + 'cq1' => $expectedRows['rk2']['cf0']['cq1'] + ] + ] + ], + 'testLimitCellsPerRow failed' + ], + [ + [ + 'rowKeys' => ['rk8', 'rk9'], + 'filter' => Filter::limit()->cellsPerColumn(2) + ], + [ + 'rk8' => [ + 'cf0' => [ + 'cq0' => [ + [ + 'value' => 'value1002', + 'timeStamp' => 5000, + 'labels' => '' + ], + [ + 'value' => 'value1001', + 'timeStamp' => 4000, + 'labels' => '' + ] + ], + 'cq1' => [ + [ + 'value' => 'value1012', + 'timeStamp' => 5000, + 'labels' => '' + ], + [ + 'value' => 'value1011', + 'timeStamp' => 4000, + 'labels' => '' + ] + ] + ] + ], + 'rk9' => [ + 'cf0' => [ + 'cq0' => [ + [ + 'value' => 'value1002', + 'timeStamp' => 5000, + 'labels' => '' + ], + [ + 'value' => 'value1001', + 'timeStamp' => 4000, + 'labels' => '' + ] + ], + 'cq1' => [ + [ + 'value' => 'value1012', + 'timeStamp' => 5000, + 'labels' => '' + ], + [ + 'value' => 'value1011', + 'timeStamp' => 4000, + 'labels' => '' + ] + ] + ] + ] + ], + 'testLimitCellsPerColumn failed' + ], + [ + [ + 'rowKeys' => ['rk1', 'rk2'], + 'filter' => Filter::offset()->cellsPerRow(90) + ], + [ + 'rk1' => [ + 'cf9' => $expectedRows['rk1']['cf9'] + ], + 'rk2' => [ + 'cf9' => $expectedRows['rk2']['cf9'] + ] + ], + 'testOffsetCellsPerRow failed' + ], + [ + [ + 'rowKeys' => ['rk5'], + 'filter' => Filter::qualifier()->exactMatch('cq1') + ], + [ + 'rk5' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk5']['cf1']['cq1'] + ] + ] + ], + 'testQualifierExactMatch failed' + ], + [ + [ + 'rowKeys' => ['rk5'], + 'filter' => Filter::qualifier()->regex('cq[12]+') + ], + [ + 'rk5' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk5']['cf1']['cq1'], + 'cq2' => $expectedRows['rk5']['cf1']['cq2'] + ] + ] + ], + 'testQualifierRegex failed' + ], + [ + [ + 'rowKeys' => ['rk6'], + 'filter' => Filter::qualifier()->rangeWithinFamily('cf1')->of('cq1', 'cq3') + ], + [ + 'rk6' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk6']['cf1']['cq1'], + 'cq2' => $expectedRows['rk6']['cf1']['cq2'] + ] + ] + ], + 'testQualifierRangeWithinFamily failed' + ], + [ + [ + 'rowKeys' => ['rk1'], + 'filter' => Filter::pass() + ], + [ + 'rk1' => $expectedRows['rk1'] + ], + 'testPass failed' + ], + [ + [ + 'filter' => Filter::block() + ], + [], + 'testBlock failed' + ], + [ + [ + 'rowKeys' => ['rk1'], + 'filter' => Filter::sink() + ], + [ + 'rk1' => $expectedRows['rk1'] + ], + 'testSink failed' + ], + [ + [ + 'rowKeys' => ['rk5'], + 'filter' => Filter::timestamp()->range()->of(3000, 5000) + ], + [ + 'rk5' => [ + 'cf1' => [ + 'cq2' => $expectedRows['rk5']['cf1']['cq2'], + 'cq3' => $expectedRows['rk5']['cf1']['cq3'] + ] + ] + ], + 'testTimestampRange failed' + ], + [ + [ + 'rowKeys' => ['rk5'], + 'filter' => Filter::value()->exactMatch('value1') + ], + [ + 'rk5' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk5']['cf1']['cq1'] + ] + ] + ], + 'testValueExactMatch failed' + ], + [ + [ + 'rowKeys' => ['rk5'], + 'filter' => Filter::value()->regex('value[12]+') + ], + [ + 'rk5' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk5']['cf1']['cq1'], + 'cq2' => $expectedRows['rk5']['cf1']['cq2'] + ] + ] + ], + 'testValueRegex failed' + ], + [ + [ + 'rowKeys' => ['rk5'], + 'filter' => Filter::value()->range()->of('value1', 'value3') + ], + [ + 'rk5' => [ + 'cf1' => [ + 'cq1' => $expectedRows['rk5']['cf1']['cq1'], + 'cq2' => $expectedRows['rk5']['cf1']['cq2'] + ] + ] + ], + 'testValueRange failed' + ], + [ + [ + 'rowKeys' => ['rk7'], + 'filter' => Filter::value()->strip() + ], + [ + 'rk7' => [ + 'cf1' => [ + 'cq1' => [[ + 'value' => '', + 'labels' => '', + 'timeStamp' => 2000 + ]] + ] + ] + ], + 'testValueStrip failed' + ], + ]; + } + + public function testSample() + { + $rowFilter = Filter::key()->sample(.50); + $rows = iterator_to_array( + self::$dataClient->readRows( + [ + 'filter' => $rowFilter + ] + )->readAll() + ); + $this->assertGreaterThan(0, count($rows)); + } + + public function testLabel() + { + //TODO Implement label test + } +} diff --git a/Bigtable/tests/System/data/data.json b/Bigtable/tests/System/data/data.json new file mode 100644 index 000000000000..7499420130dd --- /dev/null +++ b/Bigtable/tests/System/data/data.json @@ -0,0 +1,14 @@ +{"rk0":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf1":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf2":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf3":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf4":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf5":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf6":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf7":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf8":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf9":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}}}} +{"rk1":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf1":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf2":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf3":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf4":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf5":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf6":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf7":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf8":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf9":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}}}} +{"rk2":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf1":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf2":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf3":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf4":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf5":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf6":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf7":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf8":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf9":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}}}} +{"rk3":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000}}}} +{"rk4":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000}}}} +{"rk5":{"cf1":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}}}} +{"rk6":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf1":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf2":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf3":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf4":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf5":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf6":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf7":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf8":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}},"cf9":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000},"cq2":{"value":"value2","timeStamp":3000},"cq3":{"value":"value3","timeStamp":4000},"cq4":{"value":"value4","timeStamp":5000},"cq5":{"value":"value5","timeStamp":6000},"cq6":{"value":"value6","timeStamp":7000},"cq7":{"value":"value7","timeStamp":8000},"cq8":{"value":"value8","timeStamp":9000},"cq9":{"value":"value9","timeStamp":10000}}}} +{"rk7":{"cf1":{"cq1":{"value":"value1","timeStamp":2000}}}} +{"rk8":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000}}}} +{"rk9":{"cf0":{"cq0":{"value":"value0","timeStamp":1000},"cq1":{"value":"value1","timeStamp":2000}}}} +{"rk8":{"cf0":{"cq0":{"value":"value1001","timeStamp":4000},"cq1":{"value":"value1011","timeStamp":4000}}}} +{"rk9":{"cf0":{"cq0":{"value":"value1001","timeStamp":4000},"cq1":{"value":"value1011","timeStamp":4000}}}} +{"rk8":{"cf0":{"cq0":{"value":"value1002","timeStamp":5000},"cq1":{"value":"value1012","timeStamp":5000}}}} +{"rk9":{"cf0":{"cq0":{"value":"value1002","timeStamp":5000},"cq1":{"value":"value1012","timeStamp":5000}}}} \ No newline at end of file diff --git a/Bigtable/tests/Unit/DataClientTest.php b/Bigtable/tests/Unit/DataClientTest.php index 53c74aa88ee4..4e3b2d4fd078 100644 --- a/Bigtable/tests/Unit/DataClientTest.php +++ b/Bigtable/tests/Unit/DataClientTest.php @@ -28,6 +28,7 @@ use Google\Cloud\Bigtable\V2\MutateRowsResponse\Entry; use Google\Cloud\Bigtable\V2\RowRange; use Google\Cloud\Bigtable\V2\RowSet; +use Google\Cloud\Bigtable\Filter; use Google\Rpc\Code; use Google\Rpc\Status; use PHPUnit\Framework\TestCase; @@ -519,6 +520,33 @@ public function testReadRowsWithKeyAndRanges() $this->assertInstanceOf(ChunkFormatter::class, $iterator); } + public function testReadRowsWithFilter() + { + $rowFilter = Filter::pass(); + $expectedArgs = $this->options + [ + 'filter' => $rowFilter->toProto() + ]; + $this->bigtableClient->readRows(self::TABLE_NAME, $expectedArgs) + ->shouldBeCalled() + ->willReturn( + $this->serverStream->reveal() + ); + $args = [ + 'filter' => $rowFilter + ]; + $iterator = $this->dataClient->readRows($args); + $this->assertInstanceOf(ChunkFormatter::class, $iterator); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage FilterInterface + */ + public function testReadRowsFilterShouldThrow() + { + $this->dataClient->readRows(['filter' => new \stdClass()]); + } + private function getMutateRowsResponse(array $status) { $mutateRowsResponses = []; diff --git a/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php b/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php index 8d1b6f0a34c2..8725d5a0a962 100644 --- a/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php +++ b/Bigtable/tests/Unit/Filter/Builder/QualifierFilterTest.php @@ -54,11 +54,11 @@ public function testExactMatch() $this->assertEquals($rowFilter, $filter->toProto()); } - public function testRangeWithInFamily() + public function testRangeWithinFamily() { $this->assertInstanceOf( QualifierRangeFilter::class, - $this->qualifierFilter->rangeWithInFamily('cf1') + $this->qualifierFilter->rangeWithinFamily('cf1') ); } } diff --git a/Bigtable/tests/Unit/FilterTest.php b/Bigtable/tests/Unit/FilterTest.php index 2a6e537aea5b..103cc0dcccd7 100644 --- a/Bigtable/tests/Unit/FilterTest.php +++ b/Bigtable/tests/Unit/FilterTest.php @@ -18,7 +18,6 @@ namespace Google\Cloud\Bigtable\Tests\Unit; use Google\Cloud\Bigtable\Filter; - use Google\Cloud\Bigtable\Filter\Builder\FamilyFilter; use Google\Cloud\Bigtable\Filter\Builder\KeyFilter; use Google\Cloud\Bigtable\Filter\Builder\LimitFilter;