• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Method Aggregate

Aggregate(IValueExtractor, IAggregator, IKeyFilter, QueryCommand, Int32)

Built upon MapReduce framework, processes distributed data records to return compiled and statistical results for analytical purposes.

Declaration
object Aggregate(IValueExtractor extractor, IAggregator aggregator, IKeyFilter keyFilter = null, QueryCommand queryCommand = null, int timeout = 2147483647)
Parameters
Type Name Description
IValueExtractor extractor

Implementation of IValueExtractor to extract the meaningful attributes from given objects.

IAggregator aggregator

IAggregator For actual grouping and analytical operations on given data using Map Reduce Combiner and Reducer.

IKeyFilter keyFilter

Instance of IKeyFilter implementation.

QueryCommand queryCommand

Instance of QueryCommand containing query and values.

System.Int32 timeout

Time in millisecond in which if result is not returned, thread will be terminated and a timeout exception will be thrown.

Returns
Type Description
System.Object

Returns a single result depending upon given extractor.

Remarks

Aggregator can perform following operations Average, Sum, Min, Max, Count, Distinct. If result after aggregation execution is null than default value of built in Aggregator for that specific type is returned. User can also implement custom aggregator, as well as aggregator for custom data types and also for custom functions like Mean, Median, Mode.

Examples
 ICache cache = CacheManager.GetCache("demoCache");

string key1 = "2202";

Product product1 = new Product()
{
    Id = 4,
    Category = "Clothes",
    UnitPrice = 4,
    UnitsAvailable = 2
};

string key2 = "2203";
Product product2 = new Product()
{
    Id = 4,
    Category = "Shoes",
    UnitPrice = 5,
    UnitsAvailable = 9
};

cache.Add(key1, product1);
cache.Add(key2, product2);

string query = "SELECT Alachisoft.NCache.Sample.Data.Product WHERE this.Category=?";
QueryCommand queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("Category", "Clothes");

object result = cache.ExecutionService.Aggregate(new BasicTypeExtractor(), BuiltInAggregator.Count(), null, queryCommand, 50000);
Back to top Copyright © 2017 Alachisoft