public void QueryBinType()
        {
            int begin = 1;
            int end   = 10;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));

            QueryPolicy policy = new QueryPolicy();

            policy.filterExp = Exp.Build(Exp.EQ(Exp.BinType("listbin"), Exp.Val(ParticleType.LIST)));

            RecordSet rs = client.Query(policy, stmt);

            try {
                int count = 0;

                while (rs.Next())
                {
                    count++;
                }
                Assert.AreEqual(9, count);
            }
            finally {
                rs.Close();
            }
        }
        public void QueryDigestModulo()
        {
            int begin = 1;
            int end   = 10;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));

            // Record key digest % 3 == 1
            QueryPolicy policy = new QueryPolicy();

            policy.filterExp = Exp.Build(Exp.EQ(Exp.DigestModulo(3), Exp.Val(1)));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    //Console.WriteLine(rs.Record.ToString());
                    count++;
                }
                Assert.AreEqual(4, count);
            }
            finally
            {
                rs.Close();
            }
        }
        private void Union(Key key)
        {
            List <Value.HLLValue> hlls = new List <Value.HLLValue>();

            hlls.Add(hll1);
            hlls.Add(hll2);
            hlls.Add(hll3);

            policy.filterExp = Exp.Build(
                Exp.NE(
                    HLLExp.GetCount(HLLExp.GetUnion(Exp.Val(hlls), Exp.HLLBin(bin1))),
                    HLLExp.GetUnionCount(Exp.Val(hlls), Exp.HLLBin(bin1))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    HLLExp.GetCount(HLLExp.GetUnion(Exp.Val(hlls), Exp.HLLBin(bin1))),
                    HLLExp.GetUnionCount(Exp.Val(hlls), Exp.HLLBin(bin1))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        public void QuerySetName()
        {
            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);

            QueryPolicy policy = new QueryPolicy();

            policy.filterExp = Exp.Build(Exp.EQ(Exp.SetName(), Exp.Val(set2)));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    count++;
                }
                Assert.AreEqual(3, count);
            }
            finally
            {
                rs.Close();
            }
        }
        private void Get(Key key)
        {
            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin(binA)),
                    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin(binA))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin(binA)),
                    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin(binA))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin(binA)),
                    Exp.Val(new byte[] { 0x03 })));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void Count(Key key)
        {
            policy.filterExp = Exp.Build(Exp.EQ(HLLExp.GetCount(Exp.HLLBin(bin1)), Exp.Val(0)));
            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(Exp.GT(HLLExp.GetCount(Exp.HLLBin(bin1)), Exp.Val(0)));
            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void MayContain(Key key)
        {
            List <Value> values = new List <Value>();

            values.Add(Value.Get("new_val"));

            policy.filterExp = Exp.Build(Exp.EQ(HLLExp.MayContain(Exp.Val(values), Exp.HLLBin(bin2)), Exp.Val(1)));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(Exp.NE(HLLExp.MayContain(Exp.Val(values), Exp.HLLBin(bin2)), Exp.Val(1)));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
Beispiel #8
0
        public void Initialize()
        {
            predAEq1BPolicy = new BatchPolicy();
            predAEq1RPolicy = new Policy();
            predAEq1WPolicy = new WritePolicy();

            Expression filter = Exp.Build(Exp.EQ(Exp.IntBin(binAName), Exp.Val(1)));

            predAEq1BPolicy.filterExp = filter;
            predAEq1RPolicy.filterExp = filter;
            predAEq1WPolicy.filterExp = filter;

            client.Delete(null, keyA);
            client.Delete(null, keyB);

            client.Put(null, keyA, binA1);
            client.Put(null, keyB, binA2);
        }
        public void QueryAndOr()
        {
            int begin = 10;
            int end   = 45;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));

            // ((bin2 > 40 && bin2 < 44) || bin2 == 22 || bin2 == 9) && (binName == bin2)
            QueryPolicy policy = new QueryPolicy();

            policy.filterExp = Exp.Build(
                Exp.And(
                    Exp.Or(
                        Exp.And(
                            Exp.GT(Exp.IntBin("bin2"), Exp.Val(40)),
                            Exp.LT(Exp.IntBin("bin2"), Exp.Val(44))),
                        Exp.EQ(Exp.IntBin("bin2"), Exp.Val(22)),
                        Exp.EQ(Exp.IntBin("bin2"), Exp.Val(9))),
                    Exp.EQ(Exp.IntBin(binName), Exp.IntBin("bin2"))));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    //Console.WriteLine(rs.Record.GetValue(binName));
                    count++;
                }
                // 22, 41, 42, 43
                Assert.AreEqual(4, count);
            }
            finally
            {
                rs.Close();
            }
        }
        private void GetInt(Key key)
        {
            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.GetInt(Exp.Val(32), Exp.Val(8), true, Exp.BlobBin(binA)),
                    Exp.Val(0x05)));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.GetInt(Exp.Val(32), Exp.Val(8), true, Exp.BlobBin(binA)),
                    Exp.Val(0x05)));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        public void QueryMap6()
        {
            int begin = 1;
            int end   = 10;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));

            // Map bin contains keys "A" and "C".
            QueryPolicy policy = new QueryPolicy();

            List <string> list = new List <string>();

            list.Add("A");
            list.Add("C");

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    ListExp.Size(                     // return type VALUE returns a list
                        MapExp.GetByKeyList(MapReturnType.VALUE, Exp.Val(list), Exp.MapBin("mapbin"))),
                    Exp.Val(2)));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    //Console.WriteLine(rs.Record.ToString());
                    count++;
                }
                Assert.AreEqual(1, count);
            }
            finally
            {
                rs.Close();
            }
        }
Beispiel #12
0
        private void RunQuery1(AerospikeClient client, Arguments args, string binName)
        {
            int begin = 10;
            int end   = 40;

            console.Info("Query Predicate: (bin2 > 126 && bin2 <= 140) || (bin2 = 360)");

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(args.set);

            // Filter applied on query itself.  Filter can only reference an indexed bin.
            stmt.SetFilter(Filter.Range(binName, begin, end));

            // Predicates are applied on query results on server side.
            // Predicates can reference any bin.
            QueryPolicy policy = new QueryPolicy(client.queryPolicyDefault);

            policy.filterExp = Exp.Build(
                Exp.Or(
                    Exp.And(
                        Exp.GT(Exp.IntBin("bin2"), Exp.Val(126)),
                        Exp.LE(Exp.IntBin("bin2"), Exp.Val(140))),
                    Exp.EQ(Exp.IntBin("bin2"), Exp.Val(360))));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                while (rs.Next())
                {
                    Record record = rs.Record;
                    console.Info("Record: " + record.ToString());
                }
            }
            finally
            {
                rs.Close();
            }
        }
        private void SetInt(Key key)
        {
            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.Get(Exp.Val(24), Exp.Val(8),
                               BitExp.SetInt(BitPolicy.Default, Exp.Val(24), Exp.Val(8), Exp.Val(0x42), Exp.BlobBin(binA))),
                    BitExp.Get(Exp.Val(8), Exp.Val(8), Exp.BlobBin(binA))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.Get(Exp.Val(24), Exp.Val(8),
                               BitExp.SetInt(BitPolicy.Default, Exp.Val(24), Exp.Val(8), Exp.Val(0x42), Exp.BlobBin(binA))),
                    BitExp.Get(Exp.Val(8), Exp.Val(8), Exp.BlobBin(binA))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void Subtract(Key key)
        {
            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.Get(Exp.Val(24), Exp.Val(8),
                               BitExp.Subtract(BitPolicy.Default, Exp.Val(24), Exp.Val(8), Exp.Val(1), false, BitOverflowAction.FAIL, Exp.BlobBin(binA))),
                    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin(binA))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.Get(Exp.Val(24), Exp.Val(8),
                               BitExp.Subtract(BitPolicy.Default, Exp.Val(24), Exp.Val(8), Exp.Val(1), false, BitOverflowAction.FAIL, Exp.BlobBin(binA))),
                    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin(binA))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void Resize(Key key)
        {
            Exp size = Exp.Val(6);

            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.Resize(BitPolicy.Default, size, 0, Exp.BlobBin(binA)),
                    BitExp.Resize(BitPolicy.Default, size, 0, Exp.BlobBin(binA))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.Resize(BitPolicy.Default, size, 0, Exp.BlobBin(binA)),
                    BitExp.Resize(BitPolicy.Default, size, 0, Exp.BlobBin(binA))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void Describe(Key key)
        {
            Exp index = Exp.Val(0);

            policy.filterExp = Exp.Build(
                Exp.NE(
                    ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin1))),
                    ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin2)))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin1))),
                    ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, index, HLLExp.Describe(Exp.HLLBin(bin2)))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void And(Key key)
        {
            byte[] bytes = new byte[] { (byte)0x01 };

            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.Get(Exp.Val(0), Exp.Val(8),
                               BitExp.And(BitPolicy.Default, Exp.Val(16), Exp.Val(8), Exp.Val(bytes), Exp.BlobBin(binA))),
                    BitExp.Get(Exp.Val(0), Exp.Val(8), Exp.BlobBin(binA))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.Get(Exp.Val(0), Exp.Val(8),
                               BitExp.And(BitPolicy.Default, Exp.Val(16), Exp.Val(8), Exp.Val(bytes), Exp.BlobBin(binA))),
                    BitExp.Get(Exp.Val(0), Exp.Val(8), Exp.BlobBin(binA))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void Remove(Key key)
        {
            int expected = 0x42;

            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.GetInt(Exp.Val(0), Exp.Val(8), false,
                                  BitExp.Remove(BitPolicy.Default, Exp.Val(0), Exp.Val(1), Exp.BlobBin(binA))),
                    Exp.Val(expected)));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.GetInt(Exp.Val(0), Exp.Val(8), false,
                                  BitExp.Remove(BitPolicy.Default, Exp.Val(0), Exp.Val(1), Exp.BlobBin(binA))),
                    Exp.Val(expected)));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        private void Add(Key key)
        {
            List <Value> values = new List <Value>();

            values.Add(Value.Get("new_val"));

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    HLLExp.GetCount(Exp.HLLBin(bin1)),
                    HLLExp.GetCount(HLLExp.Add(HLLPolicy.Default, Exp.Val(values), Exp.HLLBin(bin2)))));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.LT(
                    HLLExp.GetCount(Exp.HLLBin(bin1)),
                    HLLExp.GetCount(HLLExp.Add(HLLPolicy.Default, Exp.Val(values), Exp.HLLBin(bin2)))));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        public void QueryMap4()
        {
            int begin = 1;
            int end   = 10;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));

            // Map bin does not contains value "AAA"
            QueryPolicy policy = new QueryPolicy();

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    MapExp.GetByValue(MapReturnType.COUNT, Exp.Val("AAA"), Exp.MapBin("mapbin")),
                    Exp.Val(0)));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    //Console.WriteLine(rs.Record.ToString());
                    count++;
                }
                Assert.AreEqual(7, count);
            }
            finally
            {
                rs.Close();
            }
        }
        public void QueryList3()
        {
            int begin = 1;
            int end   = 10;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));

            // list[4] == 20
            QueryPolicy policy = new QueryPolicy();

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    ListExp.GetByIndex(ListReturnType.VALUE, Exp.Type.INT, Exp.Val(4), Exp.ListBin("listbin")),
                    Exp.Val(20)));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    //Console.WriteLine(rs.Record.ToString());
                    count++;
                }
                Assert.AreEqual(1, count);
            }
            finally
            {
                rs.Close();
            }
        }
        private void Insert(Key key)
        {
            byte[] bytes    = new byte[] { (byte)0xff };
            int    expected = 0xff;

            policy.filterExp = Exp.Build(
                Exp.NE(
                    BitExp.GetInt(Exp.Val(8), Exp.Val(8), false,
                                  BitExp.Insert(BitPolicy.Default, Exp.Val(1), Exp.Val(bytes), Exp.BlobBin(binA))),
                    Exp.Val(expected)));

            Record r = client.Get(policy, key);

            Assert.AreEqual(null, r);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    BitExp.GetInt(Exp.Val(8), Exp.Val(8), false,
                                  BitExp.Insert(BitPolicy.Default, Exp.Val(1), Exp.Val(bytes), Exp.BlobBin(binA))),
                    Exp.Val(expected)));

            r = client.Get(policy, key);
            AssertRecordFound(key, r);
        }
        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);
        }