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 comparrison 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:

from __future__ import print_function
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.

Current Limitations:

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

The expressions module uses typehints, here are a table of custom typehints mapped to standard types.

Title

Type Name

Type Description

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]

TypeCDT

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

Base expressions include operators, bin, and meta data related expressions.

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)

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

__init__(*exprs)

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

Parameters

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

Returns

(boolean value)

Example:

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

Create an expression that returns True if bin exists.

__init__(bin)

Create an expression that returns True if bin exists.

Parameters

bin (str) – bin name.

Return (boolean value)

True if bin exists, False otherwise.

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – bin name.

Return (integer value)

returns the bin type.

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

:return (blob bin)

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

Returns

(boolean bin)

Example:

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

Create a point within region or region contains point expression.

__init__(expr0, expr1)

Create a point within region or region contains point expression.

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 = CmpGeo(GeoBin("point"), GeoBin("region")).compile()
class aerospike_helpers.expressions.base.CmpRegex(options, regex_str, cmp_str)

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

__init__(options, regex_str, cmp_str)

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

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 = CmpRegex(aerospike.REGEX_ICASE | aerospike.REGEX_NEWLINE, "prefix.*suffix", BinStr("a")).compile()
class aerospike_helpers.expressions.base.Cond(*exprs)

Conditionally select an expression from a variable number of expression pairs followed by default expression action. Takes a set of test-expression/action-expression pairs. It evaluates each test one at a time. If a test returns True, ‘cond’ evaluates and returns the value of the corresponding expression and doesn’t evaluate any of the other tests or expressions. The final expression is the default expression and is evaluated if all tests evaluate to False All actions-expressions must evaluate to the same type or be the Unknown expression.

__init__(*exprs)
Conditionally select an expression from a variable number of expression pairs

followed by default expression action. Takes a set of test-expression/action-expression pairs. It evaluates each test one at a time. If a test returns True, ‘cond’ evaluates and returns the value of the corresponding expression and doesn’t evaluate any of the other tests or expressions. The final expression is the default expression and is evaluated if all tests evaluate to False All actions-expressions must evaluate to the same type or be the Unknown expression. Requires server version 5.6.0+.

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 = GT(
        Cond(
            Eq(IntBin("type"), 0),
                Add(IntBin("val1"), IntBin("val2")),
            Eq(IntBin("type"), 1),
                Sub(IntBin("val1"), IntBin("val2")),
            Eq(IntBin("type"), 2),
                Mul(IntBin("val1"), IntBin("val2")))
        100).compile()
class aerospike_helpers.expressions.base.Def(var_name, expr)

Assign variable to an expression that can be accessed later.

__init__(var_name, expr)
Assign variable to an expression that can be accessed later.

Requires server version 5.6.0+.

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 = Let(Def("x", IntBin("a")),
        And(
            LT(5, Var("x")),
            LT(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__()

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.

Return (integer value)

Uncompressed storage size of the record.

Example:

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

Create an expression that returns record digest modulo as integer.

__init__(mod)

Create an expression that returns record digest modulo as integer.

Parameters

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

Return (integer value)

Value in range 0 and mod (exclusive).

Example:

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

Create an equals, (==) expression.

__init__(expr0, expr1)

Create an equals, (==) expression.

Parameters
  • expr0 (TypeComparisonArg) – Left argument to ==.

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

Returns

(boolean value)

Example:

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

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

__init__(*exprs)

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

Parameters

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

Returns

(boolean value)

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

Returns

(float bin)

Example:

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

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

__init__(expr0, expr1)

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

Parameters
  • expr0 (TypeComparisonArg) – Left argument to >=.

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

Returns

(boolean value)

Example:

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

Create a greater than (>) expression.

__init__(expr0, expr1)

Create a greater than (>) expression.

Parameters
  • expr0 (TypeComparisonArg) – Left argument to >.

  • expr1 (TypeComparisonArg) – Right argument to >.

Returns

(boolean value)

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

:return (geojson bin)

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

:return (HyperLogLog bin)

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

Returns

(integer bin)

Example:

# Integer bin "a" == 200.
expr = Eq(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__()

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.

Return (boolean value)

True if the record is a tombstone, false otherwise.

Example:

# Detect deleted records that are in tombstone state.
expr = 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__()

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

Return (blob value)

Blob value of the key if the key is a blob.

Example:

# blob record key <= bytearray([0x65, 0x65]).
expr = GE(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__()

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.

Return (boolean value)

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

Example:

# Key exists in record meta data.
expr = 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__()

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

Return (integer value)

Integer value of the key if the key is an integer.

Example:

# Integer record key >= 10000.
expr = 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__()

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

Return (string value)

string value of the key if the key is an string.

Example:

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

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

__init__(expr0, expr1)

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

Parameters
  • expr0 (TypeComparisonArg) – Left argument to <=.

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

Returns

(boolean value)

Example:

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

Create a less than (<) expression.

__init__(expr0, expr1)

Create a less than (<) expression.

Parameters
  • expr0 (TypeComparisonArg) – Left argument to <.

  • expr1 (TypeComparisonArg) – Right argument to <.

Returns

(boolean value)

Example:

# Integer bin "a" < 1000.
expr = LT(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__()

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

Return (integer value)

When the record was last updated.

Example:

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

Defines variables to be used within the <code>let</code> expression’s scope. The last argument can be any expression and should make use of the defined variables. The <code>let</code> 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)
Defines variables to be used within the <code>let</code> expression’s scope. The last

argument can be any expression and should make use of the defined variables. The <code>let</code> expression returns the evaluated result of the last argument. This expression is useful if Requires server version 5.6.0+.

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 = Let(Def("x", IntBin("a")),
        And(
            LT(5, Var("x")),
            LT(Var("x"), 10))).compile()
class aerospike_helpers.expressions.base.ListBin(bin)

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

:return (list bin)

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

:return (map bin)

Example:

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

Create a not equals (not ==) expressions.

__init__(expr0, expr1)

Create a not equals (not ==) expressions.

Parameters
  • expr0 (TypeComparisonArg) – Left argument to not ==.

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

Returns

(boolean value)

Example:

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

Create a “not” (not) operator expression.

__init__(*exprs)

Create a “not” (not) operator expression.

Parameters

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

Returns

(boolean value)

Example:

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

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

__init__(*exprs)

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

Parameters

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

Returns

(boolean value)

Example:

# (a == 0 || b == 0)
expr = Or(
        Eq(IntBin("a"), 0),
        Eq(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__()

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

Return (string value)

Name of the set this record belongs to.

Example:

# Record set name == "myset".
expr = Eq(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__()

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.

Return (integer value)

Number of milliseconds since last updated.

Example:

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

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

__init__(bin)

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

Parameters

bin (str) – Bin name.

Returns

(string bin)

Example:

# String bin "a" == "xyz".
expr = Eq(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__()

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

Return (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 = LT(TTL(), 60 * 60).compile()
class aerospike_helpers.expressions.base.Unknown

Create an ‘Unknown’ expression. Used to intentionally fail an expression operation such as expression_read or expression_write with error code 26, OpNotApplicable. When evaluated, the Unkown expression return the unknown-value returned by other failed expressions. These failures can be ignored with the expression flag aerospike.EXP_READ_EVAL_NO_FAIL. This expression is most useful as a case in a conditional expression used in an expression operation.

__init__()

Create an ‘Unknown’ expression. Used to intentionally fail an expression. The failure can be ignored with EXP_WRITE_EVAL_NO_FAIL or EXP_READ_NO_FAIL see Expression Write Flags.

:return (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().
Let(Def("bal", IntBin("balance")),
    Cond(
        GE(Var("bal"), 50),
            Add(Var("bal"), 50),
        Unknown())
)
class aerospike_helpers.expressions.base.Var(var_name)

Retrieve expression value from a variable.

__init__(var_name)
Retrieve expression value from a variable.

Requires server version 5.6.0+.

Parameters

var_name (str) – Variable name.

Returns

(value stored in variable)

Example:

# for int bin "a", 5 < a < 10
expr = Let(Def("x", IntBin("a")),
        And(
            LT(5, Var("x")),
            LT(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__()

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

Return (integer value)

Expiration time in nanoseconds since 1970-01-01.

Example:

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

aerospike_helpers.expressions.list module

List expressions contain list read and modify expressions.

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, policy, value, bin)

Create an expression that appends value to end of list.

__init__(ctx, policy, value, bin)

Create an expression that appends value to end of list.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional dictionary of list write options list write options.

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

  • bin (TypeBinName) – List bin or list expression.

Returns

List expression.

Example:

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

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

__init__(ctx, policy, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional dictionary of list write options list write options.

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

  • bin (TypeBinName) – Bin name or list expression.

Returns

List expression.

Example:

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

Create an expression that removes all items in a list.

__init__(ctx, bin)

Create an expression that removes all items in a list.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • bin (TypeBinName) – List bin or list expression to clear.

Returns

List expression.

Example:

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

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

__init__(ctx, return_type, value_type, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, index, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – List bin name or list expression.

Returns

Expression.

Example:

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

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, return_type, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value_type, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, rank, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – List bin name or list expression.

Returns

Expression.

Example:

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

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, return_type, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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 One of the aerospike list return types.

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value_begin, value_end, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

Expression.

Example:

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

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, return_type, value, rank, count, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, policy, index, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional dictionary of list write options list write options.Optional list write policy.

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

  • value (TypeValue) – Value or value expression.

  • bin (TypeBinName) – Bin name or list expression.

Returns

List expression.

Example:

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

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

__init__(ctx, policy, index, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional dictionary of list write options list write options.

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

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

  • bin (TypeBinName) – Bin name or list expression.

Returns

List expression.

Example:

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

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

__init__(ctx, policy, index, values, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional dictionary of list write options list write options.Optional list write policy.

  • 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 name or list expression.

Returns

List expression.

Example:

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

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

__init__(ctx, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

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

__init__(ctx, index, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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) – List bin name or list expression.

Returns

list expression.

Example:

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

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

__init__(ctx, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

Create an expression that removes list item identified by rank.

__init__(ctx, rank, bin)

Create an expression that removes list item identified by rank.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

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

__init__(ctx, rank, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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) – List bin name or list expression.

Returns

list expression.

Example:

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

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

__init__(ctx, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

Create an expression that removes list items identified by value.

__init__(ctx, value, bin)

Create an expression that removes list items identified by value.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – bin name or bin expression.

Returns

list expression.

Example:

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

Create an expression that removes list items identified by values.

__init__(ctx, values, bin)

Create an expression that removes list items identified by values.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

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, begin, end, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

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

__init__(ctx, value, rank, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

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

__init__(ctx, value, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – List bin name or list expression.

Returns

list expression.

Example:

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

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

__init__(ctx, policy, index, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional dictionary of list write options list write options.Optional list write policy.

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

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

  • bin (TypeBinName) – bin name or list expression.

Returns

List expression.

Example:

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

Create an expression that returns list size.

__init__(ctx, bin)

Create an expression that returns list size.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • bin (TypeBinName) – List bin name or list expression.

Returns

Integer expression.

Example:

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

Create an expression that sorts a list.

__init__(ctx, order, bin)

Create an expression that sorts a list.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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) – List bin name or list expression.

Returns

list expression.

Example:

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

aerospike_helpers.expressions.map module

Map expressions contain map read and modify expressions.

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, bin)

Create an expression that removes all items in map.

__init__(ctx, bin)

Create an expression that removes all items in map.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • bin (TypeBinName) – Map bin or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, return_type, value_type, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – Map bin name or map expression.

Returns

Expression.

Example:

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

Create an expression that selects “count” map items starting at specified index.

__init__(ctx, return_type, index, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value_type, key, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, keys, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

Create an expression that selects map items identified by key range.

__init__(ctx, return_type, begin, end, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • begin (TypeKey) – Key value or expression.

  • end (TypeKey) – Key value or expression.

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, key, index, count, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, key, index, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value_type, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, rank, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

Create an expression that selects map items identified by value.

__init__(ctx, return_type, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

Create an expression that selects map items identified by values.

__init__(ctx, return_type, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

Create an expression that selects map items identified by value range.

__init__(ctx, return_type, value_begin, value_end, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Expression.

Example:

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

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, return_type, value, rank, count, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – List bin name or list expression.

Returns

Expression.

Example:

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

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

__init__(ctx, return_type, value, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • 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) – Map bin name or map expression.

Returns

Expression.

Example:

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

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

__init__(ctx, policy, key, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional map write policy.

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

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

  • bin (TypeBinName) – Map bin or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, policy, key, value, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional map write policy.

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

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

  • bin (TypeBinName) – Map bin or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, policy, map, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • policy (TypePolicy) – Optional map write policy.

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

  • bin (TypeBinName) – Map bin or map expression.

Returns

Map expression.

Example:

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

Create an expression that removes map item identified by index.

__init__(ctx, index, bin)

Create an expression that removes map item identified by index.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Bin name or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, index, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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) – Map bin name or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, key, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Map bin or map expression.

Returns

Map expression.

Example:

# Remove element at key 1 in map bin "b".
expr = MapRemoveByKey(None, 1, MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByKeyList(ctx, keys, bin)

Create an expression that removes map items identified by keys.

__init__(ctx, keys, bin)

Create an expression that removes map items identified by keys.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Map bin or map expression.

Returns

Map expression.

Example:

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

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, begin, end, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • begin (TypeValue) – Begin value expression.

  • end (TypeValue) – End value expression.

  • bin (TypeBinName) – Map bin or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, key, index, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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) – Map bin or map expression.

Returns

[Map expression.

Example:

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

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

__init__(ctx, key, index, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Map bin or map expression.

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 = MapRemoveByKeyRelIndexRangeToEnd(None, "key1", 1, MapBin("b")).compile()
class aerospike_helpers.expressions.map.MapRemoveByRank(ctx, rank, bin)

Create an expression that removes map item identified by rank.

__init__(ctx, rank, bin)

Create an expression that removes map item identified by rank.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, rank, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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) – Map bin name or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Map expression.

Example:

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

Create an expression that removes map items identified by value.

__init__(ctx, value, bin)

Create an expression that removes map items identified by value.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Bin name or map expression.

Returns

Map expression.

Example:

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

Create an expression that removes map items identified by values.

__init__(ctx, values, bin)

Create an expression that removes map items identified by values.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

  • bin (TypeBinName) – Bin name or map expression.

Returns

Map expression.

Example:

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

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, begin, end, bin)

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.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Bin name or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, value, rank, count, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • 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 name or map expression.

Returns

Map expression.

Example:

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

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

__init__(ctx, value, rank, bin)

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

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

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

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

  • bin (TypeBinName) – Bin name or map expression.

Returns

Map expression.

Example:

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

Create an expression that returns map size.

__init__(ctx, bin)

Create an expression that returns map size.

Parameters
  • ctx (TypeCDT) – Optional context path for nested CDT.

  • bin (TypeBinName) – Map bin name or map expression.

Returns

Integer expression.

Example:

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

aerospike_helpers.expressions.bit module

Bitwise expressions contain bit read and modify expressions.

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, bit_offset, bit_size, value, action, bin)

Create an expression that performs a bit_add operation.

__init__(policy, bit_offset, bit_size, value, action, bin)

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

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitAdd(None, 8, 8, 1, aerospike.BIT_OVERFLOW_FAIL).compile()
class aerospike_helpers.expressions.bitwise.BitAnd(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_and operation.

__init__(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_and operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitAnd(None, 0, 8, bytearray([0]), BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitCount(bit_offset, bit_size, bin)

Create an expression that performs a bit_count operation.

__init__(bit_offset, bit_size, bin)

Create an expression that performs a bit_count operation.

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

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

  • bin (TypeBinName) – Blob bin name or blob 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 = BitCount(16, 8 * 3, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitGet(bit_offset, bit_size, bin)

Create an expression that performs a bit_get operation.

__init__(bit_offset, bit_size, bin)

Create an expression that performs a bit_get operation.

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

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

  • bin (TypeBinName) – Blob bin name or blob 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 = BitGet(8, 8, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitGetInt(bit_offset, bit_size, sign, bin)

Create an expression that performs a bit_get_int operation.

__init__(bit_offset, bit_size, sign, bin)

Create an expression that performs a bit_get_int operation.

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) – Blob bin name or blob expression.

Returns

Integer expression.

Example:

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

Create an expression that performs a bit_insert operation.

__init__(policy, byte_offset, value, bin)

Create an expression that performs a bit_insert operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob value 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 = BitInsert(None, 1, bytearray([3]), BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitLeftScan(bit_offset, bit_size, value, bin)

Create an expression that performs a bit_lscan operation.

__init__(bit_offset, bit_size, value, bin)

Create an expression that performs a bit_lscan operation.

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) – Blob bin name or blob 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 = BitLeftScan(0, 8, True, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitLeftShift(policy, bit_offset, bit_size, shift, bin)

Create an expression that performs a bit_lshift operation.

__init__(policy, bit_offset, bit_size, shift, bin)

Create an expression that performs a bit_lshift operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitLeftShift(None, 0, 8, 3, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitNot(policy, bit_offset, bit_size, bin)

Create an expression that performs a bit_not operation.

__init__(policy, bit_offset, bit_size, bin)

Create an expression that performs a bit_not operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

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

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

  • bin (TypeBinName) – Blob bin name or blob 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 = BitNot(None, 0, 40, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitOr(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_or operation.

__init__(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_or operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitOr(None, 0, 8, bytearray([8]), BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitRemove(policy, byte_offset, byte_size, bin)

Create an expression that performs a bit_remove operation.

__init__(policy, byte_offset, byte_size, bin)

Create an expression that performs a bit_remove operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

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

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

  • bin (TypeBinName) – Blob bin name or blob value 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 = BitRemove(None, 1, 1, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitResize(policy, byte_size, flags, bin)

Create an expression that performs a bit_resize operation.

__init__(policy, byte_size, flags, bin)

Create an expression that performs a bit_resize operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

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

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

  • bin (TypeBinName) – Blob bin name or blob value 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 = BitResize(None, 10, aerospike.BIT_RESIZE_FROM_FRONT, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitRightScan(bit_offset, bit_size, value, bin)

Create an expression that performs a bit_rscan operation.

__init__(bit_offset, bit_size, value, bin)

Create an expression that performs a bit_rscan operation.

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) – Blob bin name or blob 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 = BitRightScan(0, 8, True, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitRightShift(policy, bit_offset, bit_size, shift, bin)

Create an expression that performs a bit_rshift operation.

__init__(policy, bit_offset, bit_size, shift, bin)

Create an expression that performs a bit_rshift operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitRightShift(None, 0, 8, 1, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitSet(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_set operation.

__init__(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_set operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitSet(None, 7, 1, bytearray([255]), BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitSetInt(policy, bit_offset, bit_size, value, bin)

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

__init__(policy, bit_offset, bit_size, value, bin)

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

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitSetInt(None, 7, 1, 1, BlobBin("c")).compile()
class aerospike_helpers.expressions.bitwise.BitSubtract(policy, bit_offset, bit_size, value, action, bin)

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

__init__(policy, bit_offset, bit_size, value, action, bin)

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

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitSubtract(None, 8, 8, 1, aerospike.BIT_OVERFLOW_FAIL).compile()
class aerospike_helpers.expressions.bitwise.BitXor(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_xor operation.

__init__(policy, bit_offset, bit_size, value, bin)

Create an expression that performs a bit_xor operation.

Parameters
  • policy (TypePolicy) – An optional aerospike bit policy.

  • 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) – Blob bin name or blob 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 = BitXor(None, 0, 8, bytearray([1]), BlobBin("c")).compile()

aerospike_helpers.expressions.hllmodule

Hyper Log Log expressions contain hll read and modify expressions.

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, list, index_bit_count, mh_bit_count, bin)

Create an expression that performs an hll_add.

__init__(policy, list, index_bit_count, mh_bit_count, bin)

Create an expression that performs an hll_add.

Parameters
  • policy (TypePolicy) – An optional aerospike HLL policy.

  • 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) – A hll bin name or bin expression to apply this function to.

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 = HLLAdd(None, ['key4', 'key5', 'key6'], 8, 8, HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLDescribe(bin)

Create an expression that performs an as_operations_hll_describe.

__init__(bin)

Create an expression that performs an as_operations_hll_describe.

Parameters

bin (TypeBinName) – A hll bin name or bin expression to read from.

Returns

List bin, a list containing the index_bit_count and minhash_bit_count.

Example:

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

Create an expression that performs an as_operations_hll_get_count.

__init__(bin)

Create an expression that performs an as_operations_hll_get_count.

Parameters

bin (TypeBinName) – A hll bin name or bin expression to read from.

Returns

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

Example:

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

Create an expression that performs an as_operations_hll_get_inersect_count.

__init__(values, bin)

Create an expression that performs an as_operations_hll_get_inersect_count.

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

  • bin (TypeBinName) – A hll bin name or bin expression to read from.

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 = HLLGetIntersectCount(values, HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetSimilarity(values, bin)

Create an expression that performs an as_operations_hll_get_similarity.

__init__(values, bin)

Create an expression that performs an as_operations_hll_get_similarity.

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

  • bin (TypeBinName) – A hll bin name or bin expression to read from.

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 = HLLGetSimilarity(values, HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetUnion(values, bin)

Create an expression that performs an hll_get_union.

__init__(values, bin)

Create an expression that performs an hll_get_union.

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

  • bin (TypeBinName) – A hll bin name or bin expression to read from.

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 = HLLGetUnion(values, HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLGetUnionCount(values, bin)

Create an expression that performs an as_operations_hll_get_union_count.

__init__(values, bin)

Create an expression that performs an as_operations_hll_get_union_count.

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

  • bin (TypeBinName) – A hll bin name or bin expression to read from.

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 = HLLGetUnionCount(values, HLLBin("d")).compile()
class aerospike_helpers.expressions.hll.HLLInit(policy, index_bit_count, mh_bit_count, bin)

Create an expression that performs an hll_init.

__init__(policy, index_bit_count, mh_bit_count, bin)

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.

Parameters
  • policy (TypePolicy) – An optional dictionary of hll policy options.

  • 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) – A hll bin name or bin expression to apply this function to.

Returns

Returns the resulting hll.

Example:

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

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

__init__(list, bin)

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

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

  • bin (TypeBinName) – Integer bin, a hll bin name or bin expression to read from.

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 = HLLMayContain(["key1", "key2", "key3"], 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)

Create an absoloute value operator expression.

__init__(value)
Create operator that returns absolute value of a number.

All arguments must resolve to integer or float. Requires server version 5.6.0+.

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

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 = Eq(Abs(IntBin("a")), 1).compile()

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

Create an add, (+) expression.

__init__(*args)
Create an add, (+) expression.

All arguments must be the same type (integer or float). Requires server version 5.6.0+.

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

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 = Eq(Add(IntBin("a"), IntBin("b")), 11).compile()

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

Create a ceiling operator expression.

__init__(value)
Create ceil expression that rounds a floating point number up

to the closest integer value. Requires server version 5.6.0+.

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

Parameters

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

Returns

(float value)

Example:

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

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

Create a divide, (/) expression.

__init__(*args)
Create “divide” (/) operator that applies to a variable number of expressions.

If there is only one argument, returns the reciprocal for that argument. Otherwise, return the first argument divided by the product of the rest. All arguments must resolve to the same type (integer or float). Requires server version 5.6.0+.

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.

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 = GE(Div(IntBin("a"), IntBin("b"), IntBin("c")), 11).compile()

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

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

Create a floor operator expression.

__init__(value)
Create floor expression that rounds a floating point number down

to the closest integer value. Requires server version 5.6.0+.

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

Parameters

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

Returns

(float value)

Example:

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

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

Create a log operator expression.

__init__(num, base)
Create “log” operator for logarithm of “num” with base “base”.

All arguments must resolve to floats. Requires server version 5.6.0+.

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 = Eq(Log(FloatBin("a"), 2.0), 16.0).compile()
class aerospike_helpers.expressions.arithmetic.Max(*args)

Create expression that returns the maximum value in a variable number of expressions.

__init__(*args)
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+.

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 = GT(Max(IntBin("a"), IntBin("b"), IntBin("c")), 100).compile()
class aerospike_helpers.expressions.arithmetic.Min(*args)

Create expression that returns the minimum value in a variable number of expressions.

__init__(*args)
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+.

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 = GT(Min(IntBin("a"), IntBin("b"), IntBin("c")), 0).compile()
class aerospike_helpers.expressions.arithmetic.Mod(numerator, denominator)

Create a modulo, (%) expression.

__init__(numerator, denominator)
Create “modulo” (%) operator that determines the remainder of “numerator”

divided by “denominator”. All arguments must resolve to integers. Requires server version 5.6.0+.

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

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 = Eq(Mod(IntBin("a"), 10), 0).compile()

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

Create a multiply, (*) expression.

__init__(*args)
Create “multiply” (*) operator that applies to a variable number of expressions.

Return the product of all arguments. If only one argument is supplied, return that argument. All arguments must resolve to the same type (integer or float). Requires server version 5.6.0+.

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

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 = GE(Mul(IntBin("a"), IntBin("b")), 11).compile()

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

Create a pow, (**) expression.

__init__(base, exponent)
Create “pow” operator that raises a “base” to the “exponent” power.

All arguments must resolve to floats. Requires server version 5.6.0+.

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

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 = Eq(Pow(FloatBin("a"), 2.0), 16.0).compile()

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

Create a subtraction, (-) expression.

__init__(*args)
Create “subtract” (-) operator that applies to a variable number of expressions.

If only one argument is provided, return the negation of that argument. Otherwise, return the sum of the 2nd to Nth argument subtracted from the 1st argument. All arguments must resolve to the same type (integer or float). Requires server version 5.6.0+.

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

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 = Eq(Sub(IntBin("a"), IntBin("b")), 11).compile()

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

Create expression that converts an integer to a float.

__init__(value)
Create expression that converts an integer to a float.

Requires server version 5.6.0+.

Parameters

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

Returns

(float value)

Example:

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

Create expression that converts a float to an integer.

__init__(value)
Create expression that converts a float to an integer.

Requires server version 5.6.0+.

Parameters

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

Returns

(integer value)

Example:

#For float bin "a", int(FloatBin("a")) == 2
expr = Eq(ToInt(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)

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

__init__(*exprs)

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

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 = Eq(IntAnd(IntBin("a"), 0xff), 0x11).compile()
class aerospike_helpers.expressions.bitwise_operators.IntArithmeticRightShift(value, shift)

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

__init__(value, shift)

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

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 = GT(IntArithmeticRightShift(IntBin("a"), 8), 0xff).compile()
class aerospike_helpers.expressions.bitwise_operators.IntCount(value)

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

__init__(value)

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

Parameters

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

Returns

(integer value)

Example:

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

Create expression that scans integer bits from left (most significant bit) to right (least significant bit).

__init__(value, search)

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

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 = GT(lscan(IntBin("a"), True), 4).compile()
class aerospike_helpers.expressions.bitwise_operators.IntLeftShift(value, shift)

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

__init__(value, shift)

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

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 = GT(IntLeftShift(IntBin("a"), 8), 0xff).compile()
class aerospike_helpers.expressions.bitwise_operators.IntNot(expr)

Create integer “not” (~) operator.

__init__(expr)

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

Parameters

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

Returns

(integer value)

Example:

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

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

__init__(*exprs)

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

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 = NE(IntOr(IntBin("a"), 0x10), 0).compile()
class aerospike_helpers.expressions.bitwise_operators.IntRightScan(value, search)

Create expression that scans integer bits from right (least significant bit) to left (most significant bit).

__init__(value, search)

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

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 = GT(IntRightScan(IntBin("a"), True), 4).compile()
class aerospike_helpers.expressions.bitwise_operators.IntRightShift(value, shift)

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

__init__(value, shift)

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

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 = GT(IntRightShift(IntBin("a"), 8), 0xff).compile()
class aerospike_helpers.expressions.bitwise_operators.IntXOr(*exprs)

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

__init__(*exprs)

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

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 = Eq(IntXOr(IntBin("a"), 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