Tablestore filters are used to filter the query results on the server side. The server returns only the rows or columns that match the filtering conditions. Filters can be used for GetRow, BatchGetRow, and GetRange operations.

Filter types

The following filters can be used to filter rows based on the reference column values.
  • SingleColumnCondition: determines whether to filter a row based only on the values of a reference column.
  • CompositeColumnCondition: determines whether to filter a row by combining the values of multiple reference columns.
Note You must include the reference columns in the query results. If the columns to be queried do not include any reference columns, the filters do not obtain any values. When a specified reference column does not exist, SingleColumnCondition uses the configured pass_if_missing parameter to determine whether the filtering conditions are met and what operation to perform if a reference column does not exist.

Examples

  • Construct SingleColumnCondition
    def get_row_with_condition(client):
        primary_key = [('uid',1), ('gid',101)]
        columns_to_get = [] # given a list of columns to get, or empty list if you want to get entire row.
        // Configure the filter. Specify to return rows in which the value of name is Hangzhou.
        cond = SingleColumnCondition("name", 'Hangzhou', ComparatorType.EQUAL, pass_if_missing = True)
        consumed, return_row, next_token = client.get_row(table_name, primary_key, columns_to_get, cond, 1)
    
        print ('Read succeed, consume %s read cu.' % consumed.read)
    
        print ('Value of primary key: %s' % return_row.primary_key)
        print ('Value of attribute: %s' % return_row.attribute_columns)
        for att in return_row.attribute_columns:
            print ('name:%s\tvalue:%s\ttimestamp:%d' % (att[0], att[1], att[2]))
  • Construct CompositeColumnCondition
    def get_row_with_composite_condition(client):
        primary_key = [('uid',1), ('gid',101)]
        columns_to_get = [] # given a list of columns to get, or empty list if you want to get entire row.
        // Configure the filter. Specify to return rows in which the value of growth is 0.9 and the value of name is Hangzhou.
        cond = CompositeColumnCondition(LogicalOperator.AND)
        cond.add_sub_condition(SingleColumnCondition("growth", 0.9, ComparatorType.NOT_EQUAL))
        cond.add_sub_condition(SingleColumnCondition("name", 'Hangzhou', ComparatorType.EQUAL))
    
        consumed, return_row, next_token = client.get_row(table_name, primary_key, columns_to_get, cond, 1)
    
        print ('Read succeed, consume %s read cu.' % consumed.read)
    
        print ('Value of primary key: %s' % return_row.primary_key)
        print ('Value of attribute: %s' % return_row.attribute_columns)
        for att in return_row.attribute_columns:
            print ('name:%s\tvalue:%s\ttimestamp:%d' % (att[0], att[1], att[2]))