Dealing with Predicate Expression Filters in Aerospike REST Client (Part 2)

Diving deeper

Eugene Rizhkov
Aerospike Developer Blog
3 min readApr 26, 2020

--

Photo by Adi Goldstein on Unsplash

In the previous part we spoke about using simple Predicate Expression Filters with the Aerospike REST Client. In this post I want to dive deeper and show how special filter operators could come in handy.

LAST_UPDATE

Asserts the last update time before processing the transaction.

Parameters:

  • comparison operator
  • time in seconds since the epoch time (1970–01–01)

Example:

Java equivalent:

VOID_TIME

Asserts the record’s expiration time before processing the transaction.

Parameters:

  • comparison operator
  • time in seconds since the epoch time (1970–01–01)

Example:

Java equivalent:

DIGEST_MODULO

Asserts a modulo against the record’s digest. The 160 bits (20 Bytes) digest field is generated by hashing the set name and the user key using the RipeMD-160 hashing function.

Parameters:

  • modulo divisor
  • comparison operator
  • expected remainder value

Example for digest(key) % 3 == 1:

Java equivalent:

STRING_REGEX

Asserts that the regular expression matches the string valued bin.

Parameters:

  • string bin name
  • regular expression

Example:

Java equivalent:

LIST_ITERATE_OR

Creates a predicate expression to match any item in a list value bin.

Parameters:

  • list bin name
  • comparison operator
  • value

Example:

Find records where any list item v = “hello” in list bin x.

Java equivalent:

LIST_ITERATE_AND

Creates a predicate expression to match all items in a list value bin.

Parameters:

  • list bin name
  • comparison operator
  • value

Example:

Find records where all list elements v != “world” in list bin x.

Java equivalent:

MAPKEY_ITERATE_OR

Creates a predicate expression to match any map key.

Parameters:

  • map bin name
  • comparison operator
  • value

Example:

Find records where any map key k = 7 in map bin m.

Java equivalent:

MAPVAL_ITERATE_OR

Creates a predicate expression to match any map value.

Parameters:

  • map bin name
  • comparison operator
  • value

Example:

Find records where any map value v > 100 in map bin m.

Java equivalent:

MAPKEY_ITERATE_AND

Creates a predicate expression to match all map keys.

Parameters:

  • map bin name
  • comparison operator
  • value

Example:

Find records where all map keys k < 5 in map bin m.

Java equivalent:

MAPVAL_ITERATE_AND

Creates a predicate expression to match all map values.

Parameters:

  • map bin name
  • comparison operator
  • value

Example:

Find records where all map values v > 500 in map bin m.

Java equivalent:

At the end you can glue those with logical operators (and | or) mixing with simple filters, Base64-encode the whole expression and send it as a GET parameter.

To summarize, we’ve seen that Predicate Expression Filters are a very powerful tool and learned how to use them with the Aerospike REST Client.

If you still haven’t tried Aerospike REST Client and want to do so, you can find it here. I have more code examples here: https://github.com/aerospike-examples/rest-client-usage

Deprecation Note

As of Aerospike Database 5.2, Predicate Expressions (PredExps) are obsolete, and are scheduled for removal in version 5.8. Please use Aerospike Expressions instead. The REST gateway adds the ability to attach an Expression filter in release 1.9.0.

--

--