/// <summary> /// Create map put items operation /// Server writes each map item to map bin and returns map size. /// <para> /// The required map policy dictates the type of map to create when it does not exist. /// The map policy also specifies the flags used when writing items to the map. /// See policy <see cref="Aerospike.Client.MapPolicy"/>. /// </para> /// </summary> public static Operation PutItems(MapPolicy policy, string binName, IDictionary map, params CTX[] ctx) { Packer packer = new Packer(); if (policy.flags != 0) { PackUtil.Init(packer, ctx); packer.PackArrayBegin(4); packer.PackNumber(MapOperation.PUT_ITEMS); packer.PackMap(map); packer.PackNumber(policy.attributes); packer.PackNumber(policy.flags); } else { if (policy.itemsCommand == REPLACE_ITEMS) { // Replace doesn't allow map attributes because it does not create on non-existing key. PackUtil.Init(packer, ctx); packer.PackArrayBegin(2); packer.PackNumber(policy.itemsCommand); packer.PackMap(map); } else { PackUtil.Init(packer, ctx); packer.PackArrayBegin(3); packer.PackNumber(policy.itemsCommand); packer.PackMap(map); packer.PackNumber(policy.attributes); } } byte[] bytes = packer.ToByteArray(); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create default list append items operation. /// Server appends each input list item to end of list bin. /// Server returns list size. /// </summary> public static Operation AppendItems(string binName, IList list, params CTX[] ctx) { // Compiler bug prevents calling of this method. // byte[] bytes = PackUtil.Pack(ListOperation.APPEND_ITEMS, list, ctx); // Duplicate method instead. Packer packer = new Packer(); PackUtil.Init(packer, ctx); packer.PackArrayBegin(2); packer.PackNumber(ListOperation.APPEND_ITEMS); packer.PackList(list); byte[] bytes = packer.ToByteArray(); return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes))); }
internal static byte[] PackRangeOperation(int command, int returnType, Value begin, Value end, CTX[] ctx) { Packer packer = new Packer(); PackUtil.Init(packer, ctx); packer.PackArrayBegin((end != null) ? 4 : 3); packer.PackNumber(command); packer.PackNumber(returnType); if (begin != null) { begin.Pack(packer); } else { packer.PackNil(); } if (end != null) { end.Pack(packer); } return(packer.ToByteArray()); }
/// <summary> /// Create list get by index operation. /// Server selects list item identified by index and returns selected data specified by returnType ///. /// </summary> public static Operation GetByIndex(string binName, int index, ListReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(ListOperation.GET_BY_INDEX, (int)returnType, index, ctx); return(new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create HLL describe operation. /// Server returns indexBitCount and minHashBitCount used to create HLL bin in a list of longs. /// The list size is 2. /// </summary> /// <param name="binName">name of bin</param> public static Operation Describe(string binName) { byte[] bytes = PackUtil.Pack(HLLOperation.DESCRIBE); return(new Operation(Operation.Type.HLL_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create HLL fold operation. /// Servers folds indexBitCount to the specified value. /// This can only be applied when minHashBitCount on the HLL bin is 0. /// Server does not return a value. /// </summary> /// <param name="binName">name of bin</param> /// <param name="indexBitCount">number of index bits. Must be between 4 and 16 inclusive.</param> public static Operation Fold(string binName, int indexBitCount) { byte[] bytes = PackUtil.Pack(HLLOperation.FOLD, indexBitCount); return(new Operation(Operation.Type.HLL_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create expression that adds values to a HLL set and returns HLL set. If HLL bin does not /// exist, use indexBitCount and minHashBitCount to create HLL set. /// </summary> /// <example> /// <code> /// // Add values to HLL bin "a" and check count > 7 /// Exp.GT( /// HLLExp.GetCount( /// HLLExp.Add(HLLPolicy.Default, Exp.Val(list), Exp.Val(10), Exp.Val(20), Exp.HLLBin("a"))), /// Exp.Val(7)) /// </code> /// </example> /// <param name="policy">write policy, use <see cref="Aerospike.Client.HLLPolicy.Default"/> for default</param> /// <param name="list">list bin or value expression of values to be added</param> /// <param name="indexBitCount">number of index bits expression. Must be between 4 and 16 inclusive.</param> /// <param name="minHashBitCount">number of min hash bits expression. Must be between 4 and 51 inclusive.</param> /// <param name="bin">HLL bin or value expression</param> public static Exp Add(HLLPolicy policy, Exp list, Exp indexBitCount, Exp minHashBitCount, Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.ADD, list, indexBitCount, minHashBitCount, policy.flags); return(AddWrite(bin, bytes)); }
/// <summary> /// Create expression that returns indexBitCount and minHashBitCount used to create HLL bin /// in a list of longs. list[0] is indexBitCount and list[1] is minHashBitCount. /// </summary> /// <example> /// <code> /// // Bin "a" indexBitCount < 10 /// Exp.LT( /// ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, Exp.Val(0), /// HLLExp.describe(Exp.HLLBin("a"))), /// Exp.Val(10)) /// </code> /// </example> public static Exp Describe(Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.DESCRIBE); return(AddRead(bin, bytes, Exp.Type.LIST)); }
/// <summary> /// Create expression that returns estimated number of elements that would be contained by /// the intersection of these HLL objects. /// </summary> /// <example> /// <code> /// // Intersect count of HLL bins "a" and "b" /// HLLExp.GetIntersectCount(Exp.HLLBin("a"), Exp.HLLBin("b")) /// /// // Intersect count of local HLL list with bin "b" /// HLLExp.GetIntersectCount(Exp.Val(list), Exp.HLLBin("b")) /// </code> /// </example> public static Exp GetIntersectCount(Exp list, Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.INTERSECT_COUNT, list); return(AddRead(bin, bytes, Exp.Type.INT)); }
/// <summary> /// Create expression that returns a HLL object that is the union of all specified HLL objects /// in the list with the HLL bin. /// </summary> /// <example> /// <code> /// // Union of HLL bins "a" and "b" /// HLLExp.GetUnion(Exp.HLLBin("a"), Exp.HLLBin("b")) /// /// // Union of local HLL list with bin "b" /// HLLExp.GetUnion(Exp.Val(list), Exp.HLLBin("b")) /// </code> /// </example> public static Exp GetUnion(Exp list, Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.UNION, list); return(AddRead(bin, bytes, Exp.Type.HLL)); }
/// <summary> /// Create map remove operation. /// Server removes map items identified by value and returns removed data specified by returnType. /// </summary> public static Operation RemoveByValue(string binName, Value value, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.REMOVE_BY_VALUE, (int)returnType, value, ctx); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create map remove operation. /// Server removes map items identified by keys and returns removed data specified by returnType. /// </summary> public static Operation RemoveByKeyList(string binName, IList keys, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.REMOVE_BY_KEY_LIST, (int)returnType, keys, ctx); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create map clear operation. /// Server removes all items in map. Server returns null. /// </summary> public static Operation Clear(string binName, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.CLEAR, ctx); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
public static Operation Decrement(MapPolicy policy, string binName, Value key, Value decr, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.DECREMENT, key, decr, policy.attributes, ctx); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create set map policy operation. /// Server sets map policy attributes. Server returns null. /// <para> /// The required map policy attributes can be changed after the map is created. /// </para> /// </summary> public static Operation SetMapPolicy(MapPolicy policy, string binName, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.SET_TYPE, policy.attributes, ctx); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create list get by rank operation. /// Server selects list item identified by rank and returns selected data specified by returnType. /// </summary> public static Operation GetByRank(string binName, int rank, ListReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(ListOperation.GET_BY_RANK, (int)returnType, rank, ctx); return(new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create expression that returns estimated number of elements in the HLL bin. /// </summary> /// <example> /// <code> /// // HLL bin "a" count > 7 /// Exp.GT(HLLExp.GetCount(Exp.HLLBin("a")), Exp.Val(7)) /// </code> /// </example> public static Exp GetCount(Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.COUNT); return(AddRead(bin, bytes, Exp.Type.INT)); }
/// <summary> /// Create map remove operation. /// Server removes "count" map items starting at specified index and returns removed data specified by returnType. /// </summary> public static Operation RemoveByIndexRange(string binName, int index, int count, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.REMOVE_BY_INDEX_RANGE, (int)returnType, index, count, ctx); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create expression that returns estimated number of elements that would be contained by /// the union of these HLL objects. /// </summary> /// <example> /// <code> /// // Union count of HLL bins "a" and "b" /// HLLExp.GetUnionCount(Exp.HLLBin("a"), Exp.HLLBin("b")) /// /// // Union count of local HLL list with bin "b" /// HLLExp.GetUnionCount(Exp.Val(list), Exp.HLLBin("b")) /// </code> /// </example> public static Exp GetUnionCount(Exp list, Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.UNION_COUNT, list); return(AddRead(bin, bytes, Exp.Type.INT)); }
/// <summary> /// Create map remove operation. /// Server removes map items starting at specified rank to the last ranked item and returns removed /// data specified by returnType. /// </summary> public static Operation RemoveByRankRange(string binName, int rank, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.REMOVE_BY_RANK_RANGE, (int)returnType, rank, ctx); return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create expression that returns estimated similarity of these HLL objects as a /// 64 bit float. /// </summary> /// <example> /// <code> /// // Similarity of HLL bins "a" and "b" >= 0.75 /// Exp.GE(HLLExp.GetSimilarity(Exp.HLLBin("a"), Exp.HLLBin("b")), Exp.Val(0.75)) /// </code> /// </example> public static Exp GetSimilarity(Exp list, Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.SIMILARITY, list); return(AddRead(bin, bytes, Exp.Type.FLOAT)); }
/// <summary> /// Create map size operation. /// Server returns size of map. /// </summary> public static Operation Size(string binName, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.SIZE, ctx); return(new Operation(Operation.Type.MAP_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create expression that returns one if HLL bin may contain all items in the list. /// </summary> /// <example> /// <code> /// // Bin "a" may contain value "x" /// List list = new List(); /// list.Add(Value.Get("x")); /// Exp.EQ(HLLExp.MayContain(Exp.Val(list), Exp.HLLBin("a")), Exp.Val(1)); /// </code> /// </example> public static Exp MayContain(Exp list, Exp bin) { byte[] bytes = PackUtil.Pack(HLLOperation.MAY_CONTAIN, list); return(AddRead(bin, bytes, Exp.Type.INT)); }
/// <summary> /// Create map get by key operation. /// Server selects map item identified by key and returns selected data specified by returnType. /// </summary> public static Operation GetByKey(string binName, Value key, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_KEY, (int)returnType, key, ctx); return(new Operation(Operation.Type.MAP_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create HLL refresh operation. /// Server updates the cached count (if stale) and returns the count. /// </summary> /// <param name="binName">name of bin</param> public static Operation RefreshCount(string binName) { byte[] bytes = PackUtil.Pack(HLLOperation.SET_COUNT); return(new Operation(Operation.Type.HLL_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create map get by value list operation. /// Server selects map items identified by values and returns selected data specified by returnType. /// </summary> public static Operation GetByValueList(string binName, IList values, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_VALUE_LIST, (int)returnType, values, ctx); return(new Operation(Operation.Type.MAP_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create HLL getCount operation. /// Server returns estimated number of elements in the HLL bin. /// </summary> /// <param name="binName">name of bin</param> public static Operation GetCount(string binName) { byte[] bytes = PackUtil.Pack(HLLOperation.COUNT); return(new Operation(Operation.Type.HLL_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create map get by index range operation. /// Server selects map items starting at specified index to the end of map and returns selected /// data specified by returnType. /// </summary> public static Operation GetByIndexRange(string binName, int index, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_INDEX_RANGE, (int)returnType, index, ctx); return(new Operation(Operation.Type.MAP_READ, binName, Value.Get(bytes))); }
/// <summary> /// Create HLL init operation with minhash bits. /// Server creates a new HLL or resets an existing HLL. /// Server does not return a value. /// </summary> /// <param name="policy">write policy, use <see cref="Aerospike.Client.HLLPolicy.Default"/> for default</param> /// <param name="binName">name of bin</param> /// <param name="indexBitCount">number of index bits. Must be between 4 and 16 inclusive.</param> /// <param name="minHashBitCount">number of min hash bits. Must be between 4 and 51 inclusive.</param> public static Operation Init(HLLPolicy policy, string binName, int indexBitCount, int minHashBitCount) { byte[] bytes = PackUtil.Pack(HLLOperation.INIT, indexBitCount, minHashBitCount, policy.flags); return(new Operation(Operation.Type.HLL_MODIFY, binName, Value.Get(bytes))); }
/// <summary> /// Create map get by rank range operation. /// Server selects "count" map items starting at specified rank and returns selected data specified by returnType. /// </summary> public static Operation GetByRankRange(string binName, int rank, int count, MapReturnType returnType, params CTX[] ctx) { byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_RANK_RANGE, (int)returnType, rank, count, ctx); return(new Operation(Operation.Type.MAP_READ, binName, Value.Get(bytes))); }