Module: aerospike/exp

This module defines a filter expression that is a mechanism for additional filtering.

The resultset of a primary index (PI) query (scan) or secondary index (SI) query operation can be filtered through the QueryPolicy and ScanPolicy classes. It can also filter single key operations and batch operations through the filterExpression field of their policy class.

Filter Expressions replace PredicateExpression filtering, which was deprecated in server 5.2 and removed in server 6.0.

Source:
See:

Examples

Expressions using the operate API

const Aerospike = require('aerospike')
const op = Aerospike.operations
const exp = Aerospike.exp
const key = new Aerospike.Key('test', 'demo', 'mykey1')
const tempBin = 'ExpVar' // this bin is to hold expression read operation output

// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
const config = {  
  hosts: '192.168.33.10:3000',
  // Timeouts disabled, latency dependent on server location. Configure as needed.
  policies: {
    operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0}),
    write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0})
  }
}
  
var ops = [
  op.append('a', 'xyz'),
  op.incr('b', 10),
  exp.operations.read(tempBin,
          exp.add(exp.binInt('b'), exp.binInt('b')),
         0),
  op.read('a'),
  op.read('b')
]

Aerospike.connect(config, (error, client) => {
  if (error) throw error
  client.put(key, { a: 'abc', b: 42 }, (error) => {
    if (error) throw error
    client.operate(key, ops, (error, record) => {
      if (error) throw error
      console.log(record.bins) // => { a: 'abcxyz', b: 52, ExpVar: 104 }
      client.close()
    })
  })
})

Expressions using the query API

const Aerospike = require('aerospike')
const op = Aerospike.operations
const exp = Aerospike.exp
const key = new Aerospike.Key('test', 'demo', 'mykey1')
const tempBin = 'ExpVar' // this bin is to hold expression read operation output

// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
const config = {  
  hosts: '192.168.33.10:3000',
  // Timeouts disabled, latency dependent on server location. Configure as needed.
  policies: {
    query : new Aerospike.QueryPolicy({socketTimeout : 0, totalTimeout : 0}),
    write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0, exists : Aerospike.policy.exists.REPLACE})
  }
}

Aerospike.connect(config, (error, client) => {
  if (error) throw error
  client.put(key, { a: 'abc', b: 42 }, (error) => {
    if (error) throw error
    var query = client.query('test', 'demo')
    const queryPolicy = { filterExpression:  exp.eq(exp.binInt('b'), exp.int(42))}
    query.nobins = false
    const stream = query.foreach(queryPolicy)
    stream.on('error', (error) => {
      console.error(error)
      throw error
    })
    stream.on('data', (record) => {
      console.info(record.bins) // => { a: 'abc', b: 42} 
    })
    stream.on('end', () => {
      client.close()
    })
  })
})

Members


<static> abs

Create operator that returns absolute value of a number. All arguments must resolve to integer or float. Requires server version 5.6.0+.

Source:

<static> add

Create "add" (+) operator that applies to a variable number of expressions. Return the sum of all arguments. All arguments must be the same type (integer or float). Requires server version 5.6.0+.

Source:

<static> and

Create "and" (&&) operator that applies to a variable number of expressions.

Source:

<static> binBlob

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

Source:

<static> binBool

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

Source:

<static> binFloat

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

Source:

<static> binGeo

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

Source:

<static> binHll

Create expression that returns a bin as a HyperLogLog (hll). Returns 'unknown' if the bin is not a HyperLogLog (hll).

Source:

<static> binInt

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

Source:

<static> binList

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

Source:

<static> binMap

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

Source:

<static> binStr

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

Source:

<static> bit

Blob expressions.

The aerospike/exp/bit module defines functions for expressions on the Blob datatype

Source:

<static> bool

Create boolean value.

Source:

<static> bytes

Create byte array value.

Source:

<static> ceil

Create expression that rounds a floating point number up to the closest integer value. Requires server version 5.6.0+.

Source:

<static> cmpGeo

Create a point within region or region contains point expression.

Source:

<static> cond

Conditionally select an expression from a variable number of expression pairs followed by default expression action. Requires server version 5.6.0+.

Source:

<static> deviceSize

Create expression that returns record size on disk. If server storage-engine is memory, then zero is returned. This expression usually evaluates quickly because record meta data is cached in memory.

Source:

<static> digestModulo

Create expression that returns record digest modulo as integer.

Source:

<static> div

Create "divide" (/) operator that applies to a variable number of expressions. If there is only one argument, returns the reciprocal for that argument. Otherwise, return the first argument divided by the product of the rest. All arguments must resolve to the same type (integer or float). Requires server version 5.6.0+.

Source:

<static> eq

Create equals (==) expression.

Source:

<static> exclusive

Create expression that returns true if only one of the expressions are true. Requires server version 5.6.0+.

Source:

<static> float

Create 64 bit floating point value.

Source:

<static> floor

Create expression that rounds a floating point number down to the closest integer value. Requires server version 5.6.0+.

Source:

<static> ge

Create a greater than or equals (>=) expression.

Source:

<static> geo

Create geojson value.

Source:

<static> gt

Create a greater than (>) expression.

Source:

<static> hll

HyperLogLog expressions.

The aerospike/exp/hll module defines functions for expressions on the HyperLogLog datatype

Source:

<static> int

Create 64 bit signed integer value.

Source:

<static> intAnd

Create integer "and" (&) operator that is applied to two or more integers. All arguments must resolve to integers. Requires server version 5.6.0+.

Source:

<static> intArshift

Create integer "arithmetic right shift" (>>) operator. Requires server version 5.6.0+.

Source:

<static> intCount

Create expression that returns count of integer bits that are set to 1. Requires server version 5.6.0+.

Source:

<static> intLscan

Create expression that scans integer bits from left (most significant bit) to right (least significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If "search" is true, the scan will search for the bit value 1. If "search" is false it will search for bit value 0. Requires server version 5.6.0+.

Source:

<static> intLshift

Create integer "left shift" (<<) operator. Requires server version 5.6.0+.

Source:

<static> intNot

Create integer "not" (~) operator. Requires server version 5.6.0+.

Source:

<static> intOr

Create integer "or" (|) operator that is applied to two or more integers. All arguments must resolve to integers. Requires server version 5.6.0+.

Source:

<static> intRscan

Create expression that scans integer bits from right (least significant bit) to left (most significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If "search" is true, the scan will search for the bit value 1. If "search" is false it will search for bit value 0. Requires server version 5.6.0+.

Source:

<static> intRshift

Create integer "logical right shift" (>>>) operator. Requires server version 5.6.0+.

Source:

<static> intXor

Create integer "xor" (^) operator that is applied to two or more integers. All arguments must resolve to integers. Requires server version 5.6.0+.

Source:

<static> isTombstone

Create expression that returns if record has been deleted and is still in tombstone state. This expression usually evaluates quickly because record meta data is cached in memory.

Source:

<static> keyBlob

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

Source:

<static> keyInt

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

Source:

<static> keyStr

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

Source:

<static> lastUpdate

Create expression that returns record last update time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch.

Source:

<static> le

Create a less than or equals (<=) expression.

Source:

<static> let

Define variables and expressions in scope. Requires server version 5.6.0+.

Source:

<static> lists

List expressions.

The aerospike/exp/lists module defines functions for expressions on the List datatype.

Source:

<static> log

Create "log" operator for logarithm of "num" with base "base". All arguments must resolve to floats. Requires server version 5.6.0+.

Source:

<static> lt

Create a less than (<) expression.

Source:

<static> maps

Map expressions.

The aerospike/exp/maps module defines functions for expressions on the Map datatype.

Source:

<static> max

Create expression that returns the maximum value in a variable number of expressions. All arguments must be the same type (integer or float). Requires server version 5.6.0+.

Source:

<static> memorySize

Create expression that returns record size in memory when either the storage-engine is memory or data-in-memory is true, otherwise returns 0. This expression usually evaluates quickly because record meta data is cached in memory. Requires server version 5.3.0+.

Source:

<static> min

Create expression that returns the minimum value in a variable number of expressions. All arguments must be the same type (integer or float). Requires server version 5.6.0+.

Source:

<static> mod

Create "modulo" (%) operator that determines the remainder of "numerator" divided by "denominator". All arguments must resolve to integers. Requires server version 5.6.0+.

Source:

<static> mul

Create "multiply" (*) operator that applies to a variable number of expressions. Return the product of all arguments. If only one argument is supplied, return that argument. All arguments must resolve to the same type (integer or float). Requires server version 5.6.0+.

Source:

<static> ne

Create not equal (!=) expression.

Source:

<static> or

Create "or" (||) operator that applies to a variable number of expressions.

Source:

<static> pow

Create "pow" operator that raises a "base" to the "exponent" power. All arguments must resolve to floats. Requires server version 5.6.0+.

Source:

<static> setName

Create expression that returns record set name string. This expression usually evaluates quickly because record meta data is cached in memory.

Source:

<static> sinceUpdate

Create expression that returns milliseconds since the record was last updated. This expression usually evaluates quickly because record meta data is cached in memory.

Source:

<static> str

Create string value.

Source:

<static> sub

Create "subtract" (-) operator that applies to a variable number of expressions. If only one argument is provided, return the negation of that argument. Otherwise, return the sum of the 2nd to Nth argument subtracted from the 1st argument. All arguments must resolve to the same type (integer or float). Requires server version 5.6.0+.

Source:

<static> toFloat

Create expression that converts an integer to a float. Requires server version 5.6.0+.

Source:

<static> toInt

Create expression that converts a float to an integer. Requires server version 5.6.0+.

Source:

<static> ttl

Create expression that returns record expiration time (time to live) in integer seconds.

Source:

<static> uint

Create 64 bit unsigned integer value.

Source:

<static> voidTime

Create expression that returns record expiration time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch.

Source:

Methods


<static> binExists(binName)

Create expression that returns if bin of specified name exists.

Parameters:
Name Type Description
binName string

Bin name.

Source:
Returns:
  • value True if the bin exists, false otherwise.
Type
boolean

<static> cmpRegex(options, regex, cmpStr)

Create expression that performs a regex match on a string bin or value expression.

Parameters:
Name Type Description
options number

POSIX regex flags defined in regex.h.

regex string

POSIX regex string.

cmpStr AerospikeExp

String expression to compare against.

Source:
Returns:
  • boolean value
Type
AerospikeExp

<static> def(varName, expr)

Assign variable to an expression that can be accessed later. Requires server version 5.6.0+.

Parameters:
Name Type Description
varName string

Variable name.

expr AerospikeExp

The variable is set to the result of expr.

Source:
Returns:

A variable name expression pair.

Type
AerospikeExp

<static> keyExist()

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

Parameters:
Type Description
boolean

value True if the record has a stored key, false otherwise.

Source:
Returns:
Type
AerospikeExp

<static> nil()

Create 'nil' value.

Source:

<static> not(expr)

Create "not" (!) operator expression.

Parameters:
Name Type Description
expr AerospikeExp

Boolean expression to negate.

Source:
Returns:
  • boolean value
Type
AerospikeExp

<static> var(varName)

Retrieve expression value from a variable. Requires server version 5.6.0+.

Parameters:
Name Type Description
varName string

Variable name.

Source:
Returns:

value stored in variable.

Type
AerospikeExp