aerospike_helpers.expressions package
Classes for the creation and use of Aerospike expressions.
Overview
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.
Note
In the Python client, Aerospike expressions are built using a series of classes that represent
comparison and logical operators, bins, metadata operations, and bin operations.
Expressions are constructed using a Lisp like syntax by instantiating an expression that yields a boolean,
such as Eq()
or And()
,
while passing them other expressions and constants as arguments, and finally calling the compile()
method.
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, these transactions will filter the results.
Example:
import aerospike
from aerospike_helpers import expressions as exp
# Connect to database
config = {"hosts": [("127.0.0.1", 3000)]}
client = aerospike.client(config).connect()
# Write player records to database
keys = [("test", "demo", i) for i in range(1, 5)]
records = [
{'user': "Chief" , 'scores': [6, 12, 4, 21], 'kd': 1.2},
{'user': "Arbiter", 'scores': [5, 10, 5, 8] , 'kd': 1.0},
{'user': "Johnson", 'scores': [8, 17, 20, 5], 'kd': 0.9},
{'user': "Regret" , 'scores': [4, 2, 3, 5] , 'kd': 0.3}
]
for key, record in zip(keys, records):
client.put(key, record)
# Example #1: Get players with a K/D ratio >= 1.0
kdGreaterThan1 = exp.GE(exp.FloatBin("kd"), 1.0).compile()
policy = {"expressions": kdGreaterThan1}
# For more details on get_many() usage, see the documentation
records = client.get_many(keys, policy)
for record in records:
print(record[2])
# {'user': 'Chief', 'scores': [6, 12, 4, 21], 'kd': 1.2}
# {'user': 'Arbiter', 'scores': [5, 10, 5, 8], 'kd': 1.0}
# None
# None
# Example #2: Get player with scores higher than 20
# By nesting expressions, we can create complicated filters
# Get top score
getTopScore = exp.ListGetByRank(
None,
aerospike.LIST_RETURN_VALUE,
exp.ResultType.INTEGER,
-1,
exp.ListBin("scores")
)
# ...then compare it
scoreHigherThan20 = exp.GE(getTopScore, 20).compile()
policy = {"expressions": scoreHigherThan20}
records = client.get_many(keys, policy)
for record in records:
print(record[2])
# {'user': 'Chief', 'scores': [6, 12, 4, 21], 'kd': 1.2}
# None
# {'user': 'Johnson', 'scores': [8, 17, 20, 5], 'kd': 0.9}
# None
Currently, Aerospike expressions are supported for: - Record operations - Batch operations - Transactions - UDF apply methods (apply, scan apply, and query apply) - Query invoke methods (foreach, results, execute background) - Scan invoke methods (same as query invoke methods)
Filter Behavior
This section describes the behavior of methods when a record is filtered out by an expression.
- For:
Record operations
Numeric operations
String operations
Single record transactions
An exception FilteredOut
is thrown.
The filtered out record’s meta
and bins
are both set to None
.
For:
batch_write()
(records filtered out by a batch or batch record policy)
batch_operate()
(records filtered out by a batch or batch write policy)
batch_apply()
(records filtered out by a batch or batch apply policy)
The filtered out record’s:
BatchRecord.record
is set toNone
BatchRecord.result
is set to27
For batch_get_ops()
, the filtered out record’s:
meta
is set toFilteredOut
.
bins
is set toNone
.
Terminology
Aerospike expressions are evaluated server side, and expressions used for filtering are called filter expressions. They 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 evaluation 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 that an expression returns an expression,
this means that the data type returned may vary (usually depending on the return_type
parameter).
Note
Currently, Aerospike expressions for the python client do not support comparing as_python_bytes
blobs.
Only comparisons between key ordered map values and map expressions are supported.
Expression Type Aliases
The following documentation uses type aliases that map to standard Python types.
Alias |
Type |
---|---|
AerospikeExpression |
_BaseExpr |
TypeResultType |
Optional[int] |
TypeFixedEle |
Union[int, float, str, bytes, dict] |
TypeFixed |
Optional[Dict[str, TypeFixedEle]] |
TypeCompiledOp |
Tuple[int, TypeResultType, TypeFixed, int] |
TypeExpression |
List[TypeCompiledOp] |
TypeChild |
Union[int, float, str, bytes, _AtomExpr] |
TypeChildren |
Tuple[TypeChild, …] |
TypeBinName |
Union[_BaseExpr, str] |
TypeListValue |
Union[_BaseExpr, List[Any]] |
TypeIndex |
Union[_BaseExpr, int, aerospike.CDTInfinite] |
TypeCTX |
Union[None, List[cdt_ctx._cdt_ctx]] |
TypeRank |
Union[_BaseExpr, int, aerospike.CDTInfinite] |
TypeCount |
Union[_BaseExpr, int, aerospike.CDTInfinite] |
TypeValue |
Union[_BaseExpr, Any] |
TypePolicy |
Union[Dict[str, Any], None] |
TypeComparisonArg |
Union[_BaseExpr, int, str, list, dict, aerospike.CDTInfinite] |
TypeGeo |
Union[_BaseExpr, aerospike.GeoJSON] |
TypeKey |
Union[_BaseExpr, Any] |
TypeKeyList |
Union[_BaseExpr, List[Any]] |
TypeBitValue |
Union[bytes, bytearray] |
TypeNumber |
Union[_BaseExpr, int, float] |
TypeFloat |
Union[_BaseExpr, float] |
TypeInteger |
Union[_BaseExpr, int] |
TypeBool |
Union[_BaseExpr, bool] |
Note
Requires server version >= 5.2.0
Assume all in-line examples run this code beforehand:
import aerospike
import aerospike_helpers.expressions as exp
aerospike_helpers.expressions.base module
The expressions base module provide expressions for:
declaring variables, using variables, and control-flow
comparison operators
applying logical operators to one or more ‘boolean expressions’
returning the value of (in-memory) record metadata
returning the value from storage, such as bin data or the record’s key
- class aerospike_helpers.expressions.base.And(*exprs: _BaseExpr)
Create an “and” operator that applies to a variable amount of expressions.
- __init__(*exprs: _BaseExpr)
- Parameters:
*exprs (_BaseExpr) – Variable amount of expressions to be ANDed together.
- Returns:
(boolean value)
Example:
# (a > 5 || a == 0) && b < 3 expr = exp.And( exp.Or( exp.GT(exp.IntBin("a"), 5), exp.Eq(exp.IntBin("a"), 0)), exp.LT(exp.IntBin("b"), 3)).compile()
- class aerospike_helpers.expressions.base.BinExists(bin: str)
Create an expression that returns True if bin exists.
- class aerospike_helpers.expressions.base.BinType(bin: str)
Create an expression that returns the type of a bin as one of the aerospike bin types
- class aerospike_helpers.expressions.base.BlobBin(bin: str)
Create an expression that returns a bin as a blob. Returns the unknown-value if the bin is not a blob.
- class aerospike_helpers.expressions.base.BoolBin(bin: str)
Create an expression that returns a bin as a boolean. Returns the unknown-value if the bin is not a boolean.
- class aerospike_helpers.expressions.base.CmpGeo(expr0: TypeGeo, expr1: TypeGeo)
Create a point within region or region contains point expression.
- __init__(expr0: TypeGeo, expr1: TypeGeo)
- Parameters:
expr0 (TypeGeo) – Left expression in comparison.
expr1 (TypeGeo) – Right expression in comparison.
- Returns:
(boolean value)
Example:
# Geo bin "point" is within geo bin "region". expr = exp.CmpGeo(exp.GeoBin("point"), exp.GeoBin("region")).compile()
- class aerospike_helpers.expressions.base.CmpRegex(options: int, regex_str: str, cmp_str: _BaseExpr | str)
Create an expression that performs a regex match on a string bin or value expression.
- __init__(options: int, regex_str: str, cmp_str: _BaseExpr | str)
- Parameters:
options (int) – One of the aerospike regex constants, Regex Flag Values.
regex_str (str) – POSIX regex string.
cmp_str (Union[_BaseExpr, str]) – String expression to compare against.
- Returns:
(boolean value)
Example:
# Select string bin "a" that starts with "prefix" and ends with "suffix". # Ignore case and do not match newline. import aerospike expr = exp.CmpRegex(aerospike.REGEX_ICASE | aerospike.REGEX_NEWLINE, "prefix.*suffix", exp.StrBin("a")).compile()
- class aerospike_helpers.expressions.base.Cond(*exprs: _BaseExpr)
Conditionally select an expression from a variable number of condition/action pairs, followed by a default expression action.
Takes a set of test-expression/action-expression pairs and evaluates each test expression, one at a time. If a test returns
True
,Cond
evaluates the corresponding action expression and returns its value, after whichCond
doesn’t evaluate any of the other tests or expressions. If all tests evaluate toFalse
, the default action expression is evaluated and returned.Cond
is strictly typed, so all actions-expressions must evaluate to the same type or theUnknown
expression.Requires server version 5.6.0+.
- __init__(*exprs: _BaseExpr)
- Parameters:
*exprs (_BaseExpr) – bool exp1, action exp1, bool exp2, action exp2, …, action-default
- Returns:
(boolean value)
Example:
from aerospike_helpers.expressions.arithmetic import Add, Sub, Mul import aerospike # Configure the client config = { 'hosts': [('127.0.0.1', 3000)] } # Create a client and connect it to the cluster client = aerospike.client(config) client.truncate('test', "demo", 0) # Store 2 bin integers and use expressions to perform arithmetic # Results will only be calculated and returned, not stored keyTuple = ('test', 'demo', 'key') client.put(keyTuple, {"operation": "add", "val1": 40, "val2": 30}) # Determine operation to perform # If operation is unknown, return -1 expr = exp.Cond( exp.Eq(exp.StrBin("operation"), "add"), Add(exp.IntBin("val1"), exp.IntBin("val2")), exp.Eq(exp.StrBin("operation"), "subtract"), Sub(exp.IntBin("val1"), exp.IntBin("val2")), exp.Eq(exp.StrBin("operation"), "multiply"), Mul(exp.IntBin("val1"), exp.IntBin("val2")), -1).compile() from aerospike_helpers.operations import expression_operations as expr_ops ops = [ # Bin "results" doesn't actually exist in the server # The name is only used to return the results expr_ops.expression_read("results", expr) ] record = client.operate(keyTuple, ops) print(record) # (('test', 'demo', 'key', bytearray(b'...')), {'ttl': 2592000, 'gen': 1}, {'results': 70}) client.put(keyTuple, {"operation": "divide"}) record = client.operate(keyTuple, ops) print(record) # Divide isn't supported, so we get -1 # (('test', 'demo', 'key', bytearray(b'...')), {'ttl': 2592000, 'gen': 2}, {'results': -1})
- class aerospike_helpers.expressions.base.Def(var_name: str, expr: _BaseExpr)
Assign variable to an expression that can be accessed later with
Var
. Requires server version 5.6.0+.- __init__(var_name: str, expr: _BaseExpr)
- Parameters:
var_name (str) – Variable name.
expr (_BaseExpr) – Variable is set to result of this expression.
- Returns:
(a variable name expression pair)
Example:
# for int bin "a", 5 < a < 10 expr = exp.Let(exp.Def("x", exp.IntBin("a")), exp.And( exp.LT(5, exp.Var("x")), exp.LT(exp.Var("x"), 10))).compile()
- class aerospike_helpers.expressions.base.DeviceSize
Create an expression that returns record size on disk. If server storage-engine is memory, then zero is returned. This expression usually evaluates quickly because record meta data is cached in memory.
This expression should only be used for server versions less than 7.0. Use
RecordSize
for server version 7.0+.- __init__()
- Returns:
(integer value): Uncompressed storage size of the record.
Example:
# Record device size >= 100 KB. expr = exp.GE(exp.DeviceSize(), 100 * 1024).compile()
- class aerospike_helpers.expressions.base.DigestMod(mod: int)
Create an expression that returns record digest modulo as integer.
- class aerospike_helpers.expressions.base.Eq(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Create an equals, (==) expression.
- __init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
- Parameters:
expr0 (TypeComparisonArg) – Left argument to ==.
expr1 (TypeComparisonArg) – Right argument to ==.
- Returns:
(boolean value)
Example:
# Integer bin "a" == 11 expr = exp.Eq(exp.IntBin("a"), 11).compile()
- class aerospike_helpers.expressions.base.Exclusive(*exprs: _BaseExpr)
Create an expression that returns True if only one of the expressions are True.
- __init__(*exprs: _BaseExpr)
- Parameters:
*exprs (_BaseExpr) – Variable amount of expressions to be checked.
- Returns:
(boolean value)
Example:
# exclusive(a == 0, b == 0) expr = exp.Exclusive( exp.Eq(exp.IntBin("a"), 0), exp.Eq(exp.IntBin("b"), 0)).compile()
- class aerospike_helpers.expressions.base.FloatBin(bin: str)
Create an expression that returns a bin as a float. Returns the unknown-value if the bin is not a float.
- class aerospike_helpers.expressions.base.GE(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Create a greater than or equal to (>=) expression.
- __init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
- Parameters:
expr0 (TypeComparisonArg) – Left argument to >=.
expr1 (TypeComparisonArg) – Right argument to >=.
- Returns:
(boolean value)
Example:
# Integer bin "a" >= 88. expr = exp.GE(exp.IntBin("a"), 88).compile()
- class aerospike_helpers.expressions.base.GT(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Create a greater than (>) expression.
- __init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
- Parameters:
expr0 (TypeComparisonArg) – Left argument to >.
expr1 (TypeComparisonArg) – Right argument to >.
- Returns:
(boolean value)
Example:
# Integer bin "a" > 8. expr = exp.GT(exp.IntBin("a"), 8).compile()
- class aerospike_helpers.expressions.base.GeoBin(bin: str)
Create an expression that returns a bin as a geojson. Returns the unknown-value if the bin is not a geojson.
- class aerospike_helpers.expressions.base.HLLBin(bin: str)
Create an expression that returns a bin as a HyperLogLog. Returns the unknown-value if the bin is not a HyperLogLog.
- class aerospike_helpers.expressions.base.IntBin(bin: str)
Create an expression that returns a bin as an integer. Returns the unknown-value if the bin is not an integer.
- class aerospike_helpers.expressions.base.IsTombstone
Create an expression that returns if record has been deleted and is still in tombstone state. This expression usually evaluates quickly because record meta data is cached in memory. NOTE: this is only applicable for XDR filter expressions.
- __init__()
- Returns:
(boolean value): True if the record is a tombstone, false otherwise.
Example:
# Detect deleted records that are in tombstone state. expr = exp.IsTombstone().compile()
- class aerospike_helpers.expressions.base.KeyBlob
Create an expression that returns the key as a blob. Returns the unknown-value if the key is not a blob.
- __init__()
- Returns:
(blob value): Blob value of the key if the key is a blob.
Example:
# blob record key <= bytearray([0x65, 0x65]). expr = exp.GE(exp.KeyBlob(), bytearray([0x65, 0x65])).compile()
- class aerospike_helpers.expressions.base.KeyExists
Create an expression that returns if the primary key is stored in the record storage data as a boolean expression. This would occur on record write, when write policies set the key field to
aerospike.POLICY_KEY_SEND
.- __init__()
- Returns:
(boolean value): True if the record has a stored key, false otherwise.
Example:
# Key exists in record meta data. expr = exp.KeyExists().compile()
- class aerospike_helpers.expressions.base.KeyInt
Create an expression that returns the key as an integer. Returns the unknown-value if the key is not an integer.
- __init__()
- Returns:
(integer value): Integer value of the key if the key is an integer.
Example:
# Integer record key >= 10000. expr = exp.GE(exp.KeyInt(), 10000).compile()
- class aerospike_helpers.expressions.base.KeyStr
Create an expression that returns the key as a string. Returns the unknown-value if the key is not a string.
- __init__()
- Returns:
(string value): string value of the key if the key is an string.
Example:
# string record key == "aaa". expr = exp.Eq(exp.KeyStr(), "aaa").compile()
- class aerospike_helpers.expressions.base.LE(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Create a less than or equal to (<=) expression.
- __init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
- Parameters:
expr0 (TypeComparisonArg) – Left argument to <=.
expr1 (TypeComparisonArg) – Right argument to <=.
- Returns:
(boolean value)
Example:
# Integer bin "a" <= 1. expr = exp.LE(exp.IntBin("a"), 1).compile()
- class aerospike_helpers.expressions.base.LT(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Create a less than (<) expression.
- __init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
- Parameters:
expr0 (TypeComparisonArg) – Left argument to <.
expr1 (TypeComparisonArg) – Right argument to <.
- Returns:
(boolean value)
Example:
# Integer bin "a" < 1000. expr = exp.LT(exp.IntBin("a"), 1000).compile()
- class aerospike_helpers.expressions.base.LastUpdateTime
Create an expression that the returns record last update time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch.
- __init__()
- Returns:
(integer value): When the record was last updated.
Example:
# Record last update time >= 2020-01-15. expr = exp.GE(exp.LastUpdateTime(), 1577836800).compile()
- class aerospike_helpers.expressions.base.Let(*exprs: _BaseExpr)
Defines variables to be used within the
Let
expression’s scope. The last argument can be any expression and should make use of the defined variables. TheLet
expression returns the evaluated result of the last argument. This expression is useful if you need to reuse the result of a complicated or expensive expression.- __init__(*exprs: _BaseExpr)
- Parameters:
*exprs (_BaseExpr) – Variable number of
Def
expressionsexpression. (followed by a scoped) –
- Returns:
(result of scoped expression)
Example:
# for int bin "a", 5 < a < 10 expr = exp.Let(exp.Def("x", exp.IntBin("a")), exp.And( exp.GT(5, exp.Var("x")), exp.LT(exp.Var("x"), 10))).compile()
- class aerospike_helpers.expressions.base.ListBin(bin: str)
Create an expression that returns a bin as a list. Returns the unknown-value if the bin is not a list.
- __init__(bin: str)
- Parameters:
bin (str) – Bin name.
- Returns:
(list bin)
Example:
from aerospike_helpers.expressions import list as list_exprs # Check that list bin "listBin" contains at least one item with value 42. list42Count = list_exprs.ListGetByValue( ctx=None, return_type=aerospike.LIST_RETURN_COUNT, value=42, bin=exp.ListBin("listBin") ) expr = exp.GT(list42Count, 0).compile()
- class aerospike_helpers.expressions.base.MapBin(bin: str)
Create an expression that returns a bin as a map. Returns the unknown-value if the bin is not a map.
- class aerospike_helpers.expressions.base.MemorySize
Returns the records memory size in bytes as an integer when either the namespace is configured data-in-memory true or storage-engine memory, otherwise returns 0.
Requires server version between 5.3 inclusive and 7.0 exclusive. Use
RecordSize
for server version 7.0+.- __init__()
- Returns:
(integer value)
- class aerospike_helpers.expressions.base.NE(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
Create a not equals (not ==) expressions.
- __init__(expr0: TypeComparisonArg, expr1: TypeComparisonArg)
- Parameters:
expr0 (TypeComparisonArg) – Left argument to not ==.
expr1 (TypeComparisonArg) – Right argument to not ==.
- Returns:
(boolean value)
Example:
# Integer bin "a" not == 13. expr = exp.NE(exp.IntBin("a"), 13).compile()
- class aerospike_helpers.expressions.base.Not(*exprs: _BaseExpr)
Create a “not” (not) operator expression.
- __init__(*exprs: _BaseExpr)
- Parameters:
*exprs (_BaseExpr) – Variable amount of expressions to be negated.
- Returns:
(boolean value)
Example:
# not (a == 0 or a == 10) expr = exp.Not(exp.Or( exp.Eq(exp.IntBin("a"), 0), exp.Eq(exp.IntBin("a"), 10))).compile()
- class aerospike_helpers.expressions.base.Or(*exprs: _BaseExpr)
Create an “or” operator that applies to a variable amount of expressions.
- __init__(*exprs: _BaseExpr)
- Parameters:
*exprs (_BaseExpr) – Variable amount of expressions to be ORed together.
- Returns:
(boolean value)
Example:
# (a == 0 || b == 0) expr = exp.Or( exp.Eq(exp.IntBin("a"), 0), exp.Eq(exp.IntBin("b"), 0)).compile()
- class aerospike_helpers.expressions.base.RecordSize
Create expression that returns the record size. This expression usually evaluates quickly because record meta data is cached in memory.
Requires server version 7.0+. This expression replaces
DeviceSize()
andMemorySize()
.- __init__()
- Returns:
(integer value) Record size in bytes
- class aerospike_helpers.expressions.base.SetName
Create an expression that returns record set name string. This expression usually evaluates quickly because record meta data is cached in memory.
- __init__()
- Returns:
(string value): Name of the set this record belongs to.
Example:
# Record set name == "myset". expr = exp.Eq(exp.SetName(), "myset").compile()
- class aerospike_helpers.expressions.base.SinceUpdateTime
Create an expression that returns milliseconds since the record was last updated. This expression usually evaluates quickly because record meta data is cached in memory.
- __init__()
- Returns:
(integer value): Number of milliseconds since last updated.
Example:
# Record last updated more than 2 hours ago. expr = exp.GT(exp.SinceUpdateTime(), 2 * 60 * 60 * 1000).compile()
- class aerospike_helpers.expressions.base.StrBin(bin: str)
Create an expression that returns a bin as a string. Returns the unknown-value if the bin is not a string.
- class aerospike_helpers.expressions.base.TTL
Create an expression that returns record expiration time (time to live) in integer seconds.
- __init__()
- Returns:
(integer value): Number of seconds till the record will expire, returns -1 if the record never expires.
Example:
# Record expires in less than 1 hour. expr = exp.LT(exp.TTL(), 60 * 60).compile()
- class aerospike_helpers.expressions.base.Unknown
Create an ‘Unknown’ expression, which allows an operation expression (‘read expression’ or ‘write expression’) to be aborted.
This expression returns a special ‘unknown’ trilean value which, when returned by an operation expression, will result in an error code 26
OpNotApplicable
. These failures can be ignored with the policy flagsaerospike.EXP_READ_EVAL_NO_FAIL
for read expressions andaerospike.EXP_WRITE_EVAL_NO_FAIL
for write expressions. This would then allow subsequent operations in the transaction to proceed.This expression is only useful from a
Cond
conditional expression within an operation expression, and should be avoided in filter-expressions, where it might trigger an undesired move into the storage-data phase.If a test-expression within the
Cond
yields the special ‘unknown’ trilean value, then theCond
will also immediately yield the ‘unknown’ value and further test-expressions will not be evaluated.Note that this special ‘unknown’ trilean value is the same value returned by any failed expression.
- __init__()
- Returns:
(unknown value)
Example:
from aerospike_helpers.expressions.arithmetic import Add # Declare variable for balance bin exp.Let(exp.Def("bal", exp.IntBin("balance")), # If IntBin("balance") >= 50, get "balance" + 50. exp.Cond( exp.GE(exp.Var("bal"), 50), Add(exp.Var("bal"), 50), # Otherwise, fail the expression via Unknown(). exp.Unknown() ) )
- class aerospike_helpers.expressions.base.Val(value: Any)
Create an expression that returns a value.
- class aerospike_helpers.expressions.base.Var(var_name: str)
Retrieve expression value from a variable previously defined with
Def
. Requires server version 5.6.0+.
- class aerospike_helpers.expressions.base.VoidTime
Create an expression that returns record expiration time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch.
- __init__()
- Returns:
(integer value): Expiration time in nanoseconds since 1970-01-01.
Example:
# Record expires on 2021-01-01. expr = exp.And( exp.GE(exp.VoidTime(), 1609459200), exp.LT(exp.VoidTime(), 1609545600)).compile()
aerospike_helpers.expressions.list module
List expressions contain expressions for reading and modifying Lists. Most of
these operations are from the standard List API
.
- class aerospike_helpers.expressions.list.ListAppend(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)
Create an expression that appends value to end of list.
- __init__(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of List policies.
value (TypeValue) – Value or value expression to append to list.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
List expression.
Example:
# Check if length of list bin "a" is > 5 after appending 1 item. listAppendedBy3 = exp.ListAppend(None, None, 3, exp.ListBin("a")) expr = exp.GT(exp.ListSize(None, listAppendedBy3), 5).compile()
- class aerospike_helpers.expressions.list.ListAppendItems(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)
Create an expression that appends a list of items to the end of a list.
- __init__(ctx: TypeCTX, policy: TypePolicy, value: TypeValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of List policies.
value (TypeValue) – List or list expression of items to be appended.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
List expression.
Example:
# Check if length of list bin "a" is > 5 after appending multiple items. listAppendedByTwoItems = exp.ListAppendItems(None, None, [3, 2], exp.ListBin("a")) expr = exp.GT( exp.ListSize(None, listAppendedByTwoItems), 5).compile()
- class aerospike_helpers.expressions.list.ListClear(ctx: TypeCTX, bin: TypeBinName)
Create an expression that removes all items in a list.
- __init__(ctx: TypeCTX, bin: TypeBinName)
- Parameters:
- Returns:
List expression.
Example:
# Clear list value of list nested in list bin "a" index 1. from aerospike_helpers import cdt_ctx ctx = [cdt_ctx.cdt_ctx_list_index(1)] expr = exp.ListClear(ctx, "a").compile()
- class aerospike_helpers.expressions.list.ListGetByIndex(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)
Create an expression that selects list item identified by index and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
value_type (int) – The value type that will be returned by this expression (ResultType).
index (TypeIndex) – Integer or integer expression of index to get element at.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Expression.
Example:
# Get the value at index 0 in list bin "a". (assume this value is an integer) expr = exp.ListGetByIndex(None, aerospike.LIST_RETURN_VALUE, exp.ResultType.INTEGER, 0, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByIndexRange(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that selects “count” list items starting at specified index and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
index (TypeIndex) – Integer or integer expression of index to start getting elements at.
count (TypeCount) – Integer or integer expression for count of elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get elements at indexes 3, 4, 5, 6 in list bin "a". expr = exp.ListGetByIndexRange(None, aerospike.LIST_RETURN_VALUE, 3, 4, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByIndexRangeToEnd(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items starting at specified index to the end of list and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
index (TypeIndex) – Integer or integer expression of index to start getting elements at.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get element 5 to end from list bin "a". expr = exp.ListGetByIndexRangeToEnd(None, aerospike.LIST_RETURN_VALUE, 5, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByRank(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)
Create an expression that selects list item identified by rank and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
value_type (int) – The value type that will be returned by this expression (ResultType).
rank (TypeRank) – Rank integer or integer expression of element to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Expression.
Example:
# Get the smallest element in list bin "a". expr = exp.ListGetByRank(None, aerospike.LIST_RETURN_VALUE, exp.ResultType.INTEGER, 0, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByRankRange(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that selects “count” list items starting at specified rank and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
rank (TypeRank) – Rank integer or integer expression of first element to get.
count (TypeCount) – Count integer or integer expression for how many elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the 3 smallest elements in list bin "a". expr = exp.ListGetByRankRange(None, aerospike.LIST_RETURN_VALUE, 0, 3, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByRankRangeToEnd(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items starting at specified rank to the last ranked item and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
rank (TypeRank) – Rank integer or integer expression of first element to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the three largest elements in list bin "a". expr = exp.ListGetByRankRangeToEnd(None, aerospike.LIST_RETURN_VALUE, -3, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByValue(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items identified by value and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
value (TypeValue) – Value or value expression of element to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the index of the element with value, 3, in list bin "a". expr = exp.ListGetByValue(None, aerospike.LIST_RETURN_INDEX, 3, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByValueList(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items identified by values and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values Value specifying what should be returned from the operation. This should be one of the List Return Types values.
value (TypeListValue) – List or list expression of values of elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the indexes of the the elements in list bin "a" with values [3, 6, 12]. expr = exp.ListGetByValueList(None, aerospike.LIST_RETURN_INDEX, [3, 6, 12], exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByValueRange(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items identified by value range and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items identified by value range and returns selected data specified by return_type.
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
value_begin (TypeValue) – Value or value expression of first element to get.
value_end (TypeValue) – Value or value expression of ending element.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get rank of values between 3 (inclusive) and 7 (exclusive) in list bin "a". expr = exp.ListGetByValueRange(None, aerospike.LIST_RETURN_RANK, 3, 7, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListGetByValueRelRankRange(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items nearest to value and greater by relative rank with a count limit and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
value (TypeValue) – Value or value expression to get items relative to.
rank (TypeRank) – Rank integer expression. rank relative to “value” to start getting elements.
count (TypeCount) – Integer value or integer value expression, how many elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# [6, 12, 4, 21] expr = exp.ListGetByValueRelRankRange(None, aerospike.LIST_RETURN_VALUE, 3, 1, 2, exp.ListBin("a")).compile() # The next greater value after 3 in the list is 4 # Rank 0 = 4 # So we only fetch two values starting at rank 1 # [12, 6]
- class aerospike_helpers.expressions.list.ListGetByValueRelRankRangeToEnd(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that selects list items nearest to value and greater by relative rank
- __init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
value (TypeValue) – Value or value expression to get items relative to.
rank (TypeRank) – Rank integer expression. rank relative to “value” to start getting elements.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# [6, 12, 4, 21] expr = exp.ListGetByValueRelRankRangeToEnd(None, aerospike.LIST_RETURN_VALUE, 3, 1, exp.ListBin("a")).compile() # Rank 0: 4 # We only fetch values with rank 1 or more (i.e the rest of the list) # Expected results: [6, 12, 21]
- class aerospike_helpers.expressions.list.ListIncrement(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
Create an expression that increments list[index] by value.
- __init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of List policies.
index (TypeIndex) – Index of value to increment.
value (TypeValue) – Value or value expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
List expression.
Example:
# Check if incremented value in list bin "a" is the largest in the list. # Rank of -1 == largest element largestListValue = exp.ListGetByRank(None, aerospike.LIST_RETURN_VALUE, exp.ResultType.INTEGER, -1) listIncrementedAtIndex1 = exp.ListIncrement(None, None, 1, 5, exp.ListBin("a")) listItemAtIndex1 = exp.ListGetByIndex(None, aerospike.LIST_RETURN_VALUE, exp.ResultType.INTEGER, 1, listIncrementedAtIndex1) expr = exp.Eq( largestListValue, listItemAtIndex1 ).compile()
- class aerospike_helpers.expressions.list.ListInsert(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
Create an expression that inserts value to specified index of list.
- __init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of List policies.
index (TypeIndex) – Target index for insertion, integer or integer expression.
value (TypeValue) – Value or value expression to be inserted.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
List expression.
Example:
# Check if list bin "a" has length > 5 after insert. listInsertedBy3At0 = exp.ListInsert(None, None, 0, 3, exp.ListBin("a")) expr = exp.GT(exp.ListSize(None, listInsertedBy3At0), 5).compile()
- class aerospike_helpers.expressions.list.ListInsertItems(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, values: TypeListValue, bin: TypeBinName)
Create an expression that inserts each input list item starting at specified index of list.
- __init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, values: TypeListValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of List policies.
index (TypeIndex) – Target index where item insertion will begin, integer or integer expression.
values (TypeListValue) – List or list expression of items to be inserted.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
List expression.
Example:
# Check if list bin "a" has length > 5 after inserting items. listInsertedByTwoItems = exp.ListInsertItems(None, None, 0, [4, 7], exp.ListBin("a")) expr = exp.GT(exp.ListSize(None, listInsertedByTwoItems), 5).compile()
- class aerospike_helpers.expressions.list.ListRemoveByIndex(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
Create an expression that removes “count” list items starting at specified index.
- __init__(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
- Parameters:
- Returns:
list expression.
Example:
# Get size of list bin "a" after index 3 has been removed. expr = exp.ListSize(None, exp.ListRemoveByIndex(None, 3, exp.ListBin("a"))).compile()
- class aerospike_helpers.expressions.list.ListRemoveByIndexRange(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that removes “count” list items starting at specified index.
- __init__(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.index (TypeIndex) – Starting index integer or integer expression of elements to remove.
count (TypeCount) – Integer or integer expression, how many elements to remove.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
list expression.
Example:
# Get size of list bin "a" after index 3, 4, and 5 have been removed. expr = exp.ListSize(None, exp.ListRemoveByIndexRange(None, 3, 3, exp.ListBin("a"))).compile()
- class aerospike_helpers.expressions.list.ListRemoveByIndexRangeToEnd(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
Create an expression that removes list items starting at specified index to the end of list.
- class aerospike_helpers.expressions.list.ListRemoveByRank(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
Create an expression that removes list item identified by rank.
- __init__(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
- Parameters:
- Returns:
list expression.
Example:
# Remove smallest value in list bin "a". expr = exp.ListRemoveByRank(None, 0, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListRemoveByRankRange(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that removes “count” list items starting at specified rank.
- __init__(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.rank (TypeRank) – Rank integer or integer expression of element to start removing at.
count (TypeCount) – Count integer or integer expression of elements to remove.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
list expression.
Example:
# Remove the 3 smallest items from list bin "a". expr = exp.ListRemoveByRankRange(None, 0, 3, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListRemoveByRankRangeToEnd(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that removes list items starting at specified rank to the last ranked item.
- __init__(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
- Parameters:
- Returns:
list expression.
Example:
# Remove the 2 largest elements from List bin "a". # Assume list bin contains [6, 12, 4, 21] expr = exp.ListRemoveByRankRangeToEnd(None, -2, exp.ListBin("a")).compile() # Expected results: [6, 4]
- class aerospike_helpers.expressions.list.ListRemoveByValue(ctx: TypeCTX, value: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that removes list items identified by value.
- __init__(ctx: TypeCTX, value: TypeValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
- Returns:
list expression.
Example:
# See if list bin "a", with `3` removed, is equal to list bin "b". listRemoved3 = exp.ListRemoveByValue(None, 3, exp.ListBin("a")) expr = exp.Eq(listRemoved3, exp.ListBin("b")).compile()
- class aerospike_helpers.expressions.list.ListRemoveByValueList(ctx: TypeCTX, values: TypeListValue, bin: TypeBinName, inverted: bool = False)
Create an expression that removes list items identified by values.
- class aerospike_helpers.expressions.list.ListRemoveByValueRange(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that removes list items identified by value range (begin inclusive, end exclusive). If begin is None, the range is less than end. If end is None, the range is greater than or equal to begin.
- __init__(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.begin (TypeValue) – Begin value or value expression for range.
end (TypeValue) – End value or value expression for range.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
list expression.
Example:
# Remove list of items with values >= 3 and < 7 from list bin "a". expr = exp.ListRemoveByValueRange(None, 3, 7, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListRemoveByValueRelRankRange(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that removes list items nearest to value and greater by relative rank with a count limit.
- __init__(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.value (TypeValue) – Start value or value expression.
rank (TypeRank) – Rank integer or integer expression.
count (TypeCount) – How many elements to remove.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
list expression.
Example:
# Remove 2 elements greater than 4 # Assume list in bin a is: [6, 12, 4, 21] exp.ListRemoveByValueRelRankRange(None, 4, 1, 2, exp.ListBin("a")) # Expected results: [4, 21]
- class aerospike_helpers.expressions.list.ListRemoveByValueRelRankToEnd(ctx: TypeCTX, value: TypeValue, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that removes list items nearest to value and greater by relative rank.
- __init__(ctx: TypeCTX, value: TypeValue, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.value (TypeValue) – Start value or value expression.
rank (TypeRank) – Rank integer or integer expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
list expression.
Example:
# Remove elements larger than 4 by relative rank in list bin "a". # Assume list in bin a is: [6, 12, 4, 21] expr = exp.ListRemoveByValueRelRankToEnd(None, 4, 1, exp.ListBin("a")).compile() # Expected results: [4] # All elements starting with and after the rank are removed
- class aerospike_helpers.expressions.list.ListSet(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
Create an expression that sets item value at specified index in list.
- __init__(ctx: TypeCTX, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of List policies.
index (TypeIndex) – index of value to set.
value (TypeValue) – value or value expression to set index in list to.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
List expression.
Example:
# Get smallest element in list bin "a" after setting index 1 to 10. listSetAtIndex1 = exp.ListSet(None, None, 1, 10, exp.ListBin("a")) expr = exp.ListGetByRank(None, aerospike.LIST_RETURN_VALUE, exp.ResultType.INTEGER, 0, listSetAtIndex1).compile()
- class aerospike_helpers.expressions.list.ListSize(ctx: TypeCTX, bin: TypeBinName)
Create an expression that returns list size.
- __init__(ctx: TypeCTX, bin: TypeBinName)
- Parameters:
- Returns:
Integer expression.
Example:
#Take the size of list bin "a". expr = exp.ListSize(None, exp.ListBin("a")).compile()
- class aerospike_helpers.expressions.list.ListSort(ctx: TypeCTX, order: int, bin: TypeBinName)
Create an expression that sorts a list.
- __init__(ctx: TypeCTX, order: int, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.order (int) – Optional flags modifying the behavior of list_sort. This should be constructed by bitwise or’ing together values from List Sort Flags.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
list expression.
Example:
# Get value of sorted list bin "a". expr = exp.ListSort(None, aerospike.LIST_SORT_DEFAULT, "a").compile()
aerospike_helpers.expressions.map module
Map expressions contain expressions for reading and modifying Maps. Most of
these operations are from the standard Map API
.
- class aerospike_helpers.expressions.map.MapClear(ctx: TypeCTX, bin: TypeBinName)
Create an expression that removes all items in map.
- __init__(ctx: TypeCTX, bin: TypeBinName)
- Parameters:
- Returns:
Map expression.
Example:
# Clear map bin "b". expr = exp.MapClear(None, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByIndex(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)
Create an expression that selects map item identified by index and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value_type: int, index: TypeIndex, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value_type (int) – The value type that will be returned by this expression (ResultType).
index (TypeIndex) – Integer or integer expression of index to get element at.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Expression.
Example:
# Get the value at index 0 in map bin "b". (assume this value is an integer) expr = exp.MapGetByIndex(None, aerospike.MAP_RETURN_VALUE, exp.ResultType.INTEGER, 0, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByIndexRange(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that selects “count” map items starting at specified index and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
index (TypeIndex) – Integer or integer expression of index to start getting elements at.
count (TypeCount) – Integer or integer expression for count of elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get elements at indexes 3, 4, 5, 6 in map bin "b". expr = exp.MapGetByIndexRange(None, aerospike.MAP_RETURN_VALUE, 3, 4, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByIndexRangeToEnd(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items starting at specified index to the end of map and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
index (TypeIndex) – Integer or integer expression of index to start getting elements at.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get element at index 5 to end from map bin "b". expr = exp.MapGetByIndexRangeToEnd(None, aerospike.MAP_RETURN_VALUE, 5, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByKey(ctx: TypeCTX, return_type: int, value_type: int, key: TypeKey, bin: TypeBinName)
Create an expression that selects map item identified by key and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value_type: int, key: TypeKey, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value_type (int) – The value type that will be returned by this expression (ResultType).
key (TypeKey) – Key value or value expression of element to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Expression.
Example:
# Get the value at key "key0" in map bin "b". (assume the value at key0 is an integer) expr = exp.MapGetByKey(None, aerospike.MAP_RETURN_VALUE, exp.ResultType.INTEGER, "key0", exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByKeyList(ctx: TypeCTX, return_type: int, keys: TypeKeyList, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items identified by keys and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, keys: TypeKeyList, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
keys (TypeKeyList) – List of key values or list expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get elements at keys "key3", "key4", "key5" in map bin "b". expr = exp.MapGetByKeyList(None, aerospike.MAP_RETURN_VALUE, ["key3", "key4", "key5"], exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByKeyRange(ctx: TypeCTX, return_type: int, begin: TypeKey, end: TypeKey, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items identified by key range. (begin inclusive, end exclusive). If begin is nil, the range is less than end. If end is aerospike.CDTInfinite(), the range is greater than equal to begin. Expression returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, begin: TypeKey, end: TypeKey, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
begin (TypeKey) – Key value or expression.
end (TypeKey) – Key value or expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get elements at keys "key3", "key4", "key5", "key6" in map bin "b". expr = exp.MapGetByKeyRange(None, aerospike.MAP_RETURN_VALUE, "key3", "key7", exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByKeyRelIndexRange(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items nearest to key and greater by index with a count limit. Expression returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
key (TypeKey) – Key value or value expression.
index (TypeIndex) – Index integer or integer value expression.
count (TypeCount) – Integer count or integer value expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
expr = exp.MapGetByKeyRelIndexRange(None, aerospike.MAP_RETURN_VALUE, "key2", 0, 2, exp.MapBin("b")).compile() # [2, 3] expr = exp.MapGetByKeyRelIndexRange(None, aerospike.MAP_RETURN_VALUE, "key2", 1, 2, exp.MapBin("b")).compile() # [3, 10]
- class aerospike_helpers.expressions.map.MapGetByKeyRelIndexRangeToEnd(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items nearest to key and greater by index with a count limit. Expression returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, key: TypeKey, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
key (TypeKey) – Key value or value expression.
index (TypeIndex) – Index integer or integer value expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get elements with keys larger than "key2" from map bin "b". expr = exp.MapGetByKeyRelIndexRangeToEnd(None, aerospike.MAP_RETURN_VALUE, "key2", 1, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByRank(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)
Create an expression that selects map items identified by rank and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value_type: int, rank: TypeRank, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value_type (int) – The value type that will be returned by this expression (ResultType).
rank (TypeRank) – Rank integer or integer expression of element to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Expression.
Example:
# Get the smallest element in map bin "b". expr = exp.MapGetByRank(None, aerospike.MAP_RETURN_VALUE, exp.ResultType.INTEGER, 0, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByRankRange(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that selects “count” map items starting at specified rank and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
rank (TypeRank) – Rank integer or integer expression of first element to get.
count (TypeCount) – Count integer or integer expression for how many elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the 3 smallest elements in map bin "b". expr = exp.MapGetByRankRange(None, aerospike.MAP_RETURN_VALUE, 0, 3, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByRankRangeToEnd(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items starting at specified rank to the last ranked item and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
rank (TypeRank) – Rank integer or integer expression of first element to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the three largest elements in map bin "b". expr = exp.MapGetByRankRangeToEnd(None, aerospike.MAP_RETURN_VALUE, -3, MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByValue(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items identified by value and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value: TypeValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value (TypeValue) – Value or value expression of element to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the rank of the element with value, 3, in map bin "b". expr = exp.MapGetByValue(None, aerospike.MAP_RETURN_RANK, 3, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByValueList(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items identified by values and returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value: TypeListValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value (TypeListValue) – List or list expression of values of elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the indexes of the the elements in map bin "b" with values [3, 6, 12]. expr = exp.MapGetByValueList(None, aerospike.MAP_RETURN_INDEX, [3, 6, 12], exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByValueRange(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items identified by value range. (begin inclusive, end exclusive). If begin is None, the range is less than end. If end is None, the range is greater than equal to begin. Expression returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value_begin: TypeValue, value_end: TypeValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value_begin (TypeValue) – Value or value expression of first element to get.
value_end (TypeValue) – Value or value expression of ending element.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get elements with values between 3 and 7 from map bin "b". expr = exp.MapGetByValueRange(None, aerospike.MAP_RETURN_VALUE, 3, 7, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapGetByValueRelRankRange(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items nearest to value and greater by relative rank with a count limit. Expression returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value (TypeValue) – Value or value expression to get items relative to.
rank (TypeRank) – Rank integer expression. rank relative to “value” to start getting elements.
count (TypeCount) – Integer value or integer value expression, how many elements to get.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# {"key1": 1, "key2": 2, "key3": 3, "key4": 10} # Get next two largest values greater than a value of 1 expr = exp.MapGetByValueRelRankRange(None, aerospike.MAP_RETURN_VALUE, 1, 1, 2, exp.MapBin("b")).compile() # [2, 3]
- class aerospike_helpers.expressions.map.MapGetByValueRelRankRangeToEnd(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that selects map items nearest to value and greater by relative rank, Expression returns selected data specified by return_type.
- __init__(ctx: TypeCTX, return_type: int, value: TypeValue, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
value (TypeValue) – Value or value expression to get items relative to.
rank (TypeRank) – Rank integer expression. rank relative to “value” to start getting elements.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Expression.
Example:
# Get the values of all elements in map bin "b" larger than 3. expr = exp.MapGetByValueRelRankRangeToEnd(None, aerospike.MAP_RETURN_VALUE, 3, 1, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapIncrement(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)
Create an expression that increments a map value, by value, for all items identified by key. Valid only for numbers.
- __init__(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of Map policies.
key (TypeKey) – Key value or value expression element to increment.
value (TypeValue) – Increment element by value expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Map expression.
Example:
# Increment element at 'vageta' in map bin "b" by 9000. expr = exp.MapIncrement(None, None, 'vageta', 9000, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapPut(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)
Create an expression that writes key/val to map bin.
- __init__(ctx: TypeCTX, policy: TypePolicy, key: TypeKey, value: TypeValue, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of Map policies.
key (TypeKey) – Key value or value expression to put into map.
value (TypeValue) – Value or value expression to put into map.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Map expression.
Example:
# Put {"key": 27} into map bin "b". expr = exp.MapPut(None, None, "key", 27, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapPutItems(ctx: TypeCTX, policy: TypePolicy, map: map, bin: TypeBinName)
Create an expression that writes each map item to map bin.
- __init__(ctx: TypeCTX, policy: TypePolicy, map: map, bin: TypeBinName)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.policy (TypePolicy) – Optional dictionary of Map policies.
map (map) – Map or map expression of items to put into target map.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.
- Returns:
Map expression.
Example:
# Put {27: 'key27', 28: 'key28'} into map bin "b". expr = exp.MapPutItems(None, None, {27: 'key27', 28: 'key28'}, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapRemoveByIndex(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
Create an expression that removes map item identified by index.
- __init__(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName)
- Parameters:
- Returns:
Map expression.
Example:
# Remove element with smallest key from map bin "b". expr = exp.MapRemoveByIndex(None, 0, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapRemoveByIndexRange(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that removes count map items starting at specified index.
- __init__(ctx: TypeCTX, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.index (TypeIndex) – Starting index integer or integer expression of elements to remove.
count (TypeCount) – Integer or integer expression, how many elements to remove.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Map expression.
Example:
# Get size of map bin "b" after index 3, 4, and 5 have been removed. expr = exp.MapSize(None, exp.MapRemoveByIndexRange(None, 3, 3, exp.MapBin("b"))).compile()
- class aerospike_helpers.expressions.map.MapRemoveByIndexRangeToEnd(ctx: TypeCTX, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items starting at specified index to the end of map.
- class aerospike_helpers.expressions.map.MapRemoveByKey(ctx: TypeCTX, key: TypeKey, bin: TypeBinName)
Create an expression that removes a map item identified by key.
- __init__(ctx: TypeCTX, key: TypeKey, bin: TypeBinName)
- Parameters:
- Returns:
Map expression.
Example:
# Remove element at key 1 in map bin "b". expr = exp.MapRemoveByKey(None, 1, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapRemoveByKeyList(ctx: TypeCTX, keys: List[_BaseExpr | Any], bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items identified by keys.
- class aerospike_helpers.expressions.map.MapRemoveByKeyRange(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName, inverted: bool = False)
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.
- class aerospike_helpers.expressions.map.MapRemoveByKeyRelIndexRange(ctx: TypeCTX, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items nearest to key and greater by index with a count limit.
- __init__(ctx: TypeCTX, key: TypeKey, index: TypeIndex, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.key (TypeKey) – Key value or expression for key to start removing from.
index (TypeIndex) – Index integer or integer expression.
count (TypeCount) – Integer expression for how many elements to remove.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Map expression.
Example:
# Remove the next two items after key1 # {"key1": 1, "key2": 2, "key3": 3, "key4": 10} expr = exp.MapRemoveByKeyRelIndexRange(None, "key1", 1, 2, exp.MapBin("b")).compile() # {"key1": 1, "key4": 10}
- class aerospike_helpers.expressions.map.MapRemoveByKeyRelIndexRangeToEnd(ctx: TypeCTX, key: TypeKey, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items nearest to key and greater by index.
- __init__(ctx: TypeCTX, key: TypeKey, index: TypeIndex, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.key (TypeKey) – Key value or expression for key to start removing from.
index (TypeIndex) – Index integer or integer expression.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Map expression.
Example:
# {"key1": 1, "key2": 2, "key3": 3, "key4": 10} expr = exp.MapRemoveByKeyRelIndexRangeToEnd(None, "key2", 1, exp.MapBin("b")).compile() # This returns {"key1": 1, "key2": 2}
- class aerospike_helpers.expressions.map.MapRemoveByRank(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
Create an expression that removes map item identified by its value’s rank.
- __init__(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName)
- Parameters:
- Returns:
Map expression.
Example:
# Remove key with smallest value in map bin "b". expr = exp.MapRemoveByRank(None, 0, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapRemoveByRankRange(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that removes “count” map items starting at specified rank.
- __init__(ctx: TypeCTX, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.rank (TypeRank) – Rank integer or integer expression of element to start removing at.
count (TypeCount) – Count integer or integer expression of elements to remove.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Map expression.
Example:
# Remove 3 keys with the smallest values from map bin "b". expr = exp.MapRemoveByRankRange(None, 0, 3, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapRemoveByRankRangeToEnd(ctx: TypeCTX, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items starting at specified rank to the last ranked item.
- class aerospike_helpers.expressions.map.MapRemoveByValue(ctx: TypeCTX, value: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items identified by value.
- class aerospike_helpers.expressions.map.MapRemoveByValueList(ctx: TypeCTX, values: TypeListValue, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items identified by values.
- class aerospike_helpers.expressions.map.MapRemoveByValueRange(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items identified by value range (begin inclusive, end exclusive). If begin is nil, the range is less than end. If end is aerospike.CDTInfinite(), the range is greater than equal to begin.
- __init__(ctx: TypeCTX, begin: TypeValue, end: TypeValue, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.begin (TypeValue) – Begin value or value expression for range.
end (TypeValue) – End value or value expression for range.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Map expression.
Example:
# Remove list of items with values >= 3 and < 7 from map bin "b". expr = exp.MapRemoveByValueRange(None, 3, 7, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapRemoveByValueRelRankRange(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items nearest to value and greater by relative rank with a count limit.
- __init__(ctx: TypeCTX, value: TypeValue, rank: TypeRank, count: TypeCount, bin: TypeBinName, inverted: bool = False)
- Parameters:
ctx (TypeCTX) – An optional list of nested CDT
cdt_ctx
context operation objects.value (TypeValue) – Value or value expression to start removing from.
rank (TypeRank) – Integer or integer expression of rank.
count (TypeCount) – Integer count or integer expression for how many elements to remove.
bin (TypeBinName) – bin expression, such as
MapBin
orListBin
.inverted (bool) – Invert the expression’s search criteria.
- Returns:
Map expression.
Example:
# Remove the key with a value just lower than 17 expr = exp.MapRemoveByValueRelRankRange(None, 17, -1, 1, exp.MapBin("b")).compile()
- class aerospike_helpers.expressions.map.MapRemoveByValueRelRankRangeToEnd(ctx: TypeCTX, value: TypeValue, rank: TypeRank, bin: TypeBinName, inverted: bool = False)
Create an expression that removes map items nearest to value and greater by relative rank.
aerospike_helpers.expressions.bit module
Bitwise expressions contain expressions for performing bitwise operations.
Most of these operations are equivalent to the
Bitwise Operations API
for binary data.
Example:
import aerospike_helpers.expressions as exp
# Let blob bin "c" == bytearray([3] * 5).
# Count set bits starting at 3rd byte in bin "c" to get count of 6.
expr = exp.BitCount(16, 8 * 3, exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitAdd(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)
Create an expression that performs a bit_add operation. Note: integers are stored big-endian.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
value (int) – Integer value or expression for value to add.
action (int) – An aerospike bit overflow action.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
resulting blob with the bits operated on.
Example:
# Assume we have a blob bin of five bytes: bytearray([1, 1, 1, 1, 1]) expr = exp.BitAdd(None, 8, 8, 1, aerospike.BIT_OVERFLOW_FAIL, exp.BlobBin("b")).compile() # Treat the selected bits as a number and add the value to it # 00000001 00000001 00000001 00000001 00000001 # 01234567 89012345 (offset) # ^(+8) # xxxxxxxx (bits selected) # + 00000000 00000001 (value to add) # ============================================ # 00000001 00000010 00000001 00000001 00000001
- class aerospike_helpers.expressions.bitwise.BitAnd(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Create an expression that performs a bit_and operation.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
value (TypeBitValue) – Bytes value or blob expression containing bytes to use in operation.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob with the bits operated on.
Example:
# Let blob bin "c" == bytearray([1] * 5). # bitwise and `0` with the first byte of blob bin c so that the returned value is bytearray([0, 1, 1, 1, 1]) expr = exp.BitAnd(None, 0, 8, bytearray([0]), exp.BlobBin("c")).compile() # 00000001 00000001 00000001 00000001 00000001 # 01234567 (offset) # ^(+8) # xxxxxxxx (bits selected) # 00000000 (& operation) # ============================================ # 00000000 00000001 00000001 00000001 00000001
- class aerospike_helpers.expressions.bitwise.BitCount(bit_offset: int, bit_size: int, bin: TypeBinName)
Create an expression that performs a bit_count operation.
- __init__(bit_offset: int, bit_size: int, bin: TypeBinName)
- Parameters:
- Returns:
Blob, bit_size bits rounded up to the nearest byte size.
Example:
# Let blob bin "c" == bytearray([3] * 5). # Count set bits starting at 3rd byte in bin "c" to get count of 6. expr = exp.BitCount(16, 8 * 3, exp.BlobBin("c")).compile() # 00000011 00000011 00000011 00000011 00000011 # 01234567 89012345 6 (offset = 16) # 12345678 90123456 78901234 (bit count = 24) # Number of 1's = 6
- class aerospike_helpers.expressions.bitwise.BitGet(bit_offset: int, bit_size: int, bin: TypeBinName)
Create an expression that performs a bit_get operation.
- class aerospike_helpers.expressions.bitwise.BitGetInt(bit_offset: int, bit_size: int, sign: bool, bin: TypeBinName)
Create an expression that performs a bit_get_int operation.
- class aerospike_helpers.expressions.bitwise.BitInsert(policy: TypePolicy, byte_offset: int, value: TypeBitValue, bin: TypeBinName)
Create an expression that performs a bit_insert operation.
- __init__(policy: TypePolicy, byte_offset: int, value: TypeBitValue, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
byte_offset (int) – Integer byte index of where to insert the value.
value (TypeBitValue) – A bytes value or blob value expression to insert.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob containing the inserted bytes.
Example:
# Let blob bin "c" == bytearray([1] * 5). # Insert 3 so that returned value is bytearray([1, 3, 1, 1, 1, 1]). expr = exp.BitInsert(None, 1, bytearray([3]), exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitLeftScan(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)
Create an expression that performs a bit_lscan operation.
- __init__(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)
- Parameters:
- Returns:
Index of the left most bit starting from bit_offset set to value. Returns -1 if not found.
Example:
# Let blob bin "c" == bytearray([3] * 5). # Scan the first byte of bin "c" for the first bit set to 1. (should get 6) expr = exp.BitLeftScan(0, 8, True, exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitLeftShift(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)
Create an expression that performs a bit_lshift operation.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
shift (int) – Number of bits to shift by.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob with the bits operated on.
Example:
# Let blob bin "c" == bytearray([1] * 5). # Bit left shift the first byte of bin "c" to get bytearray([8, 1, 1, 1, 1]). expr = exp.BitLeftShift(None, 0, 8, 3, exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitNot(policy: TypePolicy, bit_offset: int, bit_size: int, bin: TypeBinName)
Create an expression that performs a bit_not operation.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob with the bits operated on.
Example:
# Let blob bin "c" == bytearray([255] * 5). # bitwise, not, all of "c" to get bytearray([254] * 5). expr = exp.BitNot(None, 0, 40, exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitOr(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Create an expression that performs a bit_or operation.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
value (TypeBitValue) – Bytes value or blob expression containing bytes to use in operation.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob with the bits operated on.
Example:
# Let blob bin "c" == bytearray([1] * 5). # bitwise Or `8` with the first byte of blob bin c so that the returned value is bytearray([9, 1, 1, 1, 1]). expr = exp.BitOr(None, 0, 8, bytearray([8]), exp.BlobBin("c")).compile() # 00000001 00000001 00000001 00000001 00000001 # 0 (index) # xxxxxxxx (bits applied) # 00001000 (OR operation) # ============================================ # 00001001 00000001 00000001 00000001 00000001
- class aerospike_helpers.expressions.bitwise.BitRemove(policy: TypePolicy, byte_offset: int, byte_size: int, bin: TypeBinName)
Create an expression that performs a bit_remove operation.
- __init__(policy: TypePolicy, byte_offset: int, byte_size: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
byte_offset (int) – Byte index of where to start removing from.
byte_size (int) – Number of bytes to remove.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob containing the remaining bytes.
Example:
# b = bytearray([1, 2, 3, 4, 5]) expr = exp.BitRemove(None, 1, 1, exp.BlobBin("b")).compile() # 00000001 00000010 00000011 00000100 00000101 # 0 1 (selected byte) # xxxxxxxx (byte(s) to remove) # ============================================ # 00001001 <-- 00000001 00000001 00000001
- class aerospike_helpers.expressions.bitwise.BitResize(policy: TypePolicy, byte_size: int, flags: int, bin: TypeBinName)
Create an expression that performs a bit_resize operation.
- __init__(policy: TypePolicy, byte_size: int, flags: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
byte_size (int) – Number of bytes the resulting blob should occupy.
flags (int) – One or a combination of bit resize flags.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Blob value expression of resized blob bin.
Example:
# Blob bin "c" == bytearray([1] * 5). # Resize blob bin "c" from the front so that the returned value is bytearray([0] * 5 + [1] * 5). expr = exp.BitResize(None, 10, aerospike.BIT_RESIZE_FROM_FRONT, exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitRightScan(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)
Create an expression that performs a bit_rscan operation.
- __init__(bit_offset: int, bit_size: int, value: bool, bin: TypeBinName)
- Parameters:
- Returns:
Index of the right most bit starting from bit_offset set to value. Returns -1 if not found.
Example:
# b = bytearray([1, 0, 0, 0, 128]) expr = exp.BitRightScan(32, 8, True, exp.BlobBin("b")).compile() # 00000001 00000000 00000000 00000000 10000000 # 01234567 89012345 67890123 45678901 2 (offset=32) # xxxxxxxx (selected bits) # 01234567 (local offset) # 1 found at local offset 0
- class aerospike_helpers.expressions.bitwise.BitRightShift(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)
Create an expression that performs a bit_rshift operation.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
shift (int) – Number of bits to shift by.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob with the bits operated on.
Example:
# Let blob bin "c" == bytearray([8] * 5). # Bit left shift the first byte of bin "c" to get bytearray([4, 8, 8, 8, 8]). expr = exp.BitRightShift(None, 0, 8, 1, exp.BlobBin("c")).compile() # 00001000 00001000 00001000 00001000 00001000 # 0 (offset=0) # xxxxxxxx (selected bits -> by 1 only in that region) # The rest of the bits are unaffected # 00000100 00001000 00001000 00001000 00001000
- class aerospike_helpers.expressions.bitwise.BitSet(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Create an expression that performs a bit_set operation.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start overwriting.
bit_size (int) – Number of bits to overwrite.
value (TypeBitValue) – Bytes value or blob expression containing bytes to write.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob expression with the bits overwritten.
Example:
# Let blob bin "c" == bytearray([0] * 5). # Set bit at offset 7 with size 1 bits to 1 to make the returned value bytearray([1, 0, 0, 0, 0]). expr = exp.BitSet(None, 7, 1, bytearray([255]), exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitSetInt(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, bin: TypeBinName)
Create an expression that performs a bit_set_int operation. Note: integers are stored big-endian.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start writing.
bit_size (int) – Number of bits to overwrite.
value (int) – Integer value or integer expression containing value to write.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob expression with the bits overwritten.
Example:
# Let blob bin "c" == bytearray([0] * 5). # Set bit at offset 7 with size 1 bytes to 1 to make the returned value bytearray([1, 0, 0, 0, 0]). expr = exp.BitSetInt(None, 7, 1, 1, exp.BlobBin("c")).compile()
- class aerospike_helpers.expressions.bitwise.BitSubtract(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)
Create an expression that performs a bit_subtract operation. Note: integers are stored big-endian.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: int, action: int, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
value (int) – Integer value or expression for value to add.
action (int) – An aerospike bit overflow action.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
resulting blob with the bits operated on.
Example:
# Let blob bin "c" == bytearray([1] * 5). # Bit subtract the second byte of bin "c" to get bytearray([1, 0, 1, 1, 1]) expr = exp.BitSubtract(None, 8, 8, 1, aerospike.BIT_OVERFLOW_FAIL).compile()
- class aerospike_helpers.expressions.bitwise.BitXor(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
Create an expression that performs a bit_xor operation.
- __init__(policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – Optional dictionary of Bit policies.
bit_offset (int) – Bit index of where to start operation.
bit_size (int) – Number of bits to be operated on.
value (TypeBitValue) – Bytes value or blob expression containing bytes to use in operation.
bin (TypeBinName) – A
BlobBin
expression.
- Returns:
Resulting blob with the bits operated on.
Example:
# Let blob bin "c" == bytearray([1] * 5). # bitwise Xor `1` with the first byte of blob bin c so that the returned value is bytearray([0, 1, 1, 1, 1]) expr = exp.BitXor(None, 0, 8, bytearray([1]), exp.BlobBin("c")).compile()
aerospike_helpers.expressions.hll module
HyperLogLog expressions contain expressions for performing HLL operations.
Most of these operations are equivalent to the HyperLogLog API
.
- class aerospike_helpers.expressions.hll.HLLAdd(policy: TypePolicy, list: TypeListValue, index_bit_count: int | None, mh_bit_count: int | None, bin: TypeBinName)
Create an expression that performs an hll_add.
- __init__(policy: TypePolicy, list: TypeListValue, index_bit_count: int | None, mh_bit_count: int | None, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – An optional dictionary of HyperLogLog policies.
list (TypeListValue) – A list or list expression of elements to add to the HLL.
index_bit_count (int) – Number of index bits. Must be between 4 and 16 inclusive.
mh_bit_count (int) – Number of min hash bits. Must be between 4 and 51 inclusive.
bin (TypeBinName) – An
HLLBin
expression.
- Returns:
Returns the resulting hll bin after adding elements from list.
Example:
# Let HLL bin "d" have the following elements, ['key1', 'key2', 'key3'], index_bits 8, mh_bits 8. # Add ['key4', 'key5', 'key6'] so that the returned value is ['key1', 'key2', 'key3', 'key4', 'key5', # 'key6'] expr = exp.HLLAdd(None, ['key4', 'key5', 'key6'], 8, 8, exp.HLLBin("d")).compile()
- class aerospike_helpers.expressions.hll.HLLDescribe(bin: TypeBinName)
Create an expression that performs an as_operations_hll_describe.
- class aerospike_helpers.expressions.hll.HLLGetCount(bin: TypeBinName)
Create an expression that performs an as_operations_hll_get_count.
- class aerospike_helpers.expressions.hll.HLLGetIntersectCount(values: TypeValue, bin: TypeBinName)
Create an expression that performs an as_operations_hll_get_intersect_count.
- __init__(values: TypeValue, bin: TypeBinName)
- Parameters:
values (TypeValue) – A single HLL or list of HLLs, values or expressions, to intersect with bin.
bin (TypeBinName) – An
HLLBin
expression.
- Returns:
Integer bin, estimated number of elements in the set intersection.
Example:
# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)]. # Let values be a list containing one HLL object with keys ['key%s' % str(i) for i in range(5000, 15000)]. # Find the count of keys in the intersection of HLL bin "d" and all HLLs in values. (Should be around 5000) expr = exp.HLLGetIntersectCount(values, exp.HLLBin("d")).compile()
- class aerospike_helpers.expressions.hll.HLLGetSimilarity(values: TypeValue, bin: TypeBinName)
Create an expression that performs an as_operations_hll_get_similarity.
- __init__(values: TypeValue, bin: TypeBinName)
- Parameters:
values (TypeValue) – A single HLL or list of HLLs, values or expressions, to calculate similarity with.
bin (TypeBinName) – An
HLLBin
expression.
- Returns:
Float bin, estimated similarity between 0.0 and 1.0.
Example:
# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)]. # Let values be a list containing one HLL object with keys ['key%s' % str(i) for i in range(5000, 15000)]. # Find the similarity the HLL in values to HLL bin "d". (Should be around 0.33) # Note that similarity is defined as intersect(A, B, ...) / union(A, B, ...). expr = exp.HLLGetSimilarity(values, exp.HLLBin("d")).compile()
- class aerospike_helpers.expressions.hll.HLLGetUnion(values: TypeValue, bin: TypeBinName)
Create an expression that performs an hll_get_union.
- __init__(values: TypeValue, bin: TypeBinName)
- Parameters:
values (TypeValue) – A single HLL or list of HLLs, values or expressions, to union with bin.
bin (TypeBinName) – An
HLLBin
expression.
- Returns:
HLL bin representing the set union.
Example:
# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)]. # Let values be a list containing HLL objects retrieved from the aerospike database. # Find the union of HLL bin "d" and all HLLs in values. expr = exp.HLLGetUnion(values, exp.HLLBin("d")).compile()
- class aerospike_helpers.expressions.hll.HLLGetUnionCount(values: TypeValue, bin: TypeBinName)
Create an expression that performs an as_operations_hll_get_union_count.
- __init__(values: TypeValue, bin: TypeBinName)
- Parameters:
values (TypeValue) – A single HLL or list of HLLs, values or expressions, to union with bin.
bin (TypeBinName) – An
HLLBin
expression.
- Returns:
Integer bin, estimated number of elements in the set union.
Example:
# Let HLLBin "d" contain keys ['key%s' % str(i) for i in range(10000)]. # Let values be a list containing one HLL object with keys ['key%s' % str(i) for i in range(5000, 15000)]. # Find the count of keys in the union of HLL bin "d" and all HLLs in values. (Should be around 15000) expr = exp.HLLGetUnionCount(values, exp.HLLBin("d")).compile()
- class aerospike_helpers.expressions.hll.HLLInit(policy: TypePolicy, index_bit_count: int | None, mh_bit_count: int | None, bin: TypeBinName)
Creates a new HLL or resets an existing HLL. If index_bit_count and mh_bit_count are None, an existing HLL bin will be reset but retain its configuration. If 1 of index_bit_count or mh_bit_count are set, an existing HLL bin will set that config and retain its current value for the unset config. If the HLL bin does not exist, index_bit_count is required to create it, mh_bit_count is optional.
- __init__(policy: TypePolicy, index_bit_count: int | None, mh_bit_count: int | None, bin: TypeBinName)
- Parameters:
policy (TypePolicy) – An optional dictionary of HyperLogLog policies.
index_bit_count (int) – Number of index bits. Must be between 4 and 16 inclusive.
mh_bit_count (int) – Number of min hash bits. Must be between 4 and 51 inclusive.
bin (TypeBinName) – An
HLLBin
expression.
- Returns:
Returns the resulting hll.
Example:
# Create an HLL with 12 index bits and 24 min hash bits. expr = exp.HLLInit(None, 12, 24, exp.HLLBin("my_hll"))
- class aerospike_helpers.expressions.hll.HLLMayContain(list: TypeListValue, bin: TypeBinName)
Create an expression that checks if the HLL bin may contain any of the keys in list.
- __init__(list: TypeListValue, bin: TypeBinName)
- Parameters:
list (TypeListValue) – A list expression of keys to check if the HLL may contain any of them.
bin (TypeBinName) – An
HLLBin
expression.
- Returns:
1 if bin may contain any key in list, 0 otherwise.
Example:
# Check if HLL bin "d" may contain any of the keys in `list`. expr = exp.HLLMayContain(["key1", "key2", "key3"], exp.HLLBin("d")).compile()
aerospike_helpers.expressions.arithmetic module
Arithmetic expressions provide arithmetic operator support for Aerospike expressions.
- class aerospike_helpers.expressions.arithmetic.Abs(value: TypeNumber)
Create operator that returns absolute value of a number. All arguments must resolve to integer or float.
Abs is also available via operator overloading using the built-in abs() function and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(value: TypeNumber)
- Parameters:
value (TypeNumber) – Float or integer expression or value to take absolute value of.
- Returns:
(number value)
Example:
# For int bin "a", abs("a") == 1 expr = exp.Eq(exp.Abs(exp.IntBin("a")), 1).compile() # Using operator overloading expr = exp.Eq(abs(exp.IntBin("a")), 1).compile()
- class aerospike_helpers.expressions.arithmetic.Add(*args: TypeNumber)
Create an add, (+) expression. All arguments must be the same type (integer or float).
Add is also available via operator overloading using + and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(*args: TypeNumber)
- Parameters:
*args (TypeNumber) – Variable amount of float or integer expressions or values to be added together.
- Returns:
(integer or float value).
Example:
# Integer bin "a" + "b" == 11 expr = exp.Eq(exp.Add(exp.IntBin("a"), exp.IntBin("b")), 11).compile() # Using operator overloading. expr = exp.Eq(exp.IntBin("a") + exp.IntBin("b"), 11).compile()
- class aerospike_helpers.expressions.arithmetic.Ceil(value: TypeFloat)
Create ceil expression that rounds a floating point number up to the closest integer value.
Ceil is also available via operator overloading using the math.ceil() function and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(value: TypeFloat)
- Parameters:
value (TypeFloat) – Float expression or value to take ceiling of.
- Returns:
(float value)
Example:
# Ceil(2.25) == 3.0 expr = exp.Eq(exp.Ceil(2.25), 3.0).compile() # Using operator overloading import math expr = exp.Eq(math.ceil(2.25), 3.0).compile()
- class aerospike_helpers.expressions.arithmetic.Div(*args: TypeNumber)
Create “divide” (/) operator that applies to a variable number of expressions. If there is only one argument, returns the reciprocal for that argument. Otherwise, return the first argument divided by the product of the rest. All arguments must resolve to the same type (integer or float).
Div is also available via operator overloading using / and any subclass of _BaseExpr. See the second example.
Floor div is also available via // but must be used with floats.
Requires server version 5.6.0+.
- __init__(*args: TypeNumber)
- Parameters:
*args (TypeNumber) – Variable amount of float or integer expressions or values to be divided.
- Returns:
(integer or float value)
Example:
# Integer bin "a" / "b" / "c" >= 11 expr = exp.GE(exp.Div(exp.IntBin("a"), exp.IntBin("b"), exp.IntBin("c")), 11).compile() # Using operator overloading. expr = exp.GE(exp.IntBin("a") / exp.IntBin("b") / exp.IntBin("c"), 11).compile() # Float bin "a" // "b" // "c" >= 11.0 expr = exp.GE(exp.FloatBin("a") // exp.FloatBin("b") // exp.FloatBin("c"), 11.0).compile()
- class aerospike_helpers.expressions.arithmetic.Floor(value: TypeFloat)
Create floor expression that rounds a floating point number down to the closest integer value.
Floor is also available via operator overloading using the math.floor() function and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(value: TypeFloat)
- Parameters:
value (TypeFloat) – Float expression or value to take floor of.
- Returns:
(float value)
Example:
# Floor(2.25) == 2.0 expr = exp.Eq(exp.Floor(2.25), 2.0).compile() # Using operator overloading import math expr = exp.Eq(math.floor(2.25), 2.0).compile()
- class aerospike_helpers.expressions.arithmetic.Log(num: TypeFloat, base: TypeFloat)
Create “log” operator for logarithm of “num” with base “base”. All arguments must resolve to floats.
Requires server version 5.6.0+.
- __init__(num: TypeFloat, base: TypeFloat)
- Parameters:
num (TypeFloat) – Float expression or value number.
base (TypeFloat) – Float expression or value base.
- Returns:
(float value)
Example:
# For float bin "a", log("a", 2.0) == 16.0 expr = exp.Eq(exp.Log(exp.FloatBin("a"), 2.0), 16.0).compile()
- class aerospike_helpers.expressions.arithmetic.Max(*args: TypeNumber)
Create expression that returns the maximum value in a variable number of expressions. All arguments must be the same type (integer or float).
Requires server version 5.6.0+.
- __init__(*args: TypeNumber)
- Parameters:
*args (TypeNumber) – Variable amount of float or integer expressions or values from which to find the
value. (maximum) –
- Returns:
(integer or float value).
Example:
# for integer bins a, b, c, max(a, b, c) > 100 expr = exp.GT(exp.Max(exp.IntBin("a"), exp.IntBin("b"), exp.IntBin("c")), 100).compile()
- class aerospike_helpers.expressions.arithmetic.Min(*args: TypeNumber)
Create expression that returns the minimum value in a variable number of expressions. All arguments must be the same type (integer or float).
Requires server version 5.6.0+.
- __init__(*args: TypeNumber)
- Parameters:
*args (TypeNumber) – Variable amount of float or integer expressions or values from which to find the
value. (minimum) –
- Returns:
(integer or float value).
Example:
# for integer bins a, b, c, min(a, b, c) > 0 expr = exp.GT(exp.Min(exp.IntBin("a"), exp.IntBin("b"), exp.IntBin("c")), 0).compile()
- class aerospike_helpers.expressions.arithmetic.Mod(numerator: TypeInteger, denominator: TypeInteger)
Create “modulo” (%) operator that determines the remainder of “numerator” divided by “denominator”. All arguments must resolve to integers.
Mod is also available via operator overloading using % and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(numerator: TypeInteger, denominator: TypeInteger)
- Parameters:
numerator (TypeInteger) – Integer expression or value numerator.
denominator (TypeInteger) – Integer expression or value denominator.
- Returns:
(integer value)
Example:
# For int bin "a" % 10 == 0 expr = exp.Eq(exp.Mod(exp.IntBin("a"), 10), 0).compile() # Using operator overloading. expr = exp.Eq(exp.IntBin("a") % 10, 0).compile()
- class aerospike_helpers.expressions.arithmetic.Mul(*args: TypeNumber)
Create “multiply” (*) operator that applies to a variable number of expressions. Return the product of all arguments. If only one argument is supplied, return that argument. All arguments must resolve to the same type (integer or float).
Mul is also available via operator overloading using * and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(*args: TypeNumber)
- Parameters:
*args (TypeNumber) – Variable amount of float or integer expressions or values to be multiplied.
- Returns:
(integer or float value)
Example:
# Integer bin "a" * "b" >= 11 expr = exp.GE(exp.Mul(exp.IntBin("a"), exp.IntBin("b")), 11).compile() # Using operator overloading. expr = exp.GE(exp.IntBin("a") * exp.IntBin("b"), 11).compile()
- class aerospike_helpers.expressions.arithmetic.Pow(base: TypeFloat, exponent: TypeFloat)
Create “pow” operator that raises a “base” to the “exponent” power. All arguments must resolve to floats.
Pow is also available via operator overloading using ** and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(base: TypeFloat, exponent: TypeFloat)
- Parameters:
base (TypeFloat) – Float expression or value base.
exponent (TypeFloat) – Float expression or value exponent.
- Returns:
(float value)
Example:
# Float bin "a" ** 2.0 == 16.0 expr = exp.Eq(exp.Pow(exp.FloatBin("a"), 2.0), 16.0).compile() # Using operator overloading. expr = exp.Eq(exp.FloatBin("a") ** 2.0, 16.0).compile()
- class aerospike_helpers.expressions.arithmetic.Sub(*args: TypeNumber)
Create “subtract” (-) operator that applies to a variable number of expressions. If only one argument is provided, return the negation of that argument. Otherwise, return the sum of the 2nd to Nth argument subtracted from the 1st argument. All arguments must resolve to the same type (integer or float).
Sub is also available via operator overloading using - and any subclass of _BaseExpr. See the second example.
Requires server version 5.6.0+.
- __init__(*args: TypeNumber)
- Parameters:
*args (TypeNumber) – Variable amount of float or integer expressions or values to be subtracted.
- Returns:
(integer or float value)
Example:
# Integer bin "a" - "b" == 11 expr = exp.Eq(exp.Sub(exp.IntBin("a"), exp.IntBin("b")), 11).compile() # Using operator overloading. expr = exp.Eq(exp.IntBin("a") - exp.IntBin("b"), 11).compile()
- class aerospike_helpers.expressions.arithmetic.ToFloat(value: TypeInteger)
Create expression that converts an integer to a float.
Requires server version 5.6.0+.
- __init__(value: TypeInteger)
- Parameters:
value (TypeInteger) – Integer expression or value to convert to float.
- Returns:
(float value)
Example:
#For int bin "a", float(exp.IntBin("a")) == 2 expr = exp.Eq(exp.ToFloat(exp.IntBin("a")), 2).compile()
- class aerospike_helpers.expressions.arithmetic.ToInt(value: TypeFloat)
Create expression that converts a float to an integer.
Requires server version 5.6.0+.
- __init__(value: TypeFloat)
- Parameters:
value (TypeFloat) – Float expression or value to convert to int.
- Returns:
(integer value)
Example:
#For float bin "a", int(exp.FloatBin("a")) == 2 expr = exp.Eq(exp.ToInt(exp.FloatBin("a")), 2).compile()
aerospike_helpers.expressions.bitwise_operators module
Bitwise operator expressions provide support for bitwise operators like & and >> in Aerospike expressions.
- class aerospike_helpers.expressions.bitwise_operators.IntAnd(*exprs: TypeInteger)
Create integer “and” (&) operator expression that is applied to two or more integers. All arguments must resolve to integers.
Requires server version 5.6.0+.
- __init__(*exprs: TypeInteger)
- Parameters:
*exprs (TypeInteger) – A variable amount of integer expressions or values to be bitwise ANDed.
- Returns:
(integer value)
Example:
# for int bin "a", a & 0xff == 0x11 expr = exp.Eq(exp.IntAnd(exp.IntBin("a"), 0xff), 0x11).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntArithmeticRightShift(value: TypeInteger, shift: TypeInteger)
Create integer “arithmetic right shift” (>>) operator.
Requires server version 5.6.0+.
- __init__(value: TypeInteger, shift: TypeInteger)
- Parameters:
value (TypeInteger) – An integer value or expression to be right shifted.
shift (TypeInteger) – An integer value or expression for number of bits to right shift value by.
- Returns:
(integer value)
Example:
# for int bin "a", a >> 8 > 0xff expr = exp.GT(exp.IntArithmeticRightShift(exp.IntBin("a"), 8), 0xff).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntCount(value: TypeInteger)
Create expression that returns count of integer bits that are set to 1.
Requires server version 5.6.0+.
- __init__(value: TypeInteger)
- Parameters:
value (TypeInteger) – An integer value or expression to have bits counted.
- Returns:
(integer value)
Example:
# for int bin "a", count(a) == 4 expr = exp.Eq(exp.IntCount(exp.IntBin("a")), 4).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntLeftScan(value: TypeInteger, search: TypeBool)
Create expression that scans integer bits from left (most significant bit) to right (least significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan will search for the bit value 1. If “search” is false it will search for bit value 0.
Requires server version 5.6.0+.
- __init__(value: TypeInteger, search: TypeBool)
- Parameters:
value (TypeInteger) – An integer value or expression to be scanned.
search (TypeBool) – A bool expression or value to scan for.
- Returns:
(integer value)
Example:
# for int bin "a", lscan(a, True) == 4 expr = exp.GT(exp.IntLeftScan(exp.IntBin("a"), True), 4).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntLeftShift(value: TypeInteger, shift: TypeInteger)
Create integer “left shift” (<<) operator.
Requires server version 5.6.0+.
- __init__(value: TypeInteger, shift: TypeInteger)
- Parameters:
value (TypeInteger) – An integer value or expression to be left shifted.
shift (TypeInteger) – An integer value or expression for number of bits to left shift value by.
- Returns:
(integer value)
Example:
# for int bin "a", a << 8 > 0xff expr = exp.GT(exp.IntLeftShift(exp.IntBin("a"), 8), 0xff).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntNot(expr: TypeInteger)
Create integer “not” (~) operator.
Requires server version 5.6.0+.
- __init__(expr: TypeInteger)
- Parameters:
expr (TypeInteger) – An integer value or expression to be bitwise negated.
- Returns:
(integer value)
Example:
# for int bin "a", ~ a == 7 expr = exp.Eq(exp.IntNot(exp.IntBin("a")), 7).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntOr(*exprs: TypeInteger)
Create integer “or” (|) operator expression that is applied to two or more integers. All arguments must resolve to integers.
Requires server version 5.6.0+.
- __init__(*exprs: TypeInteger)
- Parameters:
*exprs (TypeInteger) – A variable amount of integer expressions or values to be bitwise ORed.
- Returns:
(integer value)
Example:
# for int bin "a", a | 0x10 not == 0 expr = exp.NE(exp.IntOr(IntBin("a"), 0x10), 0).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntRightScan(value: TypeInteger, search: TypeBool)
Create expression that scans integer bits from right (least significant bit) to left (most significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan will search for the bit value 1. If “search” is false it will search for bit value 0.
Requires server version 5.6.0+.
- __init__(value: TypeInteger, search: TypeBool)
- Parameters:
value (TypeInteger) – An integer value or expression to be scanned.
search (TypeBool) – A bool expression or value to scan for.
- Returns:
(integer value)
Example:
# for int bin "a", rscan(a, True) == 4 expr = exp.GT(exp.IntRightScan(exp.IntBin("a"), True), 4).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntRightShift(value: TypeInteger, shift: TypeInteger)
Create integer “logical right shift” (>>>) operator.
Requires server version 5.6.0+.
- __init__(value: TypeInteger, shift: TypeInteger)
- Parameters:
value (TypeInteger) – An integer value or expression to be right shifted.
shift (TypeInteger) – An integer value or expression for number of bits to right shift value by.
- Returns:
(integer value)
Example:
# for int bin "a", a >>> 8 > 0xff expr = exp.GT(exp.IntRightShift(exp.IntBin("a"), 8), 0xff).compile()
- class aerospike_helpers.expressions.bitwise_operators.IntXOr(*exprs: TypeInteger)
Create integer “xor” (^) operator that is applied to two or more integers. All arguments must resolve to integers.
Requires server version 5.6.0+.
- __init__(*exprs: TypeInteger)
- Parameters:
*exprs (TypeInteger) – A variable amount of integer expressions or values to be bitwise XORed.
- Returns:
(integer value)
Example:
# for int bin "a", "b", a ^ b == 16 expr = exp.Eq(exp.IntXOr(exp.IntBin("a"), exp.IntBin("b")), 16).compile()
aerospike_helpers.expressions.resources module
Resources used by all expressions.