Table Store filters are used to filter results that the server reads so that the server only returns the rows or columns matching the filtering conditions. Filters are applicable to the column_filter parameter of the GetRow, BatchGetRow, and GetRange operations.

Currently, Table Store only supports SingleColumnValueFilter and CompositeColumnValueFilter, which are used to determine whether to filter out the data of a row based on reference column values. SingleColumnValueFilter only checks the value of a single reference column, whereas CompositeColumnValueFilter checks the values of multiple reference columns and forms a logical combination of the check results to determine whether to filter out the data of a row.

Note that the filters are used to filter the data that has been read. Therefore, the reference columns used by SingleColumnValueFilter or CompositeColumnValueFilter must be included in the read data. If you specify the columns from which data is read but these columns do not include any reference columns, the filters cannot obtain reference column values. When a reference column does not exist, SingleColumnValueFilter uses the pass_if_missing parameter to determine whether the filtering conditions are met. That is, you can select an action even when no reference column exists.

Format

    'column_filter' => <ColumnFilter>
		

The structure of SingleColumnValueFilter is as follows:

    [
        'column_name' => '<string>',
        'value' => <ColumnValue>,
        'comparator' => <ComparatorType>
        'pass_if_missing' => true || false
        'latest_version_only' => true || false
    ]
		

The structure of CompositeColumnValueFilter is as follows:

    [
        'logical_operator' => <LogicalOperator>
        'sub_filters' => [
            <ColumnFilter>,
            <ColumnFilter>,
            <ColumnFilter>,
            // Other conditions
        ]
    ]
		

Format description

column_filter: the filtering condition.

  • Example 1
    The following code provides an example of how to construct a SingleColumnValueFilter:
        // Set the filter so that a row is returned if the value of Col0 is 0.
        $column_filter = [
            'column_name' => 'Col0',
            'value' => 0,
            'comparator' => ComparatorTypeConst::CONST_EQUAL 
            'pass_if_missing' => false                         // If a row does not contain the Col0 column, the row is not returned.
            'latest_version_only' => true                      // Only the values of the latest version is checked.
        ];
    					
  • Example 2

    The following code provides an example of how to construct a CompositeColumnValueFilter:

        // The condition composite1 is (Col0 = 0) AND (Col1 > 100).
        $composite1 = [
            'logical_operator' => LogicalOperatorConst::CONST_AND,
            'sub_filters' => [
                [
                    'column_name' => 'Col0',
                    'value' => 0,
                    'comparator' => ComparatorTypeConst::CONST_EQUAL
                ],
                [
                    'column_name' => 'Col1',
                    'value' => 100,
                    'comparator' => ComparatorTypeConst::CONST_GREATER_THAN
                ]
            ]
        ];
        // The condition composite2 is ( (Col0 = 0) AND (Col1 > 100) ) OR (Col2 <= 10).
        $composite2 = [
            'logical_operator' => LogicalOperatorConst::CONST_OR,
            'sub_filters' => [
                $composite1,
                [
                    'column_name' => 'Col2',
                    'value' => 10,
                    'comparator' => ComparatorTypeConst::CONST_LESS_EQUAL
                ]
            ]
        ];