本文整理汇总了C#中Aerospike.Client.AerospikeClient.QueryAggregate方法的典型用法代码示例。如果您正苦于以下问题:C# AerospikeClient.QueryAggregate方法的具体用法?C# AerospikeClient.QueryAggregate怎么用?C# AerospikeClient.QueryAggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aerospike.Client.AerospikeClient
的用法示例。
在下文中一共展示了AerospikeClient.QueryAggregate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunQuery
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();
}
}
示例2: RunQuery
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();
}
}
示例3: RunQuery
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();
}
}
示例4: RunQuery
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();
}
}