public void ModifyWithContext() { IList <Value> listSubA = new List <Value>(); listSubA.Add(Value.Get("e")); listSubA.Add(Value.Get("d")); listSubA.Add(Value.Get("c")); listSubA.Add(Value.Get("b")); listSubA.Add(Value.Get("a")); IList <Value> listA = new List <Value>(); listA.Add(Value.Get("a")); listA.Add(Value.Get("b")); listA.Add(Value.Get("c")); listA.Add(Value.Get("d")); listA.Add(Value.Get(listSubA)); IList <Value> listB = new List <Value>(); listB.Add(Value.Get("x")); listB.Add(Value.Get("y")); listB.Add(Value.Get("z")); client.Operate(null, keyA, ListOperation.AppendItems(ListPolicy.Default, binA, (IList)listA), ListOperation.AppendItems(ListPolicy.Default, binB, (IList)listB), Operation.Put(new Bin(binC, "M")) ); CTX ctx = CTX.ListIndex(4); Record record; IList result; policy.filterExp = Exp.Build( Exp.EQ( ListExp.Size( // Temporarily Append binB/binC to binA in expression. ListExp.AppendItems(ListPolicy.Default, Exp.ListBin(binB), ListExp.Append(ListPolicy.Default, Exp.StringBin(binC), Exp.ListBin(binA), ctx), ctx), ctx), Exp.Val(9))); record = client.Get(policy, keyA, binA); AssertRecordFound(keyA, record); result = record.GetList(binA); Assert.AreEqual(5, result.Count); policy.filterExp = Exp.Build( Exp.EQ( ListExp.Size( // Temporarily Append local listB and local "M" string to binA in expression. ListExp.AppendItems(ListPolicy.Default, Exp.Val((IList)listB), ListExp.Append(ListPolicy.Default, Exp.Val("M"), Exp.ListBin(binA), ctx), ctx), ctx), Exp.Val(9))); record = client.Get(policy, keyA, binA); AssertRecordFound(keyA, record); result = record.GetList(binA); Assert.AreEqual(5, result.Count); }
public void OperateNestedList() { Key key = new Key(args.ns, args.set, "oplkey18"); client.Delete(null, key); IList <Value> l1 = new List <Value>(); l1.Add(Value.Get(7)); l1.Add(Value.Get(9)); l1.Add(Value.Get(5)); IList <Value> l2 = new List <Value>(); l2.Add(Value.Get(1)); l2.Add(Value.Get(2)); l2.Add(Value.Get(3)); IList <Value> l3 = new List <Value>(); l3.Add(Value.Get(6)); l3.Add(Value.Get(5)); l3.Add(Value.Get(4)); l3.Add(Value.Get(1)); List <Value> inputList = new List <Value>(); inputList.Add(Value.Get(l1)); inputList.Add(Value.Get(l2)); inputList.Add(Value.Get(l3)); // Create list. client.Put(null, key, new Bin(binName, inputList)); // Append value to last list and retrieve all lists. Record record = client.Operate(null, key, ListOperation.Append(binName, Value.Get(11), CTX.ListIndex(-1)), Operation.Get(binName) ); AssertRecordFound(key, record); IList results = record.GetList(binName); int i = 0; long count = (long)results[i++]; Assert.AreEqual(5, count); IList list = (IList)results[i++]; Assert.AreEqual(3, list.Count); // Test last nested list. list = (IList)list[2]; Assert.AreEqual(5, list.Count); Assert.AreEqual(6, (long)(long?)list[0]); Assert.AreEqual(5, (long)(long?)list[1]); Assert.AreEqual(4, (long)(long?)list[2]); Assert.AreEqual(1, (long)(long?)list[3]); Assert.AreEqual(11, (long)(long?)list[4]); }
/// <summary> /// Operate on a list of lists. /// </summary> private void RunNestedExample(AerospikeClient client, Arguments args) { Key key = new Key(args.ns, args.set, "listkey2"); string binName = args.GetBinName("listbin"); // Delete record if it already exists. client.Delete(args.writePolicy, key); IList <Value> l1 = new List <Value>(); l1.Add(Value.Get(7)); l1.Add(Value.Get(9)); l1.Add(Value.Get(5)); IList <Value> l2 = new List <Value>(); l2.Add(Value.Get(1)); l2.Add(Value.Get(2)); l2.Add(Value.Get(3)); IList <Value> l3 = new List <Value>(); l3.Add(Value.Get(6)); l3.Add(Value.Get(5)); l3.Add(Value.Get(4)); l3.Add(Value.Get(1)); IList <Value> inputList = new List <Value>(); inputList.Add(Value.Get(l1)); inputList.Add(Value.Get(l2)); inputList.Add(Value.Get(l3)); // Create list. client.Put(args.writePolicy, key, new Bin(binName, inputList)); // Append value to last list and retrieve all lists. Record record = client.Operate(args.writePolicy, key, ListOperation.Append(binName, Value.Get(11), CTX.ListIndex(-1)), Operation.Get(binName) ); record = client.Get(args.policy, key); console.Info("Record: " + record); }