this makes sense assuming you have the operations registered
1. DummyOperation
2. RowCountOperation
3. DummyTwo
aggregate operation works the same way "group by" does in a sql
statement. because you do not define any columns to group by there
will only be a single aggregate. the aggregate will contain a single
column named "count" with a value of 500. The aggregated rows are the
output of an abstract aggregate operation. for example
if you were to register DummyTwo before RowCountOperation you would
get 500, 500, 1.
if you want a count of the records there are plenty of ways to do
that. depending on how the count will be used depends on the best way
to implement the count.
here is an example of how Aggregate works
public class Source : AbstractOperation
{
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
foreach(var c in "hello world")
{
var row = new Row();
row["letter"] = c;
yield return row;
}
}
}
public class CountLetters : AbstractAggregationOperation
{
Dictionary<Row, int> counts = new Dictionary<Row, int>();
protected override void Accumulate(Row row, Row aggregate)
{
var aggregate["letter"] = row["letter"];
if(counts.Contains(aggregate) == false)
{
counts.Add(aggregate, 0)
}
counts[aggregate]++;
}
protected override void FinishAggregation(Row aggregate)
{
var count = counts[aggregate];
aggregate["count"] = count;
}
protected override string[] GetColumnsToGroupBy()
{
return new [] {"letter"};
}
}
public class Destination : AbstractOperation
{
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
foreach(var row in rows)
{
Debug("Letter '{0}' occurred {1} time(s)",
row["letter"],
row["count"]);
yield return rows;
}
}
}
which will result in
Letter 'h' occurred 1 time(s)
Letter 'e' occurred 1 time(s)
Letter 'l' occurred 3 time(s)
Letter 'o' occurred 2 time(s)
Letter 'w' occurred 1 time(s)
Letter 'r' occurred 1 time(s)
Letter 'd' occurred 1 time(s)
On Apr 15, 11:26 am, Larry R <[email protected]> wrote:
> Not sure that would solve any of my issues. Let me take a simpler
> example.
> In the following, how would I get the rows to be counted, but passed
> on to DummyTwo?
>
> Register(new DummyOperation());
> Register(new RowCountOperation());
> Register(new DummyTwo());
>
> protected override void OnFinishedProcessing(IOperation op)
> {
> Console.WriteLine(op.Statistics.OutputtedRows); <<<<<<<<
> Result is 500,1,1
> }
>
> public class DummyOperation : AbstractOperation
> {
> public override IEnumerable<Row> Execute(IEnumerable<Row>
> rows)
> {
> List<Row> list = new List<Row>();
> for (int i = 0; i < 500; i++)
> {
> Row r = new Row();
> r["Id"] = i;
> list.Add(r);
>
> }
>
> foreach (Row row in list)
> {
> yield return row; ;
> }
> }
> }
> public class DummyTwo:AbstractOperation
> {
> public override IEnumerable<Row> Execute(IEnumerable<Row>
> rows)
> {
> foreach (Row row in rows)
> {
> yield return row;
> }
> }
> }
> public class RowCountOperation : AbstractAggregationOperation
> {
> protected override void Accumulate(Row row, Row aggregate)
> {
> if (aggregate["count"] == null)
> aggregate["count"] = 0;
>
> int count = (int)aggregate["count"];
> aggregate["count"] = count + 1;
> }
>
> }
--
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhino-tools-dev?hl=en.