Using > TicTac AAE Fold:
Filters

Filter by bucket name

This will reduce the number of keys checked.

Buckets without a bucket type

Use the name of the bucket as a binary. For example, to query bucket “cars”, one would use:

<<"cars">>

This example will count the number of keys in the bucket “cars”:

riak_client:aae_fold({
    object_stats,
    <<"cars">>,
    all,
    all
    }, Client).

How to get the value for Client is detailed in The Riak Client.

Buckets with a bucket type

Use the name of the bucket type and the bucket as a tuple pair of binaries. For example, to query bucket “dogs” with bucket type “animals”, one would use:

{<<"animals">>, <<"dogs">>}

This example will count the number of keys in the bucket “dogs” of bucket type “animals”:

riak_client:aae_fold({
    object_stats,
    {<<"animals">>, <<"dogs">>},
    all,
    all
    }, Client).

How to get the value for Client is detailed in The Riak Client.

Filter by key range

This will reduce the number of keys checked.

From -> To

TicTacAAE stores keys in a bucket in a tree, so if you want a key starting with n you would have to go through all keys starting with a to m before reaching your starting point - and then continue on past to the very last key. This is very inefficient if you want only a specific subset of keys. Thankfully, TicTacAAE’s trees are sorted by keyname, and you can make aae_fold jump straight to any key before starting and then automatically stop at any later key using the key range filter.

Use the name of the key you want to start and end at as a tuple pair of binaries. For example, to query keys starting with n, you would filter by n to o:

{<<"n">>, <<"o">>}

This example will count the number of keys in the bucket cars that start with n:

riak_client:aae_fold({
    object_stats,
    <<"cars">>,
    {<<"n">>,<<"o">>},
    all
    }, Client).

How to get the value for Client is detailed in The Riak Client.

Warning: case sensitive

As the values used for key filters are binary strings, they are case sensitive. So a and A are not the same.

All keys

To query all keys, just use all for the key range filter. This will count all keys in the bucket cars:

riak_client:aae_fold({
    object_stats,
    <<"cars">>,
    all,
    all
    }, Client).

How to get the value for Client is detailed in The Riak Client.

Filter by segment

This filter is used internally by TictacAAE and for custom replication functions. It’s usage is not covered by this guide.

Use all for this filter.

Filter by date modified

This will not reduce the number of keys checked, but will reduce the number of keys returned.

This filter is used when you need to locate keys modified in a certain time frame.

The values are passed in a tuple with 3 values:

{date,From,To}

date is required. From and To are seconds since 1970-01-01 00:00:00.

For example, to get all keys modified between 1970-01-01 00:01:00 (From = 60) and 1970-01-01 00:02:00 (To = 120), one would use:

{date,60,120}

This example returns all keys in the “cars” bucket that were modified between 1970-01-01 00:01:00 and 1970-01-01 00:02:00:

riak_client:aae_fold({
    object_stats,
    <<"cars">>,
    all,
    {date,60,120}
    }, Client).

How to get the value for Client is detailed in The Riak Client.

Working out the number of seconds

The number of seconds can be worked out using this helper function:

Modified_Filter_Calculator = fun (StartDateTime, EndDateTime) ->
  EpochTime = calendar:datetime_to_gregorian_seconds({{1970,1,1},{0,0,0}}),
  LowTS = calendar:datetime_to_gregorian_seconds(StartDateTime) - EpochTime,
  HighTS = calendar:datetime_to_gregorian_seconds(EndDateTime) - EpochTime,
  {date, LowTS, HighTS}
end.

This can then be used like so to get the filter value for the range of “2022-01-01 00:00:00” to “2022-02-01 00:00:00” (i.e. all of January 2022):

Modified_Filter_Value = Modified_Filter_Calculator(
  {{2022,1,1},{0,0,0}},
  {{2022,2,1},{0,0,0}}
),
riak_client:aae_fold({
    object_stats,
    <<"cars">>,
    all,
    Modified_Filter_Value
    }, Client).

Or in one command to make it easily re-usable:

riak_client:aae_fold({
    object_stats,
    <<"cars">>,
    all,
    Modified_Filter_Calculator({{2022,1,1},{0,0,0}}, {{2022,2,1},{0,0,0}})
    }, Client).

Filter by sibling count

This will not reduce the number of keys checked, but will reduce the number of keys returned.

This filter is used when you need to locate keys with more than a given number of siblings. It can only be used with find_keys.

Learn More >>

Filter by object size

This will not reduce the number of keys checked, but will reduce the number of keys returned.

This filter is used when you need to locate keys whose object size is greater than a specified value. It can only be used with find_keys.

Learn More >>