All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Expression Filters

Description

Expression filters are applied on each applicable server record. Expression filters require server version >= 5.2.0.4.

If the filter exists and evaluates to false in a single record command, the command is ignored and AEROSPIKE_FILTERED_OUT is returned as an error code.

If the filter exists and evaluates to false in a batch record row, AEROSPIKE_FILTERED_OUT is returned as a status for that record row in the batch.

If the filter exists and evaluates to false on a scan/query record, that record is not returned.

Expression filters can now be defined on all commands through the command policy (as_policy_base contained in as_policy_read, as_policy_write, ...).

Example:

as_exp_build(filter,
as_exp_cmp_eq(as_exp_bin_int("a"), as_exp_int(10)));
as_policy_read_init(&p);
p.filter_exp = filter;
...
as_exp_destroy(filter);
#define as_exp_bin_int(__bin_name)
Definition as_exp.h:479
#define as_exp_int(__val)
Definition as_exp.h:304

Macros

#define as_exp_bin_blob(__bin_name)
 
#define as_exp_bin_bool(__bin_name)
 
#define as_exp_bin_float(__bin_name)
 
#define as_exp_bin_geo(__bin_name)
 
#define as_exp_bin_int(__bin_name)
 
#define as_exp_bin_str(__bin_name)
 
#define as_exp_bool(__val)   {.op=_AS_EXP_CODE_VAL_BOOL, .v.bool_val=__val}
 
#define as_exp_bytes(__val, __size)   {.op=_AS_EXP_CODE_VAL_BYTES, .sz=__size, .v.bytes_val=__val}
 
#define as_exp_float(__val)   {.op=_AS_EXP_CODE_VAL_FLOAT, .v.float_val=__val}
 
#define as_exp_geo(__val)   {.op=_AS_EXP_CODE_VAL_GEO, .v.val=(as_val*)as_geojson_new(__val, false)}
 
#define as_exp_inf()   as_exp_val(&as_cmp_inf)
 
#define as_exp_int(__val)   {.op=_AS_EXP_CODE_VAL_INT, .v.int_val=__val}
 
#define as_exp_key_blob()
 
#define as_exp_key_exist()   {.op=_AS_EXP_CODE_KEY_EXIST, .count=1}
 
#define as_exp_key_int()
 
#define as_exp_key_str()
 
#define as_exp_nil()   as_exp_val(&as_nil)
 
#define as_exp_str(__val)   {.op=_AS_EXP_CODE_VAL_STR, .v.str_val=__val}
 
#define as_exp_uint(__val)   {.op=_AS_EXP_CODE_VAL_UINT, .v.uint_val=__val}
 
#define as_exp_unknown()   {.op=_AS_EXP_CODE_UNKNOWN, .count=1}
 
#define as_exp_val(__val)   {.op=_AS_EXP_CODE_AS_VAL, .v.val=(as_val*)(__val)}
 
#define as_exp_wildcard()   as_exp_val(&as_cmp_wildcard)
 

Functions

AS_EXTERN void as_exp_destroy (as_exp *exp)
 
static void as_exp_destroy_base64 (char *base64)
 
AS_EXTERN as_expas_exp_from_base64 (const char *base64)
 
static char * as_exp_to_base64 (as_exp *exp)
 

Macro Definition Documentation

◆ as_exp_bin_blob

#define as_exp_bin_blob ( __bin_name)
Value:
{.op=_AS_EXP_CODE_BIN, .count=3}, \
as_exp_int(AS_EXP_TYPE_BLOB), \
_AS_EXP_VAL_RAWSTR(__bin_name)
@ AS_EXP_TYPE_BLOB
Definition as_exp.h:173

Create expression that returns a bin as a blob. Returns 'unknown' if the bin is not an blob.

// Integer bin "a" == { 0x65, 0x65 }
uint8_t val[] = {0x65, 0x65}
as_exp_build(expression,
as_exp_cmp_eq(as_exp_bin_blob("a"), as_exp_bytes(val, sizeof(val))));
#define as_exp_bin_blob(__bin_name)
Definition as_exp.h:537
#define as_exp_bytes(__val, __size)
Definition as_exp.h:337
Parameters
__bin_nameBin name.
Returns
(blob bin)

Definition at line 537 of file as_exp.h.

◆ as_exp_bin_bool

#define as_exp_bin_bool ( __bin_name)
Value:
{.op=_AS_EXP_CODE_BIN, .count=3}, \
as_exp_int(AS_EXP_TYPE_BOOL), \
_AS_EXP_VAL_RAWSTR(__bin_name)
@ AS_EXP_TYPE_BOOL
Definition as_exp.h:168

Create expression that returns a bin as a boolean value. Returns 'unknown' if the bin is not a boolean.

// Check if the value in bin "a" is true.
as_exp_build(expression, as_exp_bin_bool("a"));
#define as_exp_bin_bool(__bin_name)
Definition as_exp.h:460
Parameters
__bin_nameBin name.
Returns
(boolean bin)

Definition at line 460 of file as_exp.h.

◆ as_exp_bin_float

#define as_exp_bin_float ( __bin_name)
Value:
{.op=_AS_EXP_CODE_BIN, .count=3}, \
as_exp_int(AS_EXP_TYPE_FLOAT), \
_AS_EXP_VAL_RAWSTR(__bin_name)
@ AS_EXP_TYPE_FLOAT
Definition as_exp.h:174

Create expression that returns a bin as a float. Returns 'unknown' if the bin is not an float.

// Float bin "a" >= 2.71
as_exp_build(expression,
as_exp_cmp_ge(as_exp_bin_int("a"), as_exp_float(2.71)));
#define as_exp_float(__val)
Definition as_exp.h:320
Parameters
__bin_nameBin name.
Returns
(float bin)

Definition at line 498 of file as_exp.h.

◆ as_exp_bin_geo

#define as_exp_bin_geo ( __bin_name)
Value:
{.op=_AS_EXP_CODE_BIN, .count=3}, \
as_exp_int(AS_EXP_TYPE_GEOJSON), \
_AS_EXP_VAL_RAWSTR(__bin_name)
@ AS_EXP_TYPE_GEOJSON
Definition as_exp.h:175

Create expression that returns a bin as a geojson. Returns 'unknown' if the bin is not geojson.

// GeoJSON bin "a" contained by GeoJSON bin "b"
as_exp_build(expression,
as_exp_cmp_geo(as_exp_bin_geo("a"), as_exp_bin_geo("b")));
#define as_exp_bin_geo(__bin_name)
Definition as_exp.h:556
Parameters
__bin_nameBin name.
Returns
(geojson bin)

Definition at line 556 of file as_exp.h.

◆ as_exp_bin_int

#define as_exp_bin_int ( __bin_name)
Value:
{.op=_AS_EXP_CODE_BIN, .count=3}, \
as_exp_int(AS_EXP_TYPE_INT), \
_AS_EXP_VAL_RAWSTR(__bin_name)
@ AS_EXP_TYPE_INT
Definition as_exp.h:169

Create expression that returns a bin as a signed integer. Returns 'unknown' if the bin is not an integer.

// Integer bin "a" == 200
as_exp_build(expression,
as_exp_cmp_eq(as_exp_bin_int("a"), as_exp_int(200)));
Parameters
__bin_nameBin name.
Returns
(integer bin)

Definition at line 479 of file as_exp.h.

◆ as_exp_bin_str

#define as_exp_bin_str ( __bin_name)
Value:
{.op=_AS_EXP_CODE_BIN, .count=3}, \
as_exp_int(AS_EXP_TYPE_STR), \
_AS_EXP_VAL_RAWSTR(__bin_name)
@ AS_EXP_TYPE_STR
Definition as_exp.h:170

Create expression that returns a bin as a string. Returns 'unknown' if the bin is not an string.

// String bin "a" == "b"
as_exp_build(expression,
as_exp_cmp_eq(as_exp_bin_str("a"), as_exp_str("b")));
#define as_exp_str(__val)
Definition as_exp.h:328
#define as_exp_bin_str(__bin_name)
Definition as_exp.h:517
Parameters
__bin_nameBin name.
Returns
(string bin)

Definition at line 517 of file as_exp.h.

◆ as_exp_bool

#define as_exp_bool ( __val)    {.op=_AS_EXP_CODE_VAL_BOOL, .v.bool_val=__val}

Create boolean value.

Parameters
__valboolean value.

Definition at line 296 of file as_exp.h.

◆ as_exp_bytes

#define as_exp_bytes ( __val,
__size )   {.op=_AS_EXP_CODE_VAL_BYTES, .sz=__size, .v.bytes_val=__val}

Create byte array value.

Parameters
__valbyte array value.
__sizenumber of bytes.

Definition at line 337 of file as_exp.h.

◆ as_exp_float

#define as_exp_float ( __val)    {.op=_AS_EXP_CODE_VAL_FLOAT, .v.float_val=__val}

Create 64 bit floating point value.

Parameters
__valfloating point value.

Definition at line 320 of file as_exp.h.

◆ as_exp_geo

#define as_exp_geo ( __val)    {.op=_AS_EXP_CODE_VAL_GEO, .v.val=(as_val*)as_geojson_new(__val, false)}

Create geojson value.

Parameters
__valgeojson value.

Definition at line 345 of file as_exp.h.

◆ as_exp_inf

#define as_exp_inf ( )    as_exp_val(&as_cmp_inf)

Create infinity value.

Definition at line 365 of file as_exp.h.

◆ as_exp_int

#define as_exp_int ( __val)    {.op=_AS_EXP_CODE_VAL_INT, .v.int_val=__val}

Create 64 bit signed integer value.

Parameters
__valinteger value.

Definition at line 304 of file as_exp.h.

◆ as_exp_key_blob

#define as_exp_key_blob ( )
Value:
{.op=_AS_EXP_CODE_KEY, .count=2}, \
as_exp_int(AS_EXP_TYPE_BLOB)

Create expression that returns the key as an blob. Returns 'unknown' if the key is not an blob.

// Blob record key <= { 0x65, 0x65 }
uint8_t val[] = {0x65, 0x65}
as_exp_build(expression,
as_exp_cmp_le(as_exp_key_blob(), as_exp_bytes(val, sizeof(val))));
#define as_exp_key_blob()
Definition as_exp.h:423
Returns
(blob value) Blob value of the key if the key is a blob.

Definition at line 423 of file as_exp.h.

◆ as_exp_key_exist

#define as_exp_key_exist ( )    {.op=_AS_EXP_CODE_KEY_EXIST, .count=1}

Create expression that returns if the primary key is stored in the record meta data as a boolean expression. This would occur when "as_policy_write.key" is AS_POLICY_KEY_SEND on record write.

// Key exists in record meta data
as_exp_build(expression, as_exp_key_exists());
Returns
(boolean value) True if the record has a stored key, false otherwise.

Definition at line 439 of file as_exp.h.

◆ as_exp_key_int

#define as_exp_key_int ( )
Value:
{.op=_AS_EXP_CODE_KEY, .count=2}, \
as_exp_int(AS_EXP_TYPE_INT)

Create expression that returns the key as an integer. Returns 'unknown' if the key is not an integer.

// Integer record key >= 10000
as_exp_build(expression,
as_exp_cmp_ge(as_exp_key_int(), as_exp_int(10000)));
#define as_exp_key_int()
Definition as_exp.h:390
Returns
(integer value) Integer value of the key if the key is an integer.

Definition at line 390 of file as_exp.h.

◆ as_exp_key_str

#define as_exp_key_str ( )
Value:
{.op=_AS_EXP_CODE_KEY, .count=2}, \
as_exp_int(AS_EXP_TYPE_STR)

Create expression that returns the key as an string. Returns 'unknown' if the key is not a string.

// String record key == "aaa"
as_exp_build(expression,
as_exp_cmp_eq(as_exp_key_str(), as_exp_str("aaa")));
#define as_exp_key_str()
Definition as_exp.h:406
Returns
(string value) String value of the key if the key is a string.

Definition at line 406 of file as_exp.h.

◆ as_exp_nil

#define as_exp_nil ( )    as_exp_val(&as_nil)

Create 'nil' value.

Definition at line 359 of file as_exp.h.

◆ as_exp_str

#define as_exp_str ( __val)    {.op=_AS_EXP_CODE_VAL_STR, .v.str_val=__val}

Create string value.

Parameters
__valstring value.

Definition at line 328 of file as_exp.h.

◆ as_exp_uint

#define as_exp_uint ( __val)    {.op=_AS_EXP_CODE_VAL_UINT, .v.uint_val=__val}

Create 64 bit unsigned integer value.

Parameters
__valunsigned integer value.

Definition at line 312 of file as_exp.h.

◆ as_exp_unknown

#define as_exp_unknown ( )    {.op=_AS_EXP_CODE_UNKNOWN, .count=1}

Create an 'unknown' value. Used to intentionally fail an expression. The failure can be ignored with AS_EXP_WRITE_EVAL_NO_FAIL or AS_EXP_READ_NO_FAIL. Requires server version 5.6.0+.

// If var("v") (bin("balance") - 100.0) is greater that or equal to 0.0 then
// return var("v") else fail operation.
as_exp_build(expression,
as_exp_let(
as_exp_def("v", as_exp_sub(
as_exp_bin_float("balance"), as_exp_float(100.0))),
as_exp_cond(
as_exp_ge(as_exp_var("v"), as_exp_float(0)), as_exp_var("v"),
#define as_exp_unknown()
Definition as_exp.h:288
#define as_exp_bin_float(__bin_name)
Definition as_exp.h:498
Returns
(unknown value)

Definition at line 288 of file as_exp.h.

◆ as_exp_val

#define as_exp_val ( __val)    {.op=_AS_EXP_CODE_AS_VAL, .v.val=(as_val*)(__val)}

Create value from an as_val.

Parameters
__valas_val value.

Definition at line 353 of file as_exp.h.

◆ as_exp_wildcard

#define as_exp_wildcard ( )    as_exp_val(&as_cmp_wildcard)

Create wildcard value.

Definition at line 371 of file as_exp.h.

Function Documentation

◆ as_exp_destroy()

AS_EXTERN void as_exp_destroy ( as_exp * exp)

Free expression bytes.

◆ as_exp_destroy_base64()

static void as_exp_destroy_base64 ( char * base64)
inlinestatic

Free base64 string.

Definition at line 258 of file as_exp.h.

References as_exp_destroy_b64().

◆ as_exp_from_base64()

AS_EXTERN as_exp * as_exp_from_base64 ( const char * base64)

Decode null-terminated base64 string to expression. Call as_exp_destroy() when done with expression.

◆ as_exp_to_base64()

static char * as_exp_to_base64 ( as_exp * exp)
inlinestatic

Encode expression to null-terminated base64 string. Call as_exp_destroy_base64() when done with base64 string.

Definition at line 232 of file as_exp.h.

References as_exp_compile_b64().