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.
  • CompositeCondition: 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 passIfMissing parameter to determine whether the filtering conditions are met and what operation to perform if a reference column does not exist.

Examples

  • Construct SingleColumnCondition
    function getRowWithCondition() {
      // Configure the filter. Specify to return rows in which the value of col1 is Tablestore. Set passIfMissing to ture.
      var condition = new TableStore.SingleColumnCondition('col1', 'Tablestore', TableStore.ComparatorType.EQUAL,true);
    
      params.columnFilter = condition;
      client.getRow(params, function (err, data) {
        if (err) {
          console.log('error:', err);
          return;
        }
        console.log('success:', data);
      });
    }
  • Construct CompositeCondition
    function getRowWithCompositeCondition() {
      // Configure the filter. Specify to return rows in which the value of col1 is Tablestore and the value of col5 is 123456789.
      var condition = new TableStore.CompositeCondition(TableStore.LogicalOperator.AND);
      condition.addSubCondition(new TableStore.SingleColumnCondition('col1', 'Tablestore', TableStore.ComparatorType.EQUAL));
      condition.addSubCondition(new TableStore.SingleColumnCondition('col5', Long.fromNumber(123456789), TableStore.ComparatorType.EQUAL));
    
      params.columnFilter = condition;
      client.getRow(params, function (err, data) {
        if (err) {
          console.log('error:', err);
          return;
        }
        console.log('success:', data);
      });
    }