edit-icon download-icon

Filter

Last Updated: Mar 20, 2018

Table Store can re-filter the read results on the service side to limit the amount of data transmitted on the network.

The internal node of the tree-structured filter is a logical operator (CompositeColumnCondition) and its leaf nodes are comparison operators (SingleColumnCondition).

  • CompositeColumnCondition supports AND, OR, and NOT. Two or more sub-nodes can be mounted on AND and OR. Only one node can be mounted on NOT.

  • SingleColumnCondition supports all 6 comparison conditions (EQUAL TO, NOT EQUAL TO, GREATER THAN, LESS THAN, GREATER THAN OR EQUAL TO, LESS THAN OR EQUAL TO).

  • Each SingleColumnCondition object supports comparing a column (which can be a primary key column) with a constant. Comparing two columns or two constants is not supported.

  • The latestVersionOnly parameter of SingleColumnCondition controls how multiple versions of the column value are involved in the comparison. The default value is “true”.

    • If true, only the latest version of the column value, falling within the specified range of versions, is involved in the comparison. (These column values are only involved in the comparison. If the filter accepts this row, other versions of the column value are still returned.)

    • If false, when any column value satisfies the conditions, the node considers it true.

  • The passIfMissing parameter of SingleColumnCondition controls what values the node is to consider if the column value is missing. The default value is “false”.

The filter acts on the results of other conditional filters. Therefore, if a column in the filter is not specified in the specified column read, or if no column value within the range of versions exists, the filter considers this column to be missing.

Example

The following example filters out from the table all rows that meet this condition: the primary key column pkey is greater than 1 and the attribute column attr is equal to “A”.

  1. RangeQueryCriterion query;
  2. query.mutableTable() = kTableName;
  3. query.mutableMaxVersions().reset(1);
  4. {
  5. PrimaryKey& start = query.mutableInclusiveStart();
  6. start.append() = PrimaryKeyColumn(
  7. "pkey",
  8. PrimaryKeyValue::toInfMin());
  9. }
  10. {
  11. PrimaryKey& end = query.mutableExclusiveEnd();
  12. end.append() = PrimaryKeyColumn(
  13. "pkey",
  14. PrimaryKeyValue::toInfMax());
  15. }
  16. {
  17. // set filter
  18. shared_ptr<ColumnCondition> pkeyCond(
  19. new SingleColumnCondition(
  20. "pkey",
  21. SingleColumnCondition::kLarger,
  22. AttributeValue::toInteger(1)));
  23. shared_ptr<ColumnCondition> attrCond(
  24. new SingleColumnCondition(
  25. "attr",
  26. SingleColumnCondition::kEqual,
  27. AttributeValue::toStr("A")));
  28. shared_ptr<CompositeColumnCondition> top(new CompositeColumnCondition());
  29. top->mutableOp() = CompositeColumnCondition::kAnd;
  30. top->mutableChildren().append() = pkeyCond;
  31. top->mutableChildren().append() = attrCond;
  32. query.mutableFilter() = top;
  33. }
Thank you! We've received your feedback.