Beispiel #1
0
        public void Initialize()
        {
            predAEq1BPolicy = new BatchPolicy();
            predAEq1RPolicy = new Policy();
            predAEq1WPolicy = new WritePolicy();

            predAEq1BPolicy.SetPredExp(
                PredExp.IntegerBin(binAName),
                PredExp.IntegerValue(1),
                PredExp.IntegerEqual());

            predAEq1RPolicy.SetPredExp(
                PredExp.IntegerBin(binAName),
                PredExp.IntegerValue(1),
                PredExp.IntegerEqual());

            predAEq1WPolicy.SetPredExp(
                PredExp.IntegerBin(binAName),
                PredExp.IntegerValue(1),
                PredExp.IntegerEqual());

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

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

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));
            stmt.SetPredExp(
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(40),
                PredExp.IntegerGreater(),
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(44),
                PredExp.IntegerLess(),
                PredExp.And(2),
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(22),
                PredExp.IntegerEqual(),
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(9),
                PredExp.IntegerEqual(),
                PredExp.Or(3),
                PredExp.IntegerBin(binName),
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerEqual(),
                PredExp.And(2)
                );

            RecordSet rs = client.Query(null, 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 RunQuery1(AerospikeClient client, Arguments args, string binName)
        {
            int begin = 10;
            int end   = 40;

            console.Info("Query Predicate: (bin2 > 126 && bin2 <= 140) or (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.
            stmt.SetPredExp(
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(126),
                PredExp.IntegerGreater(),
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(140),
                PredExp.IntegerLessEq(),
                PredExp.And(2),
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(360),
                PredExp.IntegerEqual(),
                PredExp.Or(2)
                );

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

            try
            {
                while (rs.Next())
                {
                    Record record = rs.Record;
                    console.Info("Record: " + record.ToString());
                }
            }
            finally
            {
                rs.Close();
            }
        }
        public void QueryPredicate2()
        {
            int begin = 10;
            int end   = 45;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));
            stmt.SetPredExp(
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(15),
                PredExp.IntegerGreaterEq(),
                PredExp.IntegerBin("bin2"),
                PredExp.IntegerValue(42),
                PredExp.IntegerLessEq(),
                PredExp.And(2),
                PredExp.Not()
                );

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

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    //Console.WriteLine(rs.Record.GetValue(binName));
                    count++;
                }
                // 10, 11, 12, 13, 43, 44, 45
                Assert.AreEqual(8, count);
            }
            finally
            {
                rs.Close();
            }
        }