-
Notifications
You must be signed in to change notification settings - Fork 2
UsageExamples
gerritjvv edited this page Jan 2, 2012
·
2 revisions
SELECT a, b, COUNT(traffic), SUM(hits) from tbl GROUP BY a,b
Can be transformed into the API calls:
- Create an Aggregate store. A, B can be passed through without transformation. This assumes that the data will be read with columns in order of : a,b,traffic,hits.
HashMapAggregateStore store = new HashMapAggregateStore( new PassThroughTransform(0), new PassThroughTransform(1), new COUNT(2), new SUM(3));
- Create a GroupBy object The key Parser takes in cells index 0 and index 1. Which corresponds to A, B.
GroupBy groupBy = new GroupBy(new GroupBy.KeyParser() {
@Override
public String makeKey(Cell[] cells) {
return new StringBuilder().append(cells[0]).append(cells[1]).toString();
}
}, store);- Push information to the GroupBy Object
groupBy.fill(getCells(4));
- To see the data do
groupBy.write(new DataSink() {
@Override
public boolean fill(Cell[] data) {
System.out.println(Arrays.toString(data));
return true;
}
});