Skip to content
gerritjvv edited this page Jan 2, 2012 · 2 revisions

Usage Examples

Group By and Aggregate

SELECT a, b, COUNT(traffic), SUM(hits) from tbl GROUP BY a,b

Can be transformed into the API calls:

  1. 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));
  1. 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);
  1. Push information to the GroupBy Object
groupBy.fill(getCells(4));
  1. To see the data do
   	groupBy.write(new DataSink() {
			
			@Override
			public boolean fill(Cell[] data) {
				
				System.out.println(Arrays.toString(data));
				return true;
			}
		});

Clone this wiki locally