aerospike_helpers.expressions package

Classes for the creation and use of Aerospike Expressions. See:: Aerospike Expressions.

Aerospike Expressions are a small domain specific language that allow for filtering records in transactions by manipulating and comparing bins and record metadata. Expressions can be used everywhere that predicate expressions have been used and allow for expanded functionality and customizability.

In the Python client, Aerospike expressions are built using a series of classes that represent comparison and logical operators, bins, metadata operations, and bin operations. Expressions are constructed using a Lisp like syntax by instantiating an expression that yields a boolean, such as Eq() or And(), while passing them other expressions and constants as arguments, and finally calling the compile() method. See the example below.

Example:

# See if integer bin "bin_name" contains a value equal to 10.
from aerospike_helpers import expressions as exp
expr = exp.Eq(exp.IntBin("bin_name"), 10).compile()

By passing these compiled expressions to transactions via the “expressions” policy field, the expressions will filter the results. See the example below.

Example:

import aerospike
from aerospike_helpers import expressions as exp
from aerospike import exception as ex
import sys

TEST_NS = "test"
TEST_SET = "demo"
FIRST_RECORD_INDEX = 0
SECOND_RECORD_INDEX = 1
BIN_INDEX = 2

# Configure the client.
config = {"hosts": [("127.0.0.1", 3000)]}

# Create a client and connect it to the cluster.
try:
    client = aerospike.client(config).connect()
except ex.ClientError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
    sys.exit(1)

# Write records
keys = [(TEST_NS, TEST_SET, i) for i in range(1, 5)]
records = [
            {'user': "Chief"     , 'team': "blue", 'scores': [6, 12, 4, 21], 'kd': 1.0,  'status': "MasterPlatinum" },
            {'user': "Arbiter"   , 'team': "blue", 'scores': [5, 10, 5, 8] , 'kd': 1.0,  'status': "MasterGold"     },
            {'user': "Johnson"   , 'team': "blue", 'scores': [8, 17, 20, 5], 'kd': 0.99, 'status': "SergeantGold"   },
            {'user': "Regret"    , 'team': "red" , 'scores': [4, 2, 3, 5]  , 'kd': 0.33, 'status': "ProphetSilver"  }
        ]

try:
    for key, record in zip(keys, records):
        client.put(key, record)
except ex.RecordError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))


# EXAMPLE 1: Get records for users who's top scores are above 20 using a scan.
try:
    expr = exp.GT(exp.ListGetByRank(None, aerospike.LIST_RETURN_VALUE, exp.ResultType.INTEGER, -1, exp.ListBin("scores")), # rank -1 == largest value
                    20).compile()

    scan = client.scan(TEST_NS, TEST_SET)
    policy = {
        'expressions': expr
    }

    records = scan.results(policy)
    # This scan will only return the record for "Chief" since it is the only account with a score over 20 using batch get.
    print(records[FIRST_RECORD_INDEX][BIN_INDEX])
except ex.AerospikeError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
    sys.exit(1)

# EXPECTED OUTPUT:
# {'user': 'Chief', 'team': 'blue', 'scores': [6, 12, 4, 21], 'kd': 1.0, 'status': 'MasterPlatinum'}


# EXAMPLE 2: Get player's records with a kd >= 1.0 with a status including "Gold".
try:
    expr = exp.And(
        exp.CmpRegex(aerospike.REGEX_ICASE, '.*Gold', exp.StrBin('status')),
        exp.GE(exp.FloatBin("kd"), 1.0)).compile()

    policy = {
        'expressions': expr
    }

    records = client.get_many(keys, policy)
    # This get_many will only return the record for "Arbiter" since it is the only account with a kd >= 1.0 and Gold status.
    print(records[SECOND_RECORD_INDEX][BIN_INDEX])
except ex.AerospikeError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
    sys.exit(1)
finally:
    client.close()

# EXPECTED OUTPUT:
# {'user': 'Arbiter', 'team': 'blue', 'scores': [5, 10, 5, 8], 'kd': 1.0, 'status': 'MasterGold'}

By nesting expressions, complicated filters can be created. See the example below.

Example:

from aerospike_helpers import expressions as exp
expr = Eq(
    exp.ListGetByIndexRangeToEnd(ctx, aerospike.LIST_RETURN_VALUE, 0,
        exp.ListSort(ctx, aerospike.LIST_SORT_DEFAULT,
            exp.ListAppend(ctx, policy, value_x,
                exp.ListAppendItems(ctx, policy, value_y,
                    exp.ListInsert(ctx, policy, 1, value_z, bin_name))))),
    expected_answer
),

Note

Aerospike expressions are evaluated server side, expressions used for filtering are called filter-expressions and do not return any values to the client or write any values to the server.

When the following documentation says an expression returns a “list expression”, it means that the expression returns a list during evalution on the server side.

Expressions used with expression_read() or expression_write() do send their return values to the client or write them to the server. These expressions are called operation-expressions.

When these docs say that an expression parameter requires an “integer or integer expression”. It means it will accept a literal integer, or an expression that will return an integer during evaluation.

When the docs say an expression returns an “expression” this means that the data type returned may vary, usually depending on the return_type parameter.

Note

Currently, Aerospike expressions for the python client do not support comparing as_python_bytes blobs. Comparisons between constant map values and map expressions are also unsupported.

Expression Type Aliases

The expressions module documentaiton uses type aliases. The following is a table of how the type aliases map to standard types.

Title

Type Name

Type Description

AerospikeExpression

_BaseExpr

TypeResultType

Optional[int]

TypeFixedEle

Union[int, float, str, bytes, dict]

TypeFixed

Optional[Dict[str, TypeFixedEle]]

TypeCompiledOp

Tuple[int, TypeResultType, TypeFixed, int]

TypeExpression

List[TypeCompiledOp]

TypeChild

Union[int, float, str, bytes, _AtomExpr]

TypeChildren

Tuple[TypeChild, …]

TypeBinName

Union[_BaseExpr, str]

TypeListValue

Union[_BaseExpr, List[Any]]

TypeIndex

Union[_BaseExpr, int, aerospike.CDTInfinite]

TypeCTX

Union[None, List[cdt_ctx._cdt_ctx]]

TypeRank

Union[_BaseExpr, int, aerospike.CDTInfinite]

TypeCount

Union[_BaseExpr, int, aerospike.CDTInfinite]

TypeValue

Union[_BaseExpr, Any]

TypePolicy

Union[Dict[str, Any], None]

TypeComparisonArg

Union[_BaseExpr, int, str, list, dict, aerospike.CDTInfinite]

TypeGeo

Union[_BaseExpr, aerospike.GeoJSON]

TypeKey

Union[_BaseExpr, Any]

TypeKeyList

Union[_BaseExpr, List[Any]]

TypeBitValue

Union[bytes, bytearray]

TypeNumber

Union[_BaseExpr, int, float]

TypeFloat

Union[_BaseExpr, float]

TypeInteger

Union[_BaseExpr, int]

TypeBool

Union[_BaseExpr, bool]

Note

Requires server version >= 5.2.0

aerospike_helpers.expressions.basemodule

The expressions base module provide expressions for
  • declaring variables, using variables, and control-flow

  • comparison operators

  • applying logical operators to one or more ‘boolean expressions’

  • returning the value of (in-memory) record metadata

  • returning the value from storage, such as bin data or the record’s key

Example:

import aerospike_helpers.expressions.base as exp
# See if integer bin "bin_name" contains a value equal to 10.
expr = exp.Eq(exp.IntBin("bin_name"), 10).compile()
class aerospike_helpers.expressions.base.And(*exprs: _BaseExpr)

Create an “and” operator that applies to a variable amount of expressions.

__init__(*exprs: _BaseExpr)
Parameters

*exprs (_BaseExpr) – Variable amount of expressions to be ANDed together.

Returns

(boolean value)

Example:

# (a > 5 || a == 0) && b < 3
expr = exp.And(
        exp.Or(
          exp.GT(exp.IntBin("a"), 5),
          exp.Eq(exp.IntBin("a"), 0)),
        exp.LT(exp.IntBin("b"), 3)).compile()
class aerospike_helpers.expressions.base.BinExists(bin: str)

Create an expression that returns True if bin exists.

__init__(bin: str)
Parameters

bin (str) – bin name.

Returns

(boolean value): True if bin exists, False otherwise.

Example:

#Bin "a" exists in record.
expr = exp.BinExists("a").compile()
class aerospike_helpers.expressions.base.BinType(bin: str)

Create an expression that returns the type of a bin as one of the aerospike bin types

__init__(bin: str)
Parameters

bin (str) – bin name.

Returns

(integer value): returns the bin type.

Example:

# bin "a" == type string.
expr = exp.Eq(exp.BinType("a"), aerospike.AS_BYTES_STRING).compile()
class aerospike_helpers.expressions.base.BlobBin(bin: str)

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

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(blob bin)

Example:

#. Blob bin "a" == bytearray([0x65, 0x65])
expr = exp.Eq(exp.BlobBin("a"), bytearray([0x65, 0x65])).compile()
class aerospike_helpers.expressions.base.BoolBin(bin: str)

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

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(boolean bin)

Example:

# Boolean bin "a" is True.
expr = exp.BoolBin("a").compile()
class aerospike_helpers.expressions.base.CmpGeo(expr0: TypeGeo, expr1: TypeGeo)

Create a point within region or region contains point expression.

__init__(expr0: TypeGeo, expr1: TypeGeo)
Parameters
  • expr0 (TypeGeo) – Left expression in comparrison.

  • expr1 (TypeGeo) – Right expression in comparrison.

Returns

(boolean value)

Example:

# Geo bin "point" is within geo bin "region".
expr = exp.CmpGeo(GeoBin("point"), exp.GeoBin("region")).compile()
class aerospike_helpers.expressions.base.CmpRegex(options: int, regex_str: str, cmp_str: Union[_BaseExpr, str])

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

__init__(options: int, regex_str: str, cmp_str: Union[_BaseExpr, str])
Parameters
  • options (int) – One of the aerospike regex constants, Regex Flag Values.

  • regex_str (str) – POSIX regex string.

  • cmp_str (Union[_BaseExpr, str]) – String expression to compare against.

Returns

(boolean value)

Example:

# Select string bin "a" that starts with "prefix" and ends with "suffix".
# Ignore case and do not match newline.
expr = exp.CmpRegex(aerospike.REGEX_ICASE | aerospike.REGEX_NEWLINE, "prefix.*suffix", exp.StrBin("a")).compile()
class aerospike_helpers.expressions.base.Cond(*exprs: _BaseExpr)

Conditionally select an expression from a variable number of condition/action pairs, followed by a default expression action.

Takes a set of test-expression/action-expression pairs and evaluates each test expression, one at a time. If a test returns True, Cond evaluates the corresponding action expression and returns its value, after which Cond doesn’t evaluate any of the other tests or expressions. If all tests evaluate to False, the default action expression is evaluated and returned.

Cond is strictly typed, so all actions-expressions must evaluate to the same type or the Unknown expression.

Requires server version 5.6.0+.

__init__(*exprs: _BaseExpr)
Parameters

*exprs (_BaseExpr) – bool exp1, action exp1, bool exp2, action exp2, …, action-default

Returns

(boolean value)

Example:

# Apply operator based on type and test if greater than 100.
expr = exp.GT(
        exp.Cond(
            exp.Eq(exp.IntBin("type"), 0),
                exp.Add(exp.IntBin("val1"), exp.IntBin("val2")),
            exp.Eq(exp.IntBin("type"), 1),
                exp.Sub(exp.IntBin("val1"), exp.IntBin("val2")),
            exp.Eq(exp.IntBin("type"), 2),
                exp.Mul(exp.IntBin("val1"), exp.IntBin("val2")))
        100).compile()

Example:

# Delete the 'grade' bin if its value is less than 70
killif = exp.Cond(
    exp.LT(exp.IntBin("grade"), 70), aerospike.null(),
    exp.Unknown()).compile()
# Write a NIL on grade < 70 to delete the bin
# or short-circuit out of the operation without raising an exception
ops = [
    opexp.expression_write("grade", killif,
    aerospike.EXP_WRITE_ALLOW_DELETE | aerospike.EXP_WRITE_EVAL_NO_FAIL),
]
class aerospike_helpers.expressions.base.Def(var_name: str, expr: _BaseExpr)

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

__init__(var_name: str, expr: _BaseExpr)
Parameters
  • var_name (str) – Variable name.

  • expr (_BaseExpr) – Variable is set to result of this expression.

Returns

(a variabe name expression pair)

Example:

# for int bin "a", 5 < a < 10
expr = exp.Let(exp.Def("x", exp.IntBin("a")),
        exp.And(
            exp.LT(5, exp.Var("x")),
            exp.LT(exp.Var("x"), 10))).compile()
class aerospike_helpers.expressions.base.DeviceSize

Create an 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.

__init__()
Returns

(integer value): Uncompressed storage size of the record.

Example:

# Record device size >= 100 KB.
expr = exp.GE(exp.DeviceSize(), 100 * 1024).compile()
class aerospike_helpers.expressions.base.DigestMod(mod: int)

Create an expression that returns record digest modulo as integer.

__init__(mod: int)
Parameters

mod (int) – Divisor used to divide the digest to get a remainder.

Returns

(integer value): Value in range 0 and mod (exclusive).

Example:

# Records that have digest(key) % 3 == 1.
expr = exp.Eq(exp.DigestMod(3), 1).compile()
class aerospike_helpers.expressions.base.Eq(expr0: TypeComparisonArg, expr1: TypeComparisonArg)

Create an equals, (==) expression.

__init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Parameters
  • expr0 (TypeComparisonArg) – Left argument to ==.

  • expr1 (TypeComparisonArg) – Right argument to ==.

Returns

(boolean value)

Example:

# Integer bin "a" == 11
expr = exp.Eq(exp.IntBin("a"), 11).compile()
class aerospike_helpers.expressions.base.Exclusive(*exprs: _BaseExpr)

Create an expression that returns True if only one of the expressions are True.

__init__(*exprs: _BaseExpr)
Parameters

*exprs (_BaseExpr) – Variable amount of expressions to be checked.

Returns

(boolean value)

Example:

# exclusive(a == 0, b == 0)
expr = exp.Exclusive(
                exp.Eq(exp.IntBin("a"), 0),
                exp.Eq(exp.IntBin("b"), 0)).compile()
class aerospike_helpers.expressions.base.FloatBin(bin: str)

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

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(float bin)

Example:

# Float bin "a" > 2.71.
expr = exp.GT(exp.FloatBin("a"), 2.71).compile()
class aerospike_helpers.expressions.base.GE(expr0: TypeComparisonArg, expr1: TypeComparisonArg)

Create a greater than or equal to (>=) expression.

__init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Parameters
  • expr0 (TypeComparisonArg) – Left argument to >=.

  • expr1 (TypeComparisonArg) – Right argument to >=.

Returns

(boolean value)

Example:

# Integer bin "a" >= 88.
expr = exp.GE(exp.IntBin("a"), 88).compile()
class aerospike_helpers.expressions.base.GT(expr0: TypeComparisonArg, expr1: TypeComparisonArg)

Create a greater than (>) expression.

__init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Parameters
  • expr0 (TypeComparisonArg) – Left argument to >.

  • expr1 (TypeComparisonArg) – Right argument to >.

Returns

(boolean value)

Example:

# Integer bin "a" > 8.
expr = exp.GT(exp.IntBin("a"), 8).compile()
class aerospike_helpers.expressions.base.GeoBin(bin: str)

Create an expression that returns a bin as a geojson. Returns the unknown-value if the bin is not a geojson.

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(geojson bin)

Example:

#GeoJSON bin "a" contained by GeoJSON bin "b".
expr = exp.CmpGeo(GeoBin("a"), exp.GeoBin("b")).compile()
class aerospike_helpers.expressions.base.HLLBin(bin: str)

Create an expression that returns a bin as a HyperLogLog. Returns the unknown-value if the bin is not a HyperLogLog.

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(HyperLogLog bin)

Example:

# Does HLL bin "a" have a hll_count > 1000000.
expr = exp.GT(exp.HllGetCount(exp.HllBin("a"), 1000000)).compile()
class aerospike_helpers.expressions.base.IntBin(bin: str)

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

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(integer bin)

Example:

# Integer bin "a" == 200.
expr = exp.Eq(exp.IntBin("a"), 200).compile()
class aerospike_helpers.expressions.base.IsTombstone

Create an 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. NOTE: this is only applicable for XDR filter expressions.

__init__()
Returns

(boolean value): True if the record is a tombstone, false otherwise.

Example:

# Detect deleted records that are in tombstone state.
expr = exp.IsTombstone().compile()
class aerospike_helpers.expressions.base.KeyBlob

Create an expression that returns the key as a blob. Returns the unknown-value if the key is not a blob.

__init__()
Returns

(blob value): Blob value of the key if the key is a blob.

Example:

# blob record key <= bytearray([0x65, 0x65]).
expr = exp.GE(exp.KeyBlob(), bytearray([0x65, 0x65])).compile()
class aerospike_helpers.expressions.base.KeyExists

Create an expression that returns if the primary key is stored in the record storage data as a boolean expression. This would occur on record write, when write policies set the key field to aerospike.POLICY_KEY_SEND.

__init__()
Returns

(boolean value): True if the record has a stored key, false otherwise.

Example:

# Key exists in record meta data.
expr = exp.KeyExists().compile()
class aerospike_helpers.expressions.base.KeyInt

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

__init__()
Returns

(integer value): Integer value of the key if the key is an integer.

Example:

# Integer record key >= 10000.
expr = exp.GE(KeyInt(), 10000).compile()
class aerospike_helpers.expressions.base.KeyStr

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

__init__()
Returns

(string value): string value of the key if the key is an string.

Example:

# string record key == "aaa".
expr = exp.Eq(exp.KeyStr(), "aaa").compile()
class aerospike_helpers.expressions.base.LE(expr0: TypeComparisonArg, expr1: TypeComparisonArg)

Create a less than or equal to (<=) expression.

__init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Parameters
  • expr0 (TypeComparisonArg) – Left argument to <=.

  • expr1 (TypeComparisonArg) – Right argument to <=.

Returns

(boolean value)

Example:

# Integer bin "a" <= 1.
expr = exp.LE(exp.IntBin("a"), 1).compile()
class aerospike_helpers.expressions.base.LT(expr0: TypeComparisonArg, expr1: TypeComparisonArg)

Create a less than (<) expression.

__init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Parameters
  • expr0 (TypeComparisonArg) – Left argument to <.

  • expr1 (TypeComparisonArg) – Right argument to <.

Returns

(boolean value)

Example:

# Integer bin "a" < 1000.
expr = exp.LT(exp.IntBin("a"), 1000).compile()
class aerospike_helpers.expressions.base.LastUpdateTime

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

__init__()
Returns

(integer value): When the record was last updated.

Example:

# Record last update time >= 2020-01-15.
expr = exp.GE(exp.LastUpdateTime(), 1577836800).compile()
class aerospike_helpers.expressions.base.Let(*exprs: _BaseExpr)

Defines variables to be used within the Let expression’s scope. The last argument can be any expression and should make use of the defined variables. The Let expression returns the evaluated result of the last argument. This expression is useful if you need to reuse the result of a complicated or expensive expression.

__init__(*exprs: _BaseExpr)
Parameters

*exprs (_BaseExpr) – Variable number of Def expressions followed by a scoped expression.

Returns

(result of scoped expression)

Example:

# for int bin "a", 5 < a < 10
expr = exp.Let(exp.Def("x", exp.IntBin("a")),
        exp.And(
            exp.LT(5, exp.Var("x")),
            exp.LT(exp.Var("x"), 10))).compile()
class aerospike_helpers.expressions.base.ListBin(bin: str)

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

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(list bin)

Example:

# List bin "a" contains at least one item with value "abc".
expr = exp.GT(exp.ListGetByValue(None, aerospike.LIST_RETURN_COUNT,
            ResultType.INTEGER, "abc", ListBin("a")),
        0).compile()
class aerospike_helpers.expressions.base.MapBin(bin: str)

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

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(map bin)

Example:

# Map bin "a" size > 7.
expr = exp.GT(exp.MapSize(None, exp.MapBin("a")), 7).compile()
class aerospike_helpers.expressions.base.NE(expr0: TypeComparisonArg, expr1: TypeComparisonArg)

Create a not equals (not ==) expressions.

__init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Parameters
  • expr0 (TypeComparisonArg) – Left argument to not ==.

  • expr1 (TypeComparisonArg) – Right argument to not ==.

Returns

(boolean value)

Example:

# Integer bin "a" not == 13.
expr = exp.NE(exp.IntBin("a"), 13).compile()
class aerospike_helpers.expressions.base.Not(*exprs: _BaseExpr)

Create a “not” (not) operator expression.

__init__(*exprs: _BaseExpr)
Parameters

*exprs (_BaseExpr) – Variable amount of expressions to be negated.

Returns

(boolean value)

Example:

# not (a == 0 or a == 10)
expr = exp.Not(exp.Or(
            exp.Eq(exp.IntBin("a"), 0),
            exp.Eq(exp.IntBin("a"), 10))).compile()
class aerospike_helpers.expressions.base.Or(*exprs: _BaseExpr)

Create an “or” operator that applies to a variable amount of expressions.

__init__(*exprs: _BaseExpr)
Parameters

*exprs (_BaseExpr) – Variable amount of expressions to be ORed together.

Returns

(boolean value)

Example:

# (a == 0 || b == 0)
expr = exp.Or(
        exp.Eq(exp.IntBin("a"), 0),
        exp.Eq(exp.IntBin("b"), 0)).compile()
class aerospike_helpers.expressions.base.SetName

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

__init__()
Returns

(string value): Name of the set this record belongs to.

Example:

# Record set name == "myset".
expr = exp.Eq(exp.SetName(), "myset").compile()
class aerospike_helpers.expressions.base.SinceUpdateTime

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

__init__()
Returns

(integer value): Number of milliseconds since last updated.

Example:

# Record last updated more than 2 hours ago.
expr = exp.GT(exp.SinceUpdateTime(), 2 * 60 * 1000).compile()
class aerospike_helpers.expressions.base.StrBin(bin: str)

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

__init__(bin: str)
Parameters

bin (str) – Bin name.

Returns

(string bin)

Example:

# String bin "a" == "xyz".
expr = exp.Eq(exp.StrBin("a"), "xyz").compile()
class aerospike_helpers.expressions.base.TTL

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

__init__()
Returns

(integer value): Number of seconds till the record will expire, returns -1 if the record never expires.

Example:

# Record expires in less than 1 hour.
expr = exp.LT(exp.TTL(), 60 * 60).compile()
class aerospike_helpers.expressions.base.Unknown

Create an ‘Unknown’ expression, which allows an operation expression (‘read expression’ or ‘write expression’) to be aborted.

This expression returns a special ‘unknown’ trilean value which, when returned by an operation expression, will result in an error code 26 OpNotApplicable. These failures can be ignored with the policy flags aerospike.EXP_READ_EVAL_NO_FAIL for read expressions and aerospike.EXP_WRITE_EVAL_NO_FAIL for write expressions. This would then allow subsequent operations in the transaction to proceed.

This expression is only useful from a Cond conditional expression within an operation expression, and should be avoided in filter-expressions, where it might trigger an undesired move into the storage-data phase.

If a test-expression within the Cond yields the special ‘unknown’ trilean value, then the Cond will also immediately yield the ‘unknown’ value and further test-expressions will not be evaluated.

Note that this special ‘unknown’ trilean value is the same value returned by any failed expression.

__init__()
Returns

(unknown value)

Example:

# If IntBin("balance") >= 50, get "balance" + 50.
# Otherwise, fail the expression via Unknown().
# This sort of expression is useful with expression operations
# expression_read() and expression_write().
exp.Let(exp.Def("bal", exp.IntBin("balance")),
    exp.Cond(
        exp.GE(exp.Var("bal"), 50),
            exp.Add(exp.Var("bal"), 50),
        exp.Unknown())
)
class aerospike_helpers.expressions.base.Var(var_name: str)

Retrieve expression value from a variable previously defined with Def. Requires server version 5.6.0+.

__init__(var_name: str)
Parameters

var_name (str) – Variable name.

Returns

(value stored in variable)

Example:

# for int bin "a", 5 < a < 10
expr = exp.Let(exp.Def("x", exp.IntBin("a")),
        exp.And(
            exp.LT(5, exp.Var("x")),
            exp.LT(exp.Var("x"), 10))).compile()
class aerospike_helpers.expressions.base.VoidTime

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

__init__()
Returns

(integer value): Expiration time in nanoseconds since 1970-01-01.

Example:

# Record expires on 2021-01-01.
expr = exp.And(
        exp.GE(exp.VoidTime(), 1609459200),
        exp.LT(exp.VoidTime(), 1609545600)).compile()

aerospike_helpers.expressions.list module

List expressions contain expressions for reading and modifying Lists. Most of these operations are from the standard List API.

Example:

import aerospike_helpers.expressions as exp
#Take the size of list bin "a".
expr = exp.ListSize(None, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListAppend(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)

Create an expression that appends value to end of list.

__init__(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of List policies.

  • value (TypeValue) – Value or value expression to append to list.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

List expression.

Example:

# Check if length of list bin "a" is > 5 after appending 1 item.
expr = exp.GT(
        exp.ListSize(None, exp.ListAppend(None, None, 3, exp.ListBin("a"))),
        5).compile()
class aerospike_helpers.expressions.list.ListAppendItems(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)

Create an expression that appends a list of items to the end of a list.

__init__(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of List policies.

  • value (TypeValue) – List or list expression of items to be appended.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

List expression.

Example:

# Check if length of list bin "a" is > 5 after appending multiple items.
expr = exp.GT(
        exp.ListSize(None, exp.ListAppendItems(None, None, [3, 2], exp.ListBin("a"))),
        5).compile()
class aerospike_helpers.expressions.list.ListClear(ctx: TypeCTX, bin: TypeBinName)

Create an expression that removes all items in a list.

__init__(ctx: TypeCTX, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

List expression.

Example:

# Clear list value of list nested in list bin "a" index 1.
from aerospike_helpers import cdt_ctx
expr = exp.ListClear([cdt_ctx.cdt_ctx_list_index(1)], "a").compile()
class aerospike_helpers.expressions.list.ListGetByIndex(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)

Create an expression that selects list item identified by index and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values

  • value_type (int) – The value type that will be returned by this expression (ResultType).

  • index (TypeIndex) – Integer or integer expression of index to get element at.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the value at index 0 in list bin "a". (assume this value is an integer)
expr = exp.ListGetByIndex(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, 0, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByIndexRange(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName)

Create an expression that selects “count” list items starting at specified index and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • index (TypeIndex) – Integer or integer expression of index to start getting elements at.

  • count (TypeCount) – Integer or integer expression for count of elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get elements at indexes 3, 4, 5, 6 in list bin "a".
expr = exp.ListGetByIndexRange(None, aerospike.LIST_RETURN_VALUE, 3, 4, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByIndexRangeToEnd(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName)

Create an expression that selects list items starting at specified index to the end of list and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • index (TypeIndex) – Integer or integer expression of index to start getting elements at.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get element 5 to end from list bin "a".
expr = exp.ListGetByIndexRangeToEnd(None, aerospike.LIST_RETURN_VALUE, 5, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByRank(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)

Create an expression that selects list item identified by rank and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • value_type (int) – The value type that will be returned by this expression (ResultType).

  • rank (TypeRank) – Rank integer or integer expression of element to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the smallest element in list bin "a".
expr = exp.ListGetByRank(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, 0, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByRankRange(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that selects “count” list items starting at specified rank and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • rank (TypeRank) – Rank integer or integer expression of first element to get.

  • count (TypeCount) – Count integer or integer expression for how many elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the 3 smallest elements in list bin "a".
expr = exp.ListGetByRankRange(None, aerospike.LIST_RETURN_VALUE, 0, 3, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByRankRangeToEnd(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName)

Create an expression that selects list items starting at specified rank to the last ranked item and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • rank (TypeRank) – Rank integer or integer expression of first element to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the three largest elements in list bin "a".
expr = exp.ListGetByRankRangeToEnd(None, aerospike.LIST_RETURN_VALUE, -3, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByValue(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName)

Create an expression that selects list items identified by value and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • value (TypeValue) – Value or value expression of element to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the index of the element with value, 3, in list bin "a".
expr = exp.ListGetByValue(None, aerospike.LIST_RETURN_INDEX, 3, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByValueList(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName)

Create an expression that selects list items identified by values and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • value (TypeListValue) – List or list expression of values of elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

#Get the indexes of the the elements in list bin "a" with values [3, 6, 12].
expr = exp.ListGetByValueList(None, aerospike.LIST_RETURN_INDEX, [3, 6, 12], exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByValueRange(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName)

Create an expression that selects list items identified by value range and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName)

Create an expression that selects list items identified by value range and returns selected data specified by return_type.

Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • value_begin (TypeValue) – Value or value expression of first element to get.

  • value_end (TypeValue) – Value or value expression of ending element.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get rank of values between 3 (inclusive) and 7 (exclusive) in list bin "a".
expr = exp.ListGetByValueRange(None, aerospike.LIST_RETURN_RANK, 3, 7, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByValueRelRankRange(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that selects list items nearest to value and greater by relative rank with a count limit and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • value (TypeValue) – Value or vaule expression to get items relative to.

  • rank (TypeRank) – Rank intger expression. rank relative to “value” to start getting elements.

  • count (TypeCount) – Integer value or integer value expression, how many elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the next 2 values in list bin "a" larger than 3.
expr = exp.ListGetByValueRelRankRange(None, aerospike.LIST_RETURN_VALUE, 3, 1, 2, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListGetByValueRelRankRangeToEnd(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName)

Create an expression that selects list items nearest to value and greater by relative rank

__init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.

  • value (TypeValue) – Value or vaule expression to get items relative to.

  • rank (TypeRank) – Rank intger expression. rank relative to “value” to start getting elements.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the values of all elements in list bin "a" larger than 3.
expr = exp.ListGetByValueRelRankRangeToEnd(None, aerospike.LIST_RETURN_VALUE, 3, 1, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListIncrement(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)

Create an expression that increments list[index] by value.

__init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of List policies.

  • index (TypeIndex) – Index of value to increment.

  • value (TypeValue) – Value or value expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

List expression.

Example:

# Check if incremented value in list bin "a" is the largest in the list.
expr = exp.Eq(
        exp.ListGetByRank(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, -1, #rank of -1 == largest element.
            exp.ListIncrement(None, None, 1, 5, exp.ListBin("a"))),
        exp.ListGetByIndex(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, 1,
            exp.ListIncrement(None, None, 1, 5, exp.ListBin("a")))
).compile()
class aerospike_helpers.expressions.list.ListInsert(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)

Create an expression that inserts value to specified index of list.

__init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of List policies.

  • index (TypeIndex) – Target index for insertion, integer or integer expression.

  • value (TypeValue) – Value or value expression to be inserted.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

List expression.

Example:

# Check if list bin "a" has length > 5 after insert.
expr = exp.GT(
        exp.ListSize(None, exp.ListInsert(None, None, 0, 3, exp.ListBin("a"))),
        5).compile()
class aerospike_helpers.expressions.list.ListInsertItems(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, values: TypeListValue, bin: TypeBinName)

Create an expression that inserts each input list item starting at specified index of list.

__init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, values: TypeListValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of List policies.

  • index (TypeIndex) – Target index where item insertion will begin, integer or integer expression.

  • values (TypeListValue) – List or list expression of items to be inserted.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

List expression.

Example:

# Check if list bin "a" has length > 5 after inserting items.
expr = exp.GT(
        exp.ListSize(None, exp.ListInsertItems(None, None, 0, [4, 7], exp.ListBin("a"))),
        5).compile()
class aerospike_helpers.expressions.list.ListRemoveByIndex(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)

Create an expression that removes “count” list items starting at specified index.

__init__(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • index (TypeIndex) – Index integer or integer expression of element to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Get size of list bin "a" after index 3 has been removed.
expr = exp.ListSize(None, exp.ListRemoveByIndex(None, 3, exp.ListBin("a"))).compile()
class aerospike_helpers.expressions.list.ListRemoveByIndexRange(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName)

Create an expression that removes “count” list items starting at specified index.

__init__(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • index (TypeIndex) – Starting index integer or integer expression of elements to remove.

  • count (TypeCount) – Integer or integer expression, how many elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Get size of list bin "a" after index 3, 4, and 5 have been removed.
expr = exp.ListSize(None, exp.ListRemoveByIndexRange(None, 3, 3, exp.ListBin("a"))).compile()
class aerospike_helpers.expressions.list.ListRemoveByIndexRangeToEnd(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)

Create an expression that removes list items starting at specified index to the end of list.

__init__(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • index (TypeIndex) – Starting index integer or integer expression of elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Remove all elements starting from index 3 in list bin "a".
expr = exp.ListRemoveByIndexRangeToEnd(None, 3, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListRemoveByRank(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)

Create an expression that removes list item identified by rank.

__init__(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • rank (TypeRank) – Rank integer or integer expression of element to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Remove smallest value in list bin "a".
expr = exp.ListRemoveByRank(None, 0, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListRemoveByRankRange(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that removes “count” list items starting at specified rank.

__init__(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • rank (TypeRank) – Rank integer or integer expression of element to start removing at.

  • count (TypeCount) – Count integer or integer expression of elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Remove the 3 smallest items from list bin "a".
expr = exp.ListRemoveByRankRange(None, 0, 3, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListRemoveByRankRangeToEnd(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)

Create an expression that removes list items starting at specified rank to the last ranked item.

__init__(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • rank (TypeRank) – Rank integer or integer expression of element to start removing at.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Remove the 2 largest elements from List bin "a".
expr = exp.ListRemoveByRankRangeToEnd(None, -2, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListRemoveByValue(ctx: TypeCTX, value: TypeValue, bin: TypeBinName)

Create an expression that removes list items identified by value.

__init__(ctx: TypeCTX, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • value (TypeValue) – Value or value expression to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# See if list bin "a", with `3` removed, is equal to list bin "b".
expr = exp.Eq(exp.ListRemoveByValue(None, 3, exp.ListBin("a")), ListBin("b")).compile()
class aerospike_helpers.expressions.list.ListRemoveByValueList(ctx: TypeCTX, values: TypeListValue, bin: TypeBinName)

Create an expression that removes list items identified by values.

__init__(ctx: TypeCTX, values: TypeListValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • values (TypeListValue) – List of values or list expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Remove elements with values [1, 2, 3] from list bin "a".
expr = exp.ListRemoveByValueList(None, [1, 2, 3], exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListRemoveByValueRange(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName)

Create an expression that removes list items identified by value range (begin inclusive, end exclusive). If begin is None, the range is less than end. If end is None, the range is greater than or equal to begin.

__init__(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • begin (TypeValue) – Begin value or value expression for range.

  • end (TypeValue) – End value or value expression for range.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Remove list of items with values >= 3 and < 7 from list bin "a".
expr = exp.ListRemoveByValueRange(None, 3, 7, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListRemoveByValueRelRankRange(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that removes list items nearest to value and greater by relative rank with a count limit.

__init__(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • value (TypeValue) – Start value or value expression.

  • rank (TypeRank) – Rank integer or integer expression.

  • count (TypeCount) – How many elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# After removing the 3 elements larger than 4 by relative rank, does list bin "a" include 9?.
expr = exp.GT(
        exp.ListGetByValue(None, aerospike.LIST_RETURN_COUNT, 9,
            exp.ListRemoveByValueRelRankRange(None, 4, 1, 0, exp.ListBin("a"))),
        0).compile()
class aerospike_helpers.expressions.list.ListRemoveByValueRelRankToEnd(ctx: TypeCTX, value: TypeValue, rank: TypeRank, bin: TypeBinName)

Create an expression that removes list items nearest to value and greater by relative rank.

__init__(ctx: TypeCTX, value: TypeValue, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • value (TypeValue) – Start value or value expression.

  • rank (TypeRank) – Rank integer or integer expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Remove elements larger than 4 by relative rank in list bin "a".
expr = exp.ListRemoveByValueRelRankToEnd(None, 4, 1, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListSet(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)

Create an expression that sets item value at specified index in list.

__init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of List policies.

  • index (TypeIndex) – index of value to set.

  • value (TypeValue) – value or value expression to set index in list to.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

List expression.

Example:

# Get smallest element in list bin "a" after setting index 1 to 10.
expr = exp.ListGetByRank(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, 0,
                exp.ListSet(None, None, 1, 10, exp.ListBin("a"))).compile()
class aerospike_helpers.expressions.list.ListSize(ctx: TypeCTX, bin: TypeBinName)

Create an expression that returns list size.

__init__(ctx: TypeCTX, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Integer expression.

Example:

#Take the size of list bin "a".
expr = exp.ListSize(None, exp.ListBin("a")).compile()
class aerospike_helpers.expressions.list.ListSort(ctx: TypeCTX, order: int, bin: TypeBinName)

Create an expression that sorts a list.

__init__(ctx: TypeCTX, order: int, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • order (int) – Optional flags modifiying the behavior of list_sort. This should be constructed by bitwise or’ing together values from List Sort Flags.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

list expression.

Example:

# Get value of sorted list bin "a".
expr = exp.ListSort(None, aerospike.LIST_SORT_DEFAULT, "a").compile()

aerospike_helpers.expressions.map module

Map expressions contain expressions for reading and modifying Maps. Most of these operations are from the stadard Map API.

Example:

import aerospike_helpers.expressions as exp
#Take the size of map bin "b".
expr = exp.MapSize(None, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapClear(ctx: TypeCTX, bin: TypeBinName)

Create an expression that removes all items in map.

__init__(ctx: TypeCTX, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Clear map bin "b".
expr = exp.MapClear(None, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByIndex(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)

Create an expression that selects map item identified by index and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value_type (int) – The value type that will be returned by this expression (ResultType).

  • index (TypeIndex) – Integer or integer expression of index to get element at.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the value at index 0 in map bin "b". (assume this value is an integer)
expr = exp.MapGetByIndex(None, aerospike.MAP_RETURN_VALUE, ResultType.INTEGER, 0, MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByIndexRange(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName)

Create an expression that selects “count” map items starting at specified index and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • index (TypeIndex) – Integer or integer expression of index to start getting elements at.

  • count (TypeCount) – Integer or integer expression for count of elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get elements at indexes 3, 4, 5, 6 in map bin "b".
expr = exp.MapGetByIndexRange(None, aerospike.MAP_RETURN_VALUE, 3, 4, MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByIndexRangeToEnd(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName)

Create an expression that selects map items starting at specified index to the end of map and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • index (TypeIndex) – Integer or integer expression of index to start getting elements at.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get element at index 5 to end from map bin "b".
expr = exp.MapGetByIndexRangeToEnd(None, aerospike.MAP_RETURN_VALUE, 5, MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByKey(ctx: TypeCTX, return_type: int, value_type: int, key: TypeKey, bin: TypeBinName)

Create an expression that selects map item identified by key and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value_type: int, key: TypeKey, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value_type (int) – The value type that will be returned by this expression (ResultType).

  • key (TypeKey) – Key value or value expression of element to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the value at key "key0" in map bin "b". (assume the value at key0 is an integer)
expr = exp.MapGetByKey(None, aerospike.MAP_RETURN_VALUE, ResultType.INTEGER, "key0", exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByKeyList(ctx: TypeCTX, return_type: int, keys: TypeKeyList, bin: TypeBinName)

Create an expression that selects map items identified by keys and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, keys: TypeKeyList, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • keys (TypeKeyList) – List of key values or list expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get elements at keys "key3", "key4", "key5" in map bin "b".
expr = exp.MapGetByKeyList(None, aerospike.MAP_RETURN_VALUE, ["key3", "key4", "key5"], exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByKeyRange(ctx: TypeCTX, return_type: int, begin: TypeKey, end: TypeKey, bin: TypeBinName)

Create an expression that selects map items identified by key range. (begin inclusive, end exclusive). If begin is nil, the range is less than end. If end is aerospike.CDTInfinite(), the range is greater than equal to begin. Expression returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, begin: TypeKey, end: TypeKey, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • begin (TypeKey) – Key value or expression.

  • end (TypeKey) – Key value or expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get elements at keys "key3", "key4", "key5", "key6" in map bin "b".
expr = exp.MapGetByKeyRange(None, aerospike.MAP_RETURN_VALUE, "key3", "key7", exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByKeyRelIndexRange(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName)

Create an expression that selects map items nearest to key and greater by index with a count limit. Expression returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • key (TypeKey) – Key value or value expression.

  • index (TypeIndex) – Index integer or integer value expression.

  • count (TypeCount) – Integer count or integer value expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the next 2 elements with keys larger than "key3" from map bin "b".
expr = exp.MapGetByKeyRelIndexRange(None, aerospike.MAP_RETURN_VALUE, "key3", 1, 2, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByKeyRelIndexRangeToEnd(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, bin: TypeBinName)

Create an expression that selects map items nearest to key and greater by index with a count limit. Expression returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • key (TypeKey) – Key value or value expression.

  • index (TypeIndex) – Index integer or integer value expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get elements with keys larger than "key2" from map bin "b".
expr = exp.MapGetByKeyRelIndexRangeToEnd(None, aerospike.MAP_RETURN_VALUE, "key2", 1, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByRank(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)

Create an expression that selects map items identified by rank and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value_type (int) – The value type that will be returned by this expression (ResultType).

  • rank (TypeRank) – Rank integer or integer expression of element to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the smallest element in map bin "b".
expr = exp.MapGetByRank(None, aerospike.MAP_RETURN_VALUE, aerospike.ResultType.INTEGER, 0, MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByRankRange(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that selects “count” map items starting at specified rank and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • rank (TypeRank) – Rank integer or integer expression of first element to get.

  • count (TypeCount) – Count integer or integer expression for how many elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the 3 smallest elements in map bin "b".
expr = exp.MapGetByRankRange(None, aerospike.MAP_RETURN_VALUE, 0, 3, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByRankRangeToEnd(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName)

Create an expression that selects map items starting at specified rank to the last ranked item and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • rank (TypeRank) – Rank integer or integer expression of first element to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the three largest elements in map bin "b".
expr = exp.MapGetByRankRangeToEnd(None, aerospike.MAP_RETURN_VALUE, -3, MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByValue(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName)

Create an expression that selects map items identified by value and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value (TypeValue) – Value or value expression of element to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the rank of the element with value, 3, in map bin "b".
expr = exp.MapGetByValue(None, aerospike.MAP_RETURN_RANK, 3, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByValueList(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName)

Create an expression that selects map items identified by values and returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value (TypeListValue) – List or list expression of values of elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the indexes of the the elements in map bin "b" with values [3, 6, 12].
expr = exp.MapGetByValueList(None, aerospike.MAP_RETURN_INDEX, [3, 6, 12], exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByValueRange(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName)

Create an expression that selects map items identified by value range. (begin inclusive, end exclusive). If begin is None, the range is less than end. If end is None, the range is greater than equal to begin. Expression returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value_begin (TypeValue) – Value or value expression of first element to get.

  • value_end (TypeValue) – Value or value expression of ending element.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get elements with values between 3 and 7 from map bin "b".
expr = exp.MapGetByValueRange(None, aerospike.MAP_RETURN_VALUE, 3, 7, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByValueRelRankRange(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that selects map items nearest to value and greater by relative rank with a count limit. Expression returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value (TypeValue) – Value or vaule expression to get items relative to.

  • rank (TypeRank) – Rank intger expression. rank relative to “value” to start getting elements.

  • count (TypeCount) – Integer value or integer value expression, how many elements to get.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the next 2 values in map bin "b" larger than 3.
expr = exp.MapGetByValueRelRankRange(None, aerospike.MAP_RETURN_VALUE, 3, 1, 2, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapGetByValueRelRankRangeToEnd(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName)

Create an expression that selects map items nearest to value and greater by relative rank, Expression returns selected data specified by return_type.

__init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.

  • value (TypeValue) – Value or vaule expression to get items relative to.

  • rank (TypeRank) – Rank intger expression. rank relative to “value” to start getting elements.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Expression.

Example:

# Get the values of all elements in map bin "b" larger than 3.
expr = exp.MapGetByValueRelRankRangeToEnd(None, aerospike.MAP_RETURN_VALUE, 3, 1, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapIncrement(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)

Create an expression that increments a map value, by value, for all items identified by key. Valid only for numbers.

__init__(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of Map policies.

  • key (TypeKey) – Key value or value expression element to increment.

  • value (TypeValue) – Increment element by value expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Increment element at 'vageta' in map bin "b" by 9000.
expr = exp.MapIncrement(None, None, 'vageta', 9000, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapPut(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)

Create an expression that writes key/val to map bin.

__init__(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of Map policies.

  • key (TypeKey) – Key value or value expression to put into map.

  • value (TypeValue) – Value or value expression to put into map.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Put {27: 'key27'} into map bin "b".
expr = exp.MapPut(None, None, 27, 'key27', exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapPutItems(ctx: TypeCTX, policy: TypePolicy, map: map, bin: TypeBinName)

Create an expression that writes each map item to map bin.

__init__(ctx: TypeCTX, policy: TypePolicy, map: map, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • policy (TypePolicy) – Optional dictionary of Map policies.

  • map (map) – Map or map expression of items to put into target map.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Put {27: 'key27', 28: 'key28'} into map bin "b".
expr = exp.MapPut(None, None, {27: 'key27', 28: 'key28'}, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByIndex(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)

Create an expression that removes map item identified by index.

__init__(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • index (TypeIndex) – Index integer or integer expression of element to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove element with smallest key from map bin "b".
expr = exp.MapRemoveByIndex(None, 0, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByIndexRange(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName)

Create an expression that removes count map items starting at specified index.

__init__(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • index (TypeIndex) – Starting index integer or integer expression of elements to remove.

  • count (TypeCount) – Integer or integer expression, how many elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Get size of map bin "b" after index 3, 4, and 5 have been removed.
expr = exp.MapSize(None, exp.MapRemoveByIndexRange(None, 3, 3, exp.MapBin("b"))).compile()
class aerospike_helpers.expressions.map.MapRemoveByIndexRangeToEnd(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)

Create an expression that removes map items starting at specified index to the end of map.

__init__(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • index (TypeIndex) – Starting index integer or integer expression of elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove all elements starting from index 3 in map bin "b".
expr = exp.MapRemoveByIndexRangeToEnd(None, 3, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByKey(ctx: TypeCTX, key: TypeKey, bin: TypeBinName)

Create an expression that removes a map item identified by key.

__init__(ctx: TypeCTX, key: TypeKey, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • key (TypeKey) – Key value or value expression of key to element to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove element at key 1 in map bin "b".
expr = exp.MapRemoveByKey(None, 1, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByKeyList(ctx: TypeCTX, keys: List[Union[_BaseExpr, Any]], bin: TypeBinName)

Create an expression that removes map items identified by keys.

__init__(ctx: TypeCTX, keys: List[Union[_BaseExpr, Any]], bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • key (List[TypeKey]) – List of key values or a list expression of keys to elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove elements at keys [1, 2] in map bin "b".
expr = exp.MapRemoveByKeyList(None, [1, 2], exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByKeyRange(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName)

Create an expression that removes map items identified by key range (begin inclusive, end exclusive). If begin is None, the range is less than end. If end is None, the range is greater than equal to begin.

__init__(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • begin (TypeValue) – Begin value expression.

  • end (TypeValue) – End value expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove elements at keys between 1 and 10 in map bin "b".
expr = exp.MapRemoveByKeyRange(None, 1, 10 exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByKeyRelIndexRange(ctx: TypeCTX, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName)

Create an expression that removes map items nearest to key and greater by index with a count limit.

__init__(ctx: TypeCTX, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • key (TypeKey) – Key value or expression for key to start removing from.

  • index (TypeIndex) – Index integer or integer expression.

  • count (TypeCount) – Integer expression for how many elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove 3 elements with keys greater than "key1" from map bin "b".
expr = exp.MapRemoveByKeyRelIndexRange(None, "key1", 1, 3, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByKeyRelIndexRangeToEnd(ctx: TypeCTX, key: TypeKey, index: TypeIndex, bin: TypeBinName)

Create an expression that removes map items nearest to key and greater by index.

__init__(ctx: TypeCTX, key: TypeKey, index: TypeIndex, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • key (TypeKey) – Key value or expression for key to start removing from.

  • index (TypeIndex) – Index integer or integer expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Map bin "b" has {"key1": 1, "key2": 2, "key3": 3, "key4": 4}.
# Remove each element where the key has greater index than "key1".
expr = exp.MapRemoveByKeyRelIndexRangeToEnd(None, "key1", 1, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByRank(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)

Create an expression that removes map item identified by rank.

__init__(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • rank (TypeRank) – Rank integer or integer expression of element to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove smallest value in map bin "b".
expr = exp.MapRemoveByRank(None, 0, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByRankRange(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that removes “count” map items starting at specified rank.

__init__(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • rank (TypeRank) – Rank integer or integer expression of element to start removing at.

  • count (TypeCount) – Count integer or integer expression of elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove the 3 smallest items from map bin "b".
expr = exp.MapRemoveByRankRange(None, 0, 3, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByRankRangeToEnd(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)

Create an expression that removes map items starting at specified rank to the last ranked item.

__init__(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • rank (TypeRank) – Rank integer or integer expression of element to start removing at.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove the 2 largest elements from map bin "b".
expr = exp.MapRemoveByRankRangeToEnd(None, -2, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByValue(ctx: TypeCTX, value: TypeValue, bin: TypeBinName)

Create an expression that removes map items identified by value.

__init__(ctx: TypeCTX, value: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • value (TypeValue) – Value or value expression to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove {"key1": 1} from map bin "b".
expr = exp.MapRemoveByValue(None, 1, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByValueList(ctx: TypeCTX, values: TypeListValue, bin: TypeBinName)

Create an expression that removes map items identified by values.

__init__(ctx: TypeCTX, values: TypeListValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • values (TypeListValue) – List of values or list expression.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove elements with values 1, 2, 3 from map bin "b".
expr = exp.MapRemoveByValueList(None, [1, 2, 3], exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByValueRange(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName)

Create an expression that removes map items identified by value range (begin inclusive, end exclusive). If begin is nil, the range is less than end. If end is aerospike.CDTInfinite(), the range is greater than equal to begin.

__init__(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • begin (TypeValue) – Begin value or value expression for range.

  • end (TypeValue) – End value or value expression for range.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove list of items with values >= 3 and < 7 from map bin "b".
expr = exp.MapRemoveByValueRange(None, 3, 7, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByValueRelRankRange(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)

Create an expression that removes map items nearest to value and greater by relative rank with a count limit.

__init__(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • value (TypeValue) – Value or value expression to start removing from.

  • rank (TypeRank) – Integer or integer expression of rank.

  • count (TypeCount) – Integer count or integer expression for how many elements to remove.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove the next 4 elements larger than 3 from map bin "b".
expr = exp.MapRemoveByValueRelRankRangeToEnd(None, 3, 1, 4, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByValueRelRankRangeToEnd(ctx: TypeCTX, value: TypeValue, rank: TypeRank, bin: TypeBinName)

Create an expression that removes map items nearest to value and greater by relative rank.

__init__(ctx: TypeCTX, value: TypeValue, rank: TypeRank, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • value (TypeValue) – Value or value expression to start removing from.

  • rank (TypeRank) – Integer or integer expression of rank.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Map expression.

Example:

# Remove all elements with values larger than 3 from map bin "b".
expr = exp.MapRemoveByValueRelRankRangeToEnd(None, 3, 1, exp.MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapSize(ctx: TypeCTX, bin: TypeBinName)

Create an expression that returns map size.

__init__(ctx: TypeCTX, bin: TypeBinName)
Parameters
  • ctx (TypeCTX) – An optional list of nested CDT cdt_ctx context operation objects.

  • bin (TypeBinName) – bin expression, such as MapBin or ListBin.

Returns

Integer expression.

Example:

#Take the size of map bin "b".
expr = exp.MapSize(None, exp.MapBin("b")).compile()

aerospike_helpers.expressions.bit module

Bitwise expressions contain expressions for performing bitwise operations. Most of these operations are equivalent to the Bitwise Operations API for binary data.

Example:

import aerospike_helpers.expressions as exp
# Let blob bin "c" == bytearray([3] * 5).
# Count set bits starting at 3rd byte in bin "c" to get count of 6.
expr = exp.BitCount(16, 8 * 3, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitAdd(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)

Create an expression that performs a bit_add operation. Note: integers are stored big-endian.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • value (int) – Integer value or expression for value to add.

  • action (int) – An aerospike bit overflow action.

  • bin (TypeBinName) – A BlobBin expression.

Returns

resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# Bit add the second byte of bin "c" to get bytearray([1, 2, 1, 1, 1])
expr = exp.BitAdd(None, 8, 8, 1, aerospike.BIT_OVERFLOW_FAIL).compile()
class aerospike_helpers.expressions.bitwise.BitAnd(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)

Create an expression that performs a bit_and operation.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • value (TypeBitValue) – Bytes value or blob expression containing bytes to use in operation.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# bitwise and `0` with the first byte of blob bin c so that the returned value is bytearray([0, 5, 5, 5, 5]).
expr = exp.BitAnd(None, 0, 8, bytearray([0]), exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitCount(bit_offset: int, bit_size: int, bin: TypeBinName)

Create an expression that performs a bit_count operation.

__init__(bit_offset: int, bit_size: int, bin: TypeBinName)
Parameters
  • bit_offset (int) – Bit index of where to start reading.

  • bit_size (int) – Number of bits to count.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Blob, bit_size bits rounded up to the nearest byte size.

Example:

# Let blob bin "c" == bytearray([3] * 5).
# Count set bits starting at 3rd byte in bin "c" to get count of 6.
expr = exp.BitCount(16, 8 * 3, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitGet(bit_offset: int, bit_size: int, bin: TypeBinName)

Create an expression that performs a bit_get operation.

__init__(bit_offset: int, bit_size: int, bin: TypeBinName)
Parameters
  • bit_offset (int) – Bit index of where to start reading.

  • bit_size (int) – Number of bits to get.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Blob, bit_size bits rounded up to the nearest byte size.

Example:

# Let blob bin "c" == bytearray([1, 2, 3, 4, 5).
# Get 2 from bin "c".
expr = exp.BitGet(8, 8, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitGetInt(bit_offset: int, bit_size: int, sign: bool, bin: TypeBinName)

Create an expression that performs a bit_get_int operation.

__init__(bit_offset: int, bit_size: int, sign: bool, bin: TypeBinName)
Parameters
  • bit_offset (int) – Bit index of where to start reading.

  • bit_size (int) – Number of bits to get.

  • bool (sign) – True for signed, False for unsigned.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Integer expression.

Example:

# Let blob bin "c" == bytearray([1, 2, 3, 4, 5).
# Get 2 as an integer from bin "c".
expr = exp.BitGetInt(8, 8, True, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitInsert(policy: TypePolicy, byte_offset: int, value: TypeBitValue, bin: TypeBinName)

Create an expression that performs a bit_insert operation.

__init__(policy: TypePolicy, byte_offset: int, value: TypeBitValue, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • byte_offset (int) – Integer byte index of where to insert the value.

  • value (TypeBitValue) – A bytes value or blob value expression to insert.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob containing the inserted bytes.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# Insert 3 so that returned value is bytearray([1, 3, 1, 1, 1, 1]).
expr = exp.BitInsert(None, 1, bytearray([3]), exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitLeftScan(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)

Create an expression that performs a bit_lscan operation.

__init__(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)
Parameters
  • bit_offset (int) – Bit index of where to start reading.

  • bit_size (int) – Number of bits to read.

  • bool (value) – Bit value to check for.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Index of the left most bit starting from bit_offset set to value. Returns -1 if not found.

Example:

# Let blob bin "c" == bytearray([3] * 5).
# Scan the first byte of bin "c" for the first bit set to 1. (should get 6)
expr = exp.BitLeftScan(0, 8, True, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitLeftShift(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)

Create an expression that performs a bit_lshift operation.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • shift (int) – Number of bits to shift by.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# Bit left shift the first byte of bin "c" to get bytearray([8, 1, 1, 1, 1]).
expr = exp.BitLeftShift(None, 0, 8, 3, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitNot(policy: TypePolicy, bit_offset: int, bit_size: int, bin: TypeBinName)

Create an expression that performs a bit_not operation.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([255] * 5).
# bitwise, not, all of "c" to get bytearray([254] * 5).
expr = exp.BitNot(None, 0, 40, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitOr(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)

Create an expression that performs a bit_or operation.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • value (TypeBitValue) – Bytes value or blob expression containing bytes to use in operation.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# bitwise Or `8` with the first byte of blob bin c so that the returned value is bytearray([9, 1, 1, 1, 1]).
expr = exp.BitOr(None, 0, 8, bytearray([8]), exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitRemove(policy: TypePolicy, byte_offset: int, byte_size: int, bin: TypeBinName)

Create an expression that performs a bit_remove operation.

__init__(policy: TypePolicy, byte_offset: int, byte_size: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • byte_offset (int) – Byte index of where to start removing from.

  • byte_size (int) – Number of bytes to remove.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob containing the remaining bytes.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# Remove 1 element so that the returned value is bytearray([1] * 4).
expr = exp.BitRemove(None, 1, 1, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitResize(policy: TypePolicy, byte_size: int, flags: int, bin: TypeBinName)

Create an expression that performs a bit_resize operation.

__init__(policy: TypePolicy, byte_size: int, flags: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • byte_size (int) – Number of bytes the resulting blob should occupy.

  • flags (int) – One or a combination of bit resize flags.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Blob value expression of resized blob bin.

Example:

# Blob bin "c" == bytearray([1] * 5).
# Resize blob bin "c" from the front so that the returned value is bytearray([0] * 5 + [1] * 5).
expr = exp.BitResize(None, 10, aerospike.BIT_RESIZE_FROM_FRONT, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitRightScan(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)

Create an expression that performs a bit_rscan operation.

__init__(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)
Parameters
  • bit_offset (int) – Bit index of where to start reading.

  • bit_size (int) – Number of bits to read.

  • bool (value) – Bit value to check for.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Index of the right most bit starting from bit_offset set to value. Returns -1 if not found.

Example:

# Let blob bin "c" == bytearray([3] * 5).
# Scan the first byte of bin "c" for the right most bit set to 1. (should get 7)
expr = exp.BitRightScan(0, 8, True, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitRightShift(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)

Create an expression that performs a bit_rshift operation.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • shift (int) – Number of bits to shift by.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([8] * 5).
# Bit left shift the first byte of bin "c" to get bytearray([4, 8, 8, 8, 8]).
expr = exp.BitRightShift(None, 0, 8, 1, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitSet(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)

Create an expression that performs a bit_set operation.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start overwriting.

  • bit_size (int) – Number of bits to overwrite.

  • value (TypeBitValue) – Bytes value or blob expression containing bytes to write.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob expression with the bits overwritten.

Example:

# Let blob bin "c" == bytearray([0] * 5).
# Set bit at offset 7 with size 1 bits to 1 to make the returned value bytearray([1, 0, 0, 0, 0]).
expr = exp.BitSet(None, 7, 1, bytearray([255]), exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitSetInt(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, bin: TypeBinName)

Create an expression that performs a bit_set_int operation. Note: integers are stored big-endian.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start writing.

  • bit_size (int) – Number of bits to overwrite.

  • value (int) – Integer value or integer expression containing value to write.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob expression with the bits overwritten.

Example:

# Let blob bin "c" == bytearray([0] * 5).
# Set bit at offset 7 with size 1 bytes to 1 to make the returned value bytearray([1, 0, 0, 0, 0]).
expr = exp.BitSetInt(None, 7, 1, 1, exp.BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitSubtract(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)

Create an expression that performs a bit_subtract operation. Note: integers are stored big-endian.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • value (int) – Integer value or expression for value to add.

  • action (int) – An aerospike bit overflow action.

  • bin (TypeBinName) – A BlobBin expression.

Returns

resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# Bit subtract the second byte of bin "c" to get bytearray([1, 0, 1, 1, 1])
expr = exp.BitSubtract(None, 8, 8, 1, aerospike.BIT_OVERFLOW_FAIL).compile()
class aerospike_helpers.expressions.bitwise.BitXor(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)

Create an expression that performs a bit_xor operation.

__init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Parameters
  • policy (TypePolicy) – Optional dictionary of Bit policies.

  • bit_offset (int) – Bit index of where to start operation.

  • bit_size (int) – Number of bits to be operated on.

  • value (TypeBitValue) – Bytes value or blob expression containing bytes to use in operation.

  • bin (TypeBinName) – A BlobBin expression.

Returns

Resulting blob with the bits operated on.

Example:

# Let blob bin "c" == bytearray([1] * 5).
# bitwise Xor `1` with the first byte of blob bin c so that the returned value is bytearray([0, 1, 1, 1, 1]).
expr = exp.BitXor(None, 0, 8, bytearray([1]), exp.BlobBin("c")).compile()

aerospike_helpers.expressions.hllmodule

HyperLogLog expressions contain expressions for performing HLL operations. Most of these operations are equivalent to the HyperLogLog API.

Example:

import aerospike_helpers.expressions as exp
# Get count from HLL bin "d".
expr = exp.HLLGetCount(exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLAdd(policy: TypePolicy, list: TypeListValue, index_bit_count: Optional[int], mh_bit_count: Optional[int], bin: TypeBinName)

Create an expression that performs an hll_add.

__init__(policy: TypePolicy, list: TypeListValue, index_bit_count: Optional[int], mh_bit_count: Optional[int], bin: TypeBinName)
Parameters
  • policy (TypePolicy) – An optional dictionary of HyperLogLog policies.

  • list (TypeListValue) – A list or list expression of elements to add to the HLL.

  • index_bit_count (int) – Number of index bits. Must be between 4 and 16 inclusive.

  • mh_bit_count (int) – Number of min hash bits. Must be between 4 and 51 inclusive.

  • bin (TypeBinName) – An HLLBin expression.

Returns

Returns the resulting hll bin after adding elements from list.

Example:

# Let HLL bin "d" have the following elements, ['key1', 'key2', 'key3'], index_bits 8, mh_bits 8.
# Add ['key4', 'key5', 'key6'] so that the returned value is ['key1', 'key2', 'key3', 'key4', 'key5', 'key6']
expr = exp.HLLAdd(None, ['key4', 'key5', 'key6'], 8, 8, exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLDescribe(bin: TypeBinName)

Create an expression that performs an as_operations_hll_describe.

__init__(bin: TypeBinName)
Parameters

bin (TypeBinName) – An HLLBin expression.

Returns

List bin, a list containing the index_bit_count and minhash_bit_count.

Example:

# Get description of HLL bin "d".
expr = exp.HLLDescribe(exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetCount(bin: TypeBinName)

Create an expression that performs an as_operations_hll_get_count.

__init__(bin: TypeBinName)
Parameters

bin (TypeBinName) – An HLLBin expression.

Returns

Integer bin, the estimated number of unique elements in an HLL.

Example:

# Get count from HLL bin "d".
expr = exp.HLLGetCount(exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetIntersectCount(values: TypeValue, bin: TypeBinName)

Create an expression that performs an as_operations_hll_get_inersect_count.

__init__(values: TypeValue, bin: TypeBinName)
Parameters
  • values (TypeValue) – A single HLL or list of HLLs, values or expressions, to intersect with bin.

  • bin (TypeBinName) – An HLLBin expression.

Returns

Integer bin, estimated number of elements in the set intersection.

Example:

# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)].
# Let values be a list containing one HLL object with keys ['key%s' % str(i) for i in range(5000, 15000)].
# Find the count of keys in the intersection of HLL bin "d" and all HLLs in values. (Should be around 5000)
expr = exp.HLLGetIntersectCount(values, exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetSimilarity(values: TypeValue, bin: TypeBinName)

Create an expression that performs an as_operations_hll_get_similarity.

__init__(values: TypeValue, bin: TypeBinName)
Parameters
  • values (TypeValue) – A single HLL or list of HLLs, values or expressions, to calculate similarity with.

  • bin (TypeBinName) – An HLLBin expression.

Returns

Float bin, stimated similarity between 0.0 and 1.0.

Example:

# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)].
# Let values be a list containing one HLL object with keys ['key%s' % str(i) for i in range(5000, 15000)].
# Find the similarity the HLL in values to HLL bin "d". (Should be around 0.33)
# Note that similarity is defined as intersect(A, B, ...) / union(A, B, ...).
expr = exp.HLLGetSimilarity(values, exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetUnion(values: TypeValue, bin: TypeBinName)

Create an expression that performs an hll_get_union.

__init__(values: TypeValue, bin: TypeBinName)
Parameters
  • values (TypeValue) – A single HLL or list of HLLs, values or expressions, to union with bin.

  • bin (TypeBinName) – An HLLBin expression.

Returns

HLL bin representing the set union.

Example:

# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)].
# Let values be a list containing HLL objects retrieved from the aerospike database.
# Find the union of HLL bin "d" and all HLLs in values.
expr = exp.HLLGetUnion(values, exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetUnionCount(values: TypeValue, bin: TypeBinName)

Create an expression that performs an as_operations_hll_get_union_count.

__init__(values: TypeValue, bin: TypeBinName)
Parameters
  • values (TypeValue) – A single HLL or list of HLLs, values or expressions, to union with bin.

  • bin (TypeBinName) – An HLLBin expression.

Returns

Integer bin, estimated number of elements in the set union.

Example:

# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)].
# Let values be a list containing one HLL object with keys ['key%s' % str(i) for i in range(5000, 15000)].
# Find the count of keys in the union of HLL bin "d" and all HLLs in values. (Should be around 15000)
expr = exp.HLLGetUnionCount(values, exp.HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLInit(policy: TypePolicy, index_bit_count: Optional[int], mh_bit_count: Optional[int], bin: TypeBinName)

Creates a new HLL or resets an existing HLL. If index_bit_count and mh_bit_count are None, an existing HLL bin will be reset but retain its configuration. If 1 of index_bit_count or mh_bit_count are set, an existing HLL bin will set that config and retain its current value for the unset config. If the HLL bin does not exist, index_bit_count is required to create it, mh_bit_count is optional.

__init__(policy: TypePolicy, index_bit_count: Optional[int], mh_bit_count: Optional[int], bin: TypeBinName)
Parameters
  • policy (TypePolicy) – An optional dictionary of HyperLogLog policies.

  • index_bit_count (int) – Number of index bits. Must be between 4 and 16 inclusive.

  • mh_bit_count (int) – Number of min hash bits. Must be between 4 and 51 inclusive.

  • bin (TypeBinName) – An HLLBin expression.

Returns

Returns the resulting hll.

Example:

# Create an HLL with 12 index bits and 24 min hash bits.
expr = exp.HLLInit(None, 12, 24, exp.HLLBin("my_hll"))
class aerospike_helpers.expressions.hll.HLLMayContain(list: TypeListValue, bin: TypeBinName)

Create an expression that checks if the HLL bin contains any keys in list.

__init__(list: TypeListValue, bin: TypeBinName)
Parameters
  • list (TypeListValue) – A list expression of keys to check if the HLL may contain them.

  • bin (TypeBinName) – An HLLBin expression.

Returns

1 if bin contains any key in list, 0 otherwise.

Example:

# Check if HLL bin "d" contains any of the keys in `list`.
expr = exp.HLLMayContain(["key1", "key2", "key3"], exp.HLLBin("d")).compile()

aerospike_helpers.expressions.arithmeticmodule

Arithmetic expressions provide arithmetic operator support for Aerospike expressions.

Example:

import aerospike_helpers.expressions as exp
# Add integer bin "a" to integer bin "b" and see if the result is > 20.
expr = exp.GT(exp.Add(exp.IntBin("a"), exp.IntBin("b")), 20).compile()
class aerospike_helpers.expressions.arithmetic.Abs(value: TypeNumber)

Create operator that returns absolute value of a number. All arguments must resolve to integer or float.

Abs is also available via operator overloading using the bultin abs() function and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(value: TypeNumber)
Parameters

value (TypeNumber) – Float or integer expression or value to take absolute value of.

Returns

(number value)

Example:

# For int bin "a", abs("a") == 1
expr = exp.Eq(exp.Abs(exp.IntBin("a")), 1).compile()

# Using operator overloading
expr = exp.Eq(abs(exp.IntBin("a")), 1).compile()
class aerospike_helpers.expressions.arithmetic.Add(*args: TypeNumber)

Create an add, (+) expression. All arguments must be the same type (integer or float).

Add is also available via operator overloading using + and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(*args: TypeNumber)
Parameters

*args (TypeNumber) – Variable amount of float or integer expressions or values to be added together.

Returns

(integer or float value).

Example:

# Integer bin "a" + "b" == 11
expr = exp.Eq(exp.Add(exp.IntBin("a"), exp.IntBin("b")), 11).compile()

# Using operator overloading.
expr = exp.Eq(exp.IntBin("a") + exp.IntBin("b"), 11).compile()
class aerospike_helpers.expressions.arithmetic.Ceil(value: TypeFloat)

Create ceil expression that rounds a floating point number up to the closest integer value.

Ceil is also available via operator overloading using the math.ceil() function and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(value: TypeFloat)
Parameters

value (TypeFloat) – Float expression or value to take ceiling of.

Returns

(float value)

Example:

# Ceil(2.25) == 3.0
expr = exp.Eq(exp.Ceil(2.25), 3.0).compile()

# Using operator overloading
expr = exp.Eq(math.ceil(2.25), 3.0).compile()
class aerospike_helpers.expressions.arithmetic.Div(*args: TypeNumber)

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).

Div is also available via operator overloading using / and any subclass of _BaseExpr. See the second example.

Floor div is also avaliable via // but must be used with floats.

Requires server version 5.6.0+.

__init__(*args: TypeNumber)
Parameters

*args (TypeNumber) – Variable amount of float or integer expressions or values to be divided.

Returns

(integer or float value)

Example:

# Integer bin "a" / "b" / "c" >= 11
expr = exp.GE(exp.Div(exp.IntBin("a"), exp.IntBin("b"), exp.IntBin("c")), 11).compile()

# Using operator overloading.
expr = exp.GE(exp.IntBin("a") / exp.IntBin("b") / exp.IntBin("c"), 11).compile()

# Float bin "a" // "b" // "c" >= 11.0
expr = exp.GE(exp.FloatBin("a") // exp.FloatBin("b") // exp.FloatBin("c"), 11.0).compile()
class aerospike_helpers.expressions.arithmetic.Floor(value: TypeFloat)

Create floor expression that rounds a floating point number down to the closest integer value.

Floor is also available via operator overloading using the math.floor() function and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(value: TypeFloat)
Parameters

value (TypeFloat) – Float expression or value to take floor of.

Returns

(float value)

Example:

# Floor(2.25) == 2.0
expr = exp.Eq(exp.Floor(2.25), 2.0).compile()

# Using operator overloading
expr = exp.Eq(math.floor(2.25), 2.0).compile()
class aerospike_helpers.expressions.arithmetic.Log(num: TypeFloat, base: TypeFloat)

Create “log” operator for logarithm of “num” with base “base”. All arguments must resolve to floats.

Requires server version 5.6.0+.

__init__(num: TypeFloat, base: TypeFloat)
Parameters
  • num (TypeFloat) – Float expression or value number.

  • base (TypeFloat) – Float expression or value base.

Returns

(float value)

Example:

# For float bin "a", log("a", 2.0) == 16.0
expr = exp.Eq(exp.Log(exp.FloatBin("a"), 2.0), 16.0).compile()
class aerospike_helpers.expressions.arithmetic.Max(*args: TypeNumber)

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+.

__init__(*args: TypeNumber)
Parameters

*args (TypeNumber) – Variable amount of float or integer expressions or values from which to find the maximum value.

Returns

(integer or float value).

Example:

# for integer bins a, b, c, max(a, b, c) > 100
expr = exp.GT(exp.Max(exp.IntBin("a"), exp.IntBin("b"), exp.IntBin("c")), 100).compile()
class aerospike_helpers.expressions.arithmetic.Min(*args: TypeNumber)

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+.

__init__(*args: TypeNumber)
Parameters

*args (TypeNumber) – Variable amount of float or integer expressions or values from which to find the minimum value.

Returns

(integer or float value).

Example:

# for integer bins a, b, c, min(a, b, c) > 0
expr = exp.GT(exp.Min(exp.IntBin("a"), exp.IntBin("b"), exp.IntBin("c")), 0).compile()
class aerospike_helpers.expressions.arithmetic.Mod(numerator: TypeInteger, denominator: TypeInteger)

Create “modulo” (%) operator that determines the remainder of “numerator” divided by “denominator”. All arguments must resolve to integers.

Mod is also available via operator overloading using % and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(numerator: TypeInteger, denominator: TypeInteger)
Parameters
  • numerator (TypeInteger) – Integer expression or value numerator.

  • denominator (TypeInteger) – Integer expression or value denominator.

Returns

(integer value)

Example:

# For int bin "a" % 10 == 0
expr = exp.Eq(exp.Mod(exp.IntBin("a"), 10), 0).compile()

# Using operator overloading.
expr = exp.Eq(exp.IntBin("a") % 10, 0).compile()
class aerospike_helpers.expressions.arithmetic.Mul(*args: TypeNumber)

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).

Mul is also available via operator overloading using * and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(*args: TypeNumber)
Parameters

*args (TypeNumber) – Variable amount of float or integer expressions or values to be multiplied.

Returns

(integer or float value)

Example:

# Integer bin "a" * "b" >= 11
expr = exp.GE(exp.Mul(exp.IntBin("a"), exp.IntBin("b")), 11).compile()

# Using operator overloading.
expr = exp.GE(exp.IntBin("a") * exp.IntBin("b"), 11).compile()
class aerospike_helpers.expressions.arithmetic.Pow(base: TypeFloat, exponent: TypeFloat)

Create “pow” operator that raises a “base” to the “exponent” power. All arguments must resolve to floats.

Pow is also available via operator overloading using ** and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(base: TypeFloat, exponent: TypeFloat)
Parameters
  • base (TypeFloat) – Float expression or value base.

  • exponent (TypeFloat) – Float expression or value exponent.

Returns

(float value)

Example:

# Float bin "a" ** 2.0 == 16.0
expr = exp.Eq(exp.Pow(exp.FloatBin("a"), 2.0), 16.0).compile()

# Using operator overloading.
expr = exp.Eq(exp.FloatBin("a") ** 2.0, 16.0).compile()
class aerospike_helpers.expressions.arithmetic.Sub(*args: TypeNumber)

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).

Sub is also available via operator overloading using - and any subclass of _BaseExpr. See the second example.

Requires server version 5.6.0+.

__init__(*args: TypeNumber)
Parameters

*args (TypeNumber) – Variable amount of float or integer expressions or values to be subtracted.

Returns

(integer or float value)

Example:

# Integer bin "a" - "b" == 11
expr = exp.Eq(exp.Sub(exp.IntBin("a"), exp.IntBin("b")), 11).compile()

# Using operator overloading.
expr = exp.Eq(exp.IntBin("a") - exp.IntBin("b"), 11).compile()
class aerospike_helpers.expressions.arithmetic.ToFloat(value: TypeInteger)

Create expression that converts an integer to a float.

Requires server version 5.6.0+.

__init__(value: TypeInteger)
Parameters

value (TypeInteger) – Integer expression or value to convert to float.

Returns

(float value)

Example:

#For int bin "a", float(exp.IntBin("a")) == 2
expr = exp.Eq(exp.ToFloat(exp.IntBin("a")), 2).compile()
class aerospike_helpers.expressions.arithmetic.ToInt(value: TypeFloat)

Create expression that converts a float to an integer.

Requires server version 5.6.0+.

__init__(value: TypeFloat)
Parameters

value (TypeFloat) – Float expression or value to convert to int.

Returns

(integer value)

Example:

#For float bin "a", int(exp.FloatBin("a")) == 2
expr = exp.Eq(exp.ToInt(exp.FloatBin("a")), 2).compile()

aerospike_helpers.expressions.bitwise_operatorsmodule

Bitwise operator expressions provide support for bitwise operators like & and >> in Aerospike expressions.

Example:

import aerospike_helpers.expressions as exp
# Let int bin "a" == 0xAAAA.
# Use bitwise and to apply a mask 0xFF00 to 0xAAAA and check for 0xAA00.
expr = exp.Eq(exp.IntAnd(IntBin("a"), 0xFF00), 0xAA00).compile()
class aerospike_helpers.expressions.bitwise_operators.IntAnd(*exprs: TypeInteger)

Create integer “and” (&) operator expression that is applied to two or more integers. All arguments must resolve to integers.

Requires server version 5.6.0+.

__init__(*exprs: TypeInteger)
Parameters

*exprs (TypeInteger) – A variable amount of integer expressions or values to be bitwise ANDed.

Returns

(integer value)

Example:

# for int bin "a", a & 0xff == 0x11
expr = exp.Eq(IntAnd(exp.IntBin("a"), 0xff), 0x11).compile()
class aerospike_helpers.expressions.bitwise_operators.IntArithmeticRightShift(value: TypeInteger, shift: TypeInteger)

Create integer “arithmetic right shift” (>>) operator.

Requires server version 5.6.0+.

__init__(value: TypeInteger, shift: TypeInteger)
Parameters
  • value (TypeInteger) – An integer value or expression to be right shifted.

  • shift (TypeInteger) – An integer value or expression for number of bits to right shift value by.

Returns

(integer value)

Example:

# for int bin "a", a >> 8 > 0xff
expr = exp.GT(exp.IntArithmeticRightShift(exp.IntBin("a"), 8), 0xff).compile()
class aerospike_helpers.expressions.bitwise_operators.IntCount(value: TypeInteger)

Create expression that returns count of integer bits that are set to 1.

Requires server version 5.6.0+.

__init__(value: TypeInteger)
Parameters

value (TypeInteger) – An integer value or expression to have bits counted.

Returns

(integer value)

Example:

# for int bin "a", count(a) == 4
expr = exp.Eq(exp.IntCount(exp.IntBin("a")), 4).compile()
class aerospike_helpers.expressions.bitwise_operators.IntLeftScan(value: TypeInteger, search: TypeBool)

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+.

__init__(value: TypeInteger, search: TypeBool)
Parameters
  • value (TypeInteger) – An integer value or expression to be scanned.

  • search (TypeBool) – A bool expression or value to scan for.

Returns

(integer value)

Example:

# for int bin "a", lscan(a, True) == 4
expr = exp.GT(lscan(exp.IntBin("a"), True), 4).compile()
class aerospike_helpers.expressions.bitwise_operators.IntLeftShift(value: TypeInteger, shift: TypeInteger)

Create integer “left shift” (<<) operator.

Requires server version 5.6.0+.

__init__(value: TypeInteger, shift: TypeInteger)
Parameters
  • value (TypeInteger) – An integer value or expression to be left shifted.

  • shift (TypeInteger) – An integer value or expression for number of bits to left shift value by.

Returns

(integer value)

Example:

# for int bin "a", a << 8 > 0xff
expr = exp.GT(exp.IntLeftShift(exp.IntBin("a"), 8), 0xff).compile()
class aerospike_helpers.expressions.bitwise_operators.IntNot(expr: TypeInteger)

Create integer “not” (~) operator.

Requires server version 5.6.0+.

__init__(expr: TypeInteger)
Parameters

expr (TypeInteger) – An integer value or expression to be bitwise negated.

Returns

(integer value)

Example:

# for int bin "a", ~ a == 7
expr = exp.Eq(exp.IntNot(IntBin("a")), 7).compile()
class aerospike_helpers.expressions.bitwise_operators.IntOr(*exprs: TypeInteger)

Create integer “or” (|) operator expression that is applied to two or more integers. All arguments must resolve to integers.

Requires server version 5.6.0+.

__init__(*exprs: TypeInteger)
Parameters

*exprs (TypeInteger) – A variable amount of integer expressions or values to be bitwise ORed.

Returns

(integer value)

Example:

# for int bin "a", a | 0x10 not == 0
expr = exp.NE(exp.IntOr(IntBin("a"), 0x10), 0).compile()
class aerospike_helpers.expressions.bitwise_operators.IntRightScan(value: TypeInteger, search: TypeBool)

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+.

__init__(value: TypeInteger, search: TypeBool)
Parameters
  • value (TypeInteger) – An integer value or expression to be scanned.

  • search (TypeBool) – A bool expression or value to scan for.

Returns

(integer value)

Example:

# for int bin "a", rscan(a, True) == 4
expr = exp.GT(exp.IntRightScan(exp.IntBin("a"), True), 4).compile()
class aerospike_helpers.expressions.bitwise_operators.IntRightShift(value: TypeInteger, shift: TypeInteger)

Create integer “logical right shift” (>>>) operator.

Requires server version 5.6.0+.

__init__(value: TypeInteger, shift: TypeInteger)
Parameters
  • value (TypeInteger) – An integer value or expression to be right shifted.

  • shift (TypeInteger) – An integer value or expression for number of bits to right shift value by.

Returns

(integer value)

Example:

# for int bin "a", a >>> 8 > 0xff
expr = exp.GT(exp.IntRightShift(exp.IntBin("a"), 8), 0xff).compile()
class aerospike_helpers.expressions.bitwise_operators.IntXOr(*exprs: TypeInteger)

Create integer “xor” (^) operator that is applied to two or more integers. All arguments must resolve to integers.

Requires server version 5.6.0+.

__init__(*exprs: TypeInteger)
Parameters

*exprs (TypeInteger) – A variable amount of integer expressions or values to be bitwise XORed.

Returns

(integer value)

Example:

# for int bin "a", "b", a ^ b == 16
expr = exp.Eq(exp.IntXOr(exp.IntBin("a"), exp.IntBin("b")), 16).compile()

aerospike_helpers.expressions.resourcesmodule

Resources used by all expressions.

class aerospike_helpers.expressions.resources.ResultType

Flags used to indicate expression value_type.

BOOLEAN = 1
INTEGER = 2
STRING = 3
LIST = 4
MAP = 5
BLOB = 6
FLOAT = 7
GEOJSON = 8
HLL = 9