private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName)
        {
            console.Info("Query for:ns={0} set={1} index={2} bin={3}",
                args.ns, args.set, indexName, binName);

            Statement stmt = new Statement();
            stmt.SetNamespace(args.ns);
            stmt.SetSetName(args.set);
            stmt.SetFilters(Filter.Equal(binName, 1));

            ResultSet rs = client.QueryAggregate(null, stmt, "average_example", "average");

            try
            {
                if (rs.Next())
                {
                    object obj = rs.Object;

                    if (obj is Dictionary<object,object>)
                    {
                        Dictionary<object, object> map = (Dictionary<object, object>)obj;
                        object objsum = map["sum"];
                        object objcount = map["count"];
                        double sum = (double)(long)objsum;
                        double count = (double)(long)objcount;
                        double avg = sum / count;
                        console.Info("Sum=" + sum + " Count=" + count + " Average=" + avg);

                        double expected = 5.5;
                        if (avg != expected)
                        {
                            console.Error("Data mismatch: Expected {0}. Received {1}.", expected, avg);
                        }
                    }
                    else
                    {
                        console.Error("Unexpected object returned: " + obj);
                    }
                }
                else
                {
                    console.Error("Query failed. No records returned.");
                }
            }
            finally
            {
                rs.Close();
            }
        }
        private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName)
        {
            int begin = 4;
            int end = 7;

            console.Info("Query for:ns={0} set={1} index={2} bin={3} >= {4} <= {5}",
                args.ns, args.set, indexName, binName, begin, end);

            Statement stmt = new Statement();
            stmt.SetNamespace(args.ns);
            stmt.SetSetName(args.set);
            stmt.SetBinNames(binName);
            stmt.SetFilters(Filter.Range(binName, begin, end));

            ResultSet rs = client.QueryAggregate(null, stmt, "sum_example", "sum_single_bin", Value.Get(binName));

            try
            {
                int expected = 22; // 4 + 5 + 6 + 7
                int count = 0;

                while (rs.Next())
                {
                    object obj = rs.Object;

                    if (obj is long)
                    {
                        long sum = (long)rs.Object;

                        if (expected == (int)sum)
                        {
                            console.Info("Sum matched: value=" + expected);
                        }
                        else
                        {
                            console.Error("Sum mismatch: Expected {0}. Received {1}.", expected, sum);
                        }
                    }
                    else
                    {
                        console.Error("Unexpected return value: " + obj);
                        continue;
                    }
                    count++;
                }

                if (count == 0)
                {
                    console.Error("Query failed. No records returned.");
                }
            }
            finally
            {
                rs.Close();
            }
        }
        private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName)
        {
            string nameFilter = "Bill";
            string passFilter = "hknfpkj";

            console.Info("Query for: ns=%s set=%s index=%s name=%s pass=%s", args.ns, args.set, indexName, nameFilter, passFilter);

            Statement stmt = new Statement();
            stmt.SetNamespace(args.ns);
            stmt.SetSetName(args.set);
            stmt.SetFilters(Filter.Equal(binName, nameFilter));
            stmt.SetAggregateFunction("filter_example", "profile_filter", Value.Get(passFilter));

            // passFilter will be applied in filter_example.lua.
            ResultSet rs = client.QueryAggregate(null, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    Dictionary<object, object> map = (Dictionary<object, object>)rs.Object;
                    Validate(map, "name", nameFilter);
                    Validate(map, "password", passFilter);
                    count++;
                }

                if (count == 0)
                {
                    console.Error("Query failed. No records returned.");
                }
            }
            finally
            {
                rs.Close();
            }
        }
        private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName1, string binName2)
        {
            StringBuilder rgnsb = new StringBuilder();

            rgnsb.Append("{ ");
            rgnsb.Append("    \"type\": \"Polygon\", ");
            rgnsb.Append("    \"coordinates\": [ ");
            rgnsb.Append("        [[-122.500000, 37.000000],[-121.000000, 37.000000], ");
            rgnsb.Append("         [-121.000000, 38.080000],[-122.500000, 38.080000], ");
            rgnsb.Append("         [-122.500000, 37.000000]] ");
            rgnsb.Append("    ] ");
            rgnsb.Append(" } ");

            console.Info("QueryRegion: " + rgnsb);

            string amenStr = "school";

            Statement stmt = new Statement();
            stmt.SetNamespace(args.ns);
            stmt.SetSetName(args.set);
            stmt.SetFilters(Filter.GeoWithinRegion(binName1, rgnsb.ToString()));
            stmt.SetAggregateFunction("geo_filter_example", "match_amenity", Value.Get(amenStr));

            ResultSet rs = client.QueryAggregate(null, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    object result = rs.Object;
                    console.Info("Record found: " + result);
                    count++;
                }

                if (count != 2)
                {
                    console.Error("Wrong number of schools found. %d != 2", count);
                }
            }
            finally
            {
                rs.Close();
            }
        }