# Cloud Bigtable Client - Class Filter (2.25.0)

2.25.0 (latest) 2.24.0 2.23.0 2.22.0 2.21.1 2.20.2 2.19.2 2.18.0 2.17.1 2.16.0 2.15.0 2.14.0 2.13.0 2.12.0 2.11.1 2.9.1 2.8.0 2.7.0 2.6.3 2.5.0 2.4.0 2.3.0 2.2.1 2.1.0 2.0.1 1.32.1 1.31.1 1.30.0 1.29.2 1.28.3 1.27.0 1.26.2 1.25.0 1.24.1 1.23.0 1.22.2 1.21.1 1.20.3 Reference documentation and code samples for the Cloud Bigtable Client class Filter.

This class houses static factory methods which can be used to create a
hierarchy of filters for use with
[Table::checkAndMutateRow()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Table#_Google_Cloud_Bigtable_Table__checkAndMutateRow__) or
[Table::readRows()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Table#_Google_Cloud_Bigtable_Table__readRows__).

Filters are used to take an input row and produce an alternate view of the
row based on the specified rules. For example, a filter might trim down a row
to include just the cells from columns matching a given regular expression,
or might return all the cells of a row but not their values. More complicated
filters can be composed out of these components to express requests such as,
"within every column of a particular family, give just the two most recent
cells which are older than timestamp X."

There are two broad categories of filters (true filters and transformers),
as well as two ways to compose simple filters into more complex ones
(chains and interleaves). They work as follows:

True filters alter the input row by excluding some of its cells wholesale
from the output row. An example of a true filter is
[Filter\\Builder\\ValueFilter::regex()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.ValueFilter#_Google_Cloud_Bigtable_Filter_Builder_ValueFilter__regex__), which excludes
cells whose values don't match the specified pattern. All regex true filters
use [RE2 syntax](https://github.com/google/re2/wiki/Syntax) in raw byte mode
(RE2::Latin1), and are evaluated as full matches. An important point to keep
in mind is that `RE2(.)` is equivalent by default to `RE2([^\n])`, meaning
that it does not match newlines.

Transformers alter the input row by changing the values of some of its cells
in the output, without excluding them completely. An example of such a
transformer is [Filter\\Builder\\ValueFilter::strip()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.ValueFilter#_Google_Cloud_Bigtable_Filter_Builder_ValueFilter__strip__).

The total serialized size of a filter message must not
exceed 4096 bytes, and filters may not be nested within each other
(in Chains or Interleaves) to a depth of more than 20.

Example:

    use Google\Cloud\Bigtable\BigtableClient;
    use Google\Cloud\Bigtable\Filter;

    $bigtable = new BigtableClient();
    $table = $bigtable->table('my-instance', 'my-table');
    $rowFilter = Filter::chain()
        ->addFilter(Filter::qualifier()->regex('prefix.*'))
        ->addFilter(Filter::limit()->cellsPerRow(10));

    $rows = $table->readRows([
        'filter' => $rowFilter
    ]);

    foreach ($rows as $row) {
        print_r($row) . PHP_EOL;
    }

## Namespace

Google \\ Cloud \\ Bigtable

## Methods

### static::chain

Creates an empty chain filter.

Filters can be added to the chain by invoking
[Filter\\ChainFilter::addFilter()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ChainFilter#_Google_Cloud_Bigtable_Filter_ChainFilter__addFilter__).

The filters are applied in sequence, progressively narrowing the results.
The full chain is executed atomically.

Conceptually, the process looks like the following:
`in row -> filter0 -> intermediate row -> filter1 -> ... -> filterN -> out row`.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::chain()
        ->addFilter(Filter::qualifier()->regex('prefix.*'))
        ->addFilter(Filter::limit()->cellsPerRow(10));

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ChainFilter` |   |

### static::interleave

Creates an empty interleave filter.

Filters can be added to the interleave by invoking
[Filter\\InterleaveFilter::addFilter()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.InterleaveFilter#_Google_Cloud_Bigtable_Filter_InterleaveFilter__addFilter__).

The supplied filters all process a copy of the input row, and the
results are pooled, sorted, and combined into a single output row. If
multiple cells are produced with the same column and timestamp, they will
all appear in the output row in an unspecified mutual order. The full
chain is executed atomically.

Consider the following example, with three filters:

                                     input row
                                         |
               ---
               |                         |                         |
            filter1                   filter2                   filter3
               |                         |                         |
        1: foo,bar,10,x             foo,bar,10,z              far,bar,7,a
        2: foo,blah,11,z            far,blah,5,x              far,blah,5,x
               |                         |                         |
               ---
                                         |
        1:                      foo,bar,10,z   // could have switched with #2
        2:                      foo,bar,10,x   // could have switched with #1
        3:                      foo,blah,11,z
        4:                      far,bar,7,a
        5:                      far,blah,5,x   // identical to #6
        6:                      far,blah,5,x   // identical to #5

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::interleave()
        ->addFilter(Filter::key()->regex('prefix.*'))
        ->addFilter(Filter::sink());

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.InterleaveFilter` |   |

### static::condition

Creates a condition filter.

If the result of predicate filter outputs any cells the filter configured
by [Filter\\ConditionFilter::then()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ConditionFilter#_Google_Cloud_Bigtable_Filter_ConditionFilter__then__) will be
applied. Conversely, if the predicate results in no cells, the filter
configured by
[Filter\\ConditionFilter::otherwise()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ConditionFilter#_Google_Cloud_Bigtable_Filter_ConditionFilter__otherwise__) will
then be applied instead.

IMPORTANT NOTE: The predicate filter does not execute atomically with the
[Filter\\ConditionFilter::then()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ConditionFilter#_Google_Cloud_Bigtable_Filter_ConditionFilter__then__)
and [Filter\\ConditionFilter::otherwise()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ConditionFilter#_Google_Cloud_Bigtable_Filter_ConditionFilter__otherwise__)
filters, which may lead to inconsistent or unexpected results.
Additionally, [Filter\\ConditionFilter](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ConditionFilter) may
have poor performance, especially when filters are set for the
[Filter\\ConditionFilter::otherwise()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ConditionFilter#_Google_Cloud_Bigtable_Filter_ConditionFilter__otherwise__).

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::condition(Filter::key()->regex('prefix.*'))
        ->then(Filter::label('hasPrefix'))
        ->otherwise(Filter::value()->strip());

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `predicateFilter` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.FilterInterface` A predicate filter. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ConditionFilter` |   |

### static::key

Returns a builder used to configure row key filters.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::key()
        ->regex('prefix.*');

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.KeyFilter` |   |

### static::family

Returns a builder used to configure column family filters.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::family()
        ->regex('prefix.*');

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.FamilyFilter` |   |

### static::qualifier

Returns a builder used to configure column qualifier filters.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::qualifier()
        ->regex('prefix.*');

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.QualifierFilter` |   |

### static::timestamp

Returns a builder used to configure timestamp related filters.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::timestamp()
        ->range()
        ->of(1536766964380000, 1536766964383000);

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.TimestampFilter` |   |

### static::value

Returns a builder used to configure value related filters.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::value()
        ->range()
        ->of('a', 'z');

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.ValueFilter` |   |

### static::offset

Returns a builder used to configure offset related filters.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::offset()
        ->cellsPerRow(1);

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.OffsetFilter` |   |

### static::limit

Returns a builder used to configure limit related filters.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::limit()
        ->cellsPerRow(1);

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.Builder.LimitFilter` |   |

### static::pass

Matches all cells, regardless of input. Functionally equivalent to having
no filter.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::pass();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Filter\SimpleFilter` |   |

### static::block

Does not match any cells, regardless of input. Useful for temporarily
disabling just part of a filter.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::block();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Filter\SimpleFilter` |   |

### static::sink

Outputs all cells directly to the output of the read rather than to any
parent filter. For advanced usage,
[see comments in](https://github.com/googleapis/googleapis/blob/master/google/bigtable/v2/data.proto)
for more detail.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::sink();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Filter\SimpleFilter` |   |

### static::label

Applies the given label to all cells in the output row. This allows the
caller to determine which results were produced from which part of the
filter.

Due to technical limitation, it is not currently possible to apply
multiple labels to a cell. As a result, a
[Filter\\ChainFilter](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.ChainFilter) may have no more than one
sub-filter which contains a label. It is okay for a
[Filter\\InterleaveFilter](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.InterleaveFilter) to contain multiple
labels, as they will be applied to separate copies of the input. This may
be relaxed in the future.

Example:

    use Google\Cloud\Bigtable\Filter;

    $rowFilter = Filter::label('my-label');

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `string` The label to apply. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Filter\SimpleFilter` |   |