def __init__(self, policy: TypePolicy, byte_size: int, flags: int, bin: TypeBinName): """ Create an expression that performs a bit_resize operation. Args: policy (TypePolicy): An optional aerospike bit policy. byte_size (int): Number of bytes the resulting blob should occupy. flags (int): One or a combination of bit resize flags. bin (TypeBinName): Blob bin name or blob value expression. :return: Blob value expression of resized blob bin. Example:: # Blob bin "c" == bytearray([1] * 5). # Resize blob bin "c" from the front so that the returned value is bytearray([0] * 5 + [1] * 5). expr = BitResize(None, 10, aerospike.BIT_RESIZE_FROM_FRONT, BlobBin("c")).compile() """ self._children = ( byte_size, _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: policy['bit_write_flags']} if policy is not None and 'bit_write_flags' in policy else {_Keys.VALUE_KEY: 0}), _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: flags} if flags is not None else {_Keys.VALUE_KEY: 0}), bin if isinstance(bin, _BaseExpr) else BlobBin(bin))
def __init__(self, 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. Args: policy (TypePolicy): An optional aerospike bit policy. bit_offset (int): Bit index of where to start operation. bit_size (int): Number of bits to be operated on. value (int): Integer value or expression for value to add. action (int): An aerospike bit overflow action. bin (TypeBinName): Blob bin name or blob expression. :return: resulting blob with the bits operated on. Example:: # Let blob bin "c" == bytearray([1] * 5). # Bit subtract the second byte of bin "c" to get bytearray([1, 0, 1, 1, 1]) expr = BitSubtract(None, 8, 8, 1, aerospike.BIT_OVERFLOW_FAIL).compile() """ self._children = ( bit_offset, bit_size, value, _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: policy['bit_write_flags']} if policy is not None and 'bit_write_flags' in policy else {_Keys.VALUE_KEY: 0}), _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: action} if action is not None else {_Keys.VALUE_KEY: 0}), bin if isinstance(bin, _BaseExpr) else BlobBin(bin))
def __init__(self, policy: TypePolicy, byte_offset: int, value: TypeBitValue, bin: TypeBinName): """ Create an expression that performs a bit_insert operation. Args: policy (TypePolicy): An optional aerospike bit policy. byte_offset (int): Integer byte index of where to insert the value. value (TypeBitValue): A bytes value or blob value expression to insert. bin (TypeBinName): Blob bin name or blob value expression. :return: Resulting blob containing the inserted bytes. Example:: # Let blob bin "c" == bytearray([1] * 5). # Insert 3 so that returned value is bytearray([1, 3, 1, 1, 1, 1]). expr = BitInsert(None, 1, bytearray([3]), BlobBin("c")).compile() """ self._children = ( byte_offset, value, _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: policy['bit_write_flags']} if policy is not None and 'bit_write_flags' in policy else {_Keys.VALUE_KEY: 0}), bin if isinstance(bin, _BaseExpr) else BlobBin(bin))
def __init__(self, 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. Args: policy (TypePolicy): An optional aerospike bit policy. bit_offset (int): Bit index of where to start writing. bit_size (int): Number of bits to overwrite. value (int): Integer value or integer expression containing value to write. bin (TypeBinName): Blob bin name or blob expression. :return: Resulting blob expression with the bits overwritten. Example:: # Let blob bin "c" == bytearray([0] * 5). # Set bit at offset 7 with size 1 bytes to 1 to make the returned value bytearray([1, 0, 0, 0, 0]). expr = BitSetInt(None, 7, 1, 1, BlobBin("c")).compile() """ self._children = ( bit_offset, bit_size, value, _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: policy['bit_write_flags']} if policy is not None and 'bit_write_flags' in policy else {_Keys.VALUE_KEY: 0}), bin if isinstance(bin, _BaseExpr) else BlobBin(bin))
def __init__(self, policy: TypePolicy, bit_offset: int, bit_size: int, value: TypeBitValue, bin: TypeBinName): """ Create an expression that performs a bit_and operation. Args: policy (TypePolicy): An optional aerospike bit policy. bit_offset (int): Bit index of where to start operation. bit_size (int): Number of bits to be operated on. value (TypeBitValue): Bytes value or blob expression containing bytes to use in operation. bin (TypeBinName): Blob bin name or blob expression. :return: Resulting blob with the bits operated on. Example:: # Let blob bin "c" == bytearray([1] * 5). # bitwise and `0` with the first byte of blob bin c so that the returned value is bytearray([0, 5, 5, 5, 5]). expr = BitAnd(None, 0, 8, bytearray([0]), BlobBin("c")).compile() """ self._children = ( bit_offset, bit_size, value, _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: policy['bit_write_flags']} if policy is not None and 'bit_write_flags' in policy else {_Keys.VALUE_KEY: 0}), bin if isinstance(bin, _BaseExpr) else BlobBin(bin))
def __init__(self, policy: TypePolicy, bit_offset: int, bit_size: int, shift: int, bin: TypeBinName): """ Create an expression that performs a bit_rshift operation. Args: policy (TypePolicy): An optional aerospike bit policy. bit_offset (int): Bit index of where to start operation. bit_size (int): Number of bits to be operated on. shift (int): Number of bits to shift by. bin (TypeBinName): Blob bin name or blob expression. :return: Resulting blob with the bits operated on. Example:: # Let blob bin "c" == bytearray([8] * 5). # Bit left shift the first byte of bin "c" to get bytearray([4, 8, 8, 8, 8]). expr = BitRightShift(None, 0, 8, 1, BlobBin("c")).compile() """ self._children = ( bit_offset, bit_size, shift, _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: policy['bit_write_flags']} if policy is not None and 'bit_write_flags' in policy else {_Keys.VALUE_KEY: 0}), bin if isinstance(bin, _BaseExpr) else BlobBin(bin))
def __init__(self, policy: TypePolicy, byte_offset: int, byte_size: int, bin: TypeBinName): """ Create an expression that performs a bit_remove operation. Args: policy (TypePolicy): An optional aerospike bit policy. byte_offset (int): Byte index of where to start removing from. byte_size (int): Number of bytes to remove. bin (TypeBinName): Blob bin name or blob value expression. :return: Resulting blob containing the remaining bytes. Example:: # Let blob bin "c" == bytearray([1] * 5). # Remove 1 element so that the returned value is bytearray([1] * 4). expr = BitRemove(None, 1, 1, BlobBin("c")).compile() """ self._children = ( byte_offset, byte_size, _GenericExpr(_ExprOp._AS_EXP_BIT_FLAGS, 0, {_Keys.VALUE_KEY: policy['bit_write_flags']} if policy is not None and 'bit_write_flags' in policy else {_Keys.VALUE_KEY: 0}), bin if isinstance(bin, _BaseExpr) else BlobBin(bin))
def __init__(self, ctx: TypeCDT, policy: TypePolicy, value: TypeValue, bin: TypeBinName): """ Create an expression that appends a list of items to the end of a list. Args: ctx (TypeCDT): Optional context path for nested CDT. policy (TypePolicy): Optional dictionary of list write options :ref:`list write options <aerospike_list_policies>`. value (TypeValue): List or list expression of items to be appended. bin (TypeBinName): Bin name or list expression. :return: List expression. Example:: # Check if length of list bin "a" is > 5 after appending multiple items. expr = GT( ListSize(None, ListAppendItems(None, None, [3, 2], ListBin("a"))), 5).compile() """ self._children = (value, _GenericExpr(_ExprOp._AS_EXP_CODE_CDT_LIST_CRMOD, 0, {_Keys.LIST_POLICY_KEY: policy} if policy is not None else {}), bin if isinstance(bin, _BaseExpr) else ListBin(bin)) self._fixed = {} if ctx is not None: self._fixed[_Keys.CTX_KEY] = ctx if policy is not None: self._fixed[_Keys.LIST_POLICY_KEY] = policy
def __init__(self, ctx: TypeCDT, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName): """ Create an expression that sets item value at specified index in list. Args: ctx (TypeCDT): Optional context path for nested CDT. policy (TypePolicy): Optional dictionary of list write options :ref:`list write options <aerospike_list_policies>`.Optional list write policy. index (TypeIndex): index of value to set. value (TypeValue): value or value expression to set index in list to. bin (TypeBinName): bin name or list expression. :return: List expression. Example:: # Get smallest element in list bin "a" after setting index 1 to 10. expr = ListGetByRank(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, 0, ListSet(None, None, 1, 10, ListBin("a"))).compile() """ self._children = (index, value, _GenericExpr(_ExprOp._AS_EXP_CODE_CDT_LIST_MOD, 0, {_Keys.LIST_POLICY_KEY: policy} if policy is not None else {}), bin if isinstance(bin, _BaseExpr) else ListBin(bin)) self._fixed = {} if ctx is not None: self._fixed[_Keys.CTX_KEY] = ctx if policy is not None: self._fixed[_Keys.LIST_POLICY_KEY] = policy
def __init__(self, ctx: TypeCDT, policy: TypePolicy, index: TypeIndex, value: TypeValue, bin: TypeBinName): """ Create an expression that increments list[index] by value. Args: ctx (TypeCDT): Optional context path for nested CDT. policy (TypePolicy): Optional dictionary of list write options :ref:`list write options <aerospike_list_policies>`.Optional list write policy. index (TypeIndex): Index of value to increment. value (TypeValue): Value or value expression. bin (TypeBinName): Bin name or list expression. :return: List expression. Example:: # Check if incremented value in list bin "a" is the largest in the list. expr = Eq( ListGetByRank(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, -1, #rank of -1 == largest element. ListIncrement(None, None, 1, 5, ListBin("a"))), ListGetByIndex(None, aerospike.LIST_RETURN_VALUE, ResultType.INTEGER, 1, ListIncrement(None, None, 1, 5, ListBin("a"))) ).compile() """ self._children = (index, value, _GenericExpr(_ExprOp._AS_EXP_CODE_CDT_LIST_CRMOD, 0, {_Keys.LIST_POLICY_KEY: policy} if policy is not None else {}), bin if isinstance(bin, _BaseExpr) else ListBin(bin)) self._fixed = {} if ctx is not None: self._fixed[_Keys.CTX_KEY] = ctx if policy is not None: self._fixed[_Keys.LIST_POLICY_KEY] = policy
def __init__(self, ctx: TypeCDT, policy: TypePolicy, index: TypeIndex, values: TypeListValue, bin: TypeBinName): """ Create an expression that inserts each input list item starting at specified index of list. Args: ctx (TypeCDT): Optional context path for nested CDT. policy (TypePolicy): Optional dictionary of list write options :ref:`list write options <aerospike_list_policies>`.Optional list write policy. index (TypeIndex): Target index where item insertion will begin, integer or integer expression. values (TypeListValue): List or list expression of items to be inserted. bin (TypeBinName): Bin name or list expression. :return: List expression. Example:: # Check if list bin "a" has length > 5 after inserting items. expr = GT( ListSize(None, ListInsertItems(None, None, 0, [4, 7], ListBin("a"))), 5).compile() """ self._children = (index, values, _GenericExpr(_ExprOp._AS_EXP_CODE_CDT_LIST_MOD, 0, {_Keys.LIST_POLICY_KEY: policy} if policy is not None else {}), bin if isinstance(bin, _BaseExpr) else ListBin(bin)) self._fixed = {} if ctx is not None: self._fixed[_Keys.CTX_KEY] = ctx if policy is not None: self._fixed[_Keys.LIST_POLICY_KEY] = policy
def __init__(self, *exprs): """ Create an "or" operator that applies to a variable amount of expressions. Args: `*exprs` (_BaseExpr): Variable amount of expressions to be ORed together. :return: (boolean value) Example:: # (a == 0 || b == 0) expr = Or( Eq(IntBin("a"), 0), Eq(IntBin("b"), 0)).compile() """ self._children = exprs + (_GenericExpr(_ExprOp._AS_EXP_CODE_END_OF_VA_ARGS, 0, {}),)
def __init__(self, *exprs: _BaseExpr): """ Create an "and" operator that applies to a variable amount of expressions. Args: `*exprs` (_BaseExpr): Variable amount of expressions to be ANDed together. :return: (boolean value) Example:: # (a > 5 || a == 0) && b < 3 expr = And( Or( GT(IntBin("a"), 5), Eq(IntBin("a"), 0)), LT(IntBin("b"), 3)).compile() """ self._children = exprs self._children = exprs + (_GenericExpr(_ExprOp._AS_EXP_CODE_END_OF_VA_ARGS, 0, {}),)