You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ja...@apache.org on 2018/02/07 07:05:45 UTC

[1/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

Repository: eagle
Updated Branches:
  refs/heads/master 06a828f08 -> c970bb426


http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestPostFlatAggregateSort.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestPostFlatAggregateSort.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestPostFlatAggregateSort.java
index 91b3738..cdfc5bc 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestPostFlatAggregateSort.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestPostFlatAggregateSort.java
@@ -33,111 +33,112 @@ import org.junit.Test;
 import org.apache.eagle.query.aggregate.timeseries.SortOption;
 
 public class TestPostFlatAggregateSort {
-	private static final Logger logger = Logger.getLogger(TestPostFlatAggregateSort.class);
-	@Test
-	public void testSort(){
-		final String aggField1Value1 = "field1value1";
-		final String aggField1Value2 = "field1value2";
-		final String aggField2Value1 = "field2value1";
-		final String aggField2Value2 = "field2value2";
-		final Double d1 = new Double(1);
-		final Double d2 = new Double(2);
-		final Double d3 = new Double(3);
-		final Double d4 = new Double(4);
-		@SuppressWarnings("serial")
-		Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>(){{
-			put(Arrays.asList(aggField1Value1, aggField2Value1), Arrays.asList(d2, d3));
-			put(Arrays.asList(aggField1Value2, aggField2Value2), Arrays.asList(d1, d4));
-		}};
-		
-		// sort by function1
-		SortOption so = new SortOption();
-		so.setIndex(0);
-		so.setAscendant(true);
-		List<SortOption> sortOptions = Arrays.asList(so);
-		List<Map.Entry<List<String>, List<Double>>> set = 
-				PostFlatAggregateSort.sort(result, sortOptions, 0);
-		JsonFactory factory = new JsonFactory();
-		ObjectMapper mapper = new ObjectMapper(factory);
-		Assert.assertEquals(2, set.size());
-		Iterator<Map.Entry<List<String>, List<Double>>> it = set.iterator();
-		Map.Entry<List<String>, List<Double>> e = it.next();
-		Assert.assertTrue(e.getKey().get(0).equals(aggField1Value2));
-		Assert.assertTrue(e.getValue().get(0).equals(d1));
-		e = it.next();
-		Assert.assertTrue(e.getKey().get(0).equals(aggField1Value1));
-		Assert.assertTrue(e.getValue().get(0).equals(d2));
-		try{
-			String value = mapper.writeValueAsString(set);
-			logger.info(value);
-		}catch(Exception ex){
-			logger.error("fail with mapping", ex);
-			Assert.fail("fail with mapping");
-		}
-		
-		
-		// sort by function2
-		so = new SortOption();
-		so.setIndex(1);
-		so.setAscendant(true);
-		sortOptions = Arrays.asList(so);
-		set = PostFlatAggregateSort.sort(result, sortOptions, 0);
-		factory = new JsonFactory();
-		mapper = new ObjectMapper(factory);
-		Assert.assertEquals(2, set.size());
-		it = set.iterator();
-		e = it.next();
-		Assert.assertTrue(e.getKey().get(0).equals(aggField1Value1));
-		Assert.assertTrue(e.getValue().get(0).equals(d2));
-		e = it.next();
-		Assert.assertTrue(e.getKey().get(0).equals(aggField1Value2));
-		Assert.assertTrue(e.getValue().get(0).equals(d1));
-		try{
-			String value = mapper.writeValueAsString(set);
-			logger.info(value);
-		}catch(Exception ex){
-			logger.error("fail with mapping", ex);
-			Assert.fail("fail with mapping");
-		}
-	}
-	
-	@Test
-	public void testDefaultSort(){
-		final String aggField1Value1 = "xyz";
-		final String aggField1Value2 = "xyz";
-		final String aggField2Value1 = "abd";
-		final String aggField2Value2 = "abc";
-		final Double d1 = new Double(1);
-		final Double d2 = new Double(1);
-		@SuppressWarnings("serial")
-		Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>(){{
-			put(Arrays.asList(aggField1Value1, aggField2Value1), Arrays.asList(d2));
-			put(Arrays.asList(aggField1Value2, aggField2Value2), Arrays.asList(d1));
-		}};
-		
-		// sort by function1
-		SortOption so = new SortOption();
-		so.setIndex(0);
-		so.setAscendant(true);
-		List<SortOption> sortOptions = Arrays.asList(so);
-		List<Map.Entry<List<String>, List<Double>>> set = 
-				PostFlatAggregateSort.sort(result, sortOptions, 0);
-		JsonFactory factory = new JsonFactory();
-		ObjectMapper mapper = new ObjectMapper(factory);
-		Assert.assertEquals(2, set.size());
-		Iterator<Map.Entry<List<String>, List<Double>>> it = set.iterator();
-		Map.Entry<List<String>, List<Double>> e = it.next();
-		Assert.assertTrue(e.getKey().get(0).equals(aggField1Value2));
-		Assert.assertTrue(e.getValue().get(0).equals(d1));
-		e = it.next();
-		Assert.assertTrue(e.getKey().get(0).equals(aggField1Value1));
-		Assert.assertTrue(e.getValue().get(0).equals(d2));
-		try{
-			String value = mapper.writeValueAsString(set);
-			logger.info(value);
-		}catch(Exception ex){
-			logger.error("fail with mapping", ex);
-			Assert.fail("fail with mapping");
-		}
-	}
+    private static final Logger logger = Logger.getLogger(TestPostFlatAggregateSort.class);
+
+    @Test
+    public void testSort() {
+        final String aggField1Value1 = "field1value1";
+        final String aggField1Value2 = "field1value2";
+        final String aggField2Value1 = "field2value1";
+        final String aggField2Value2 = "field2value2";
+        final Double d1 = new Double(1);
+        final Double d2 = new Double(2);
+        final Double d3 = new Double(3);
+        final Double d4 = new Double(4);
+        @SuppressWarnings("serial")
+        Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>() {{
+            put(Arrays.asList(aggField1Value1, aggField2Value1), Arrays.asList(d2, d3));
+            put(Arrays.asList(aggField1Value2, aggField2Value2), Arrays.asList(d1, d4));
+        }};
+
+        // sort by function1
+        SortOption so = new SortOption();
+        so.setIndex(0);
+        so.setAscendant(true);
+        List<SortOption> sortOptions = Arrays.asList(so);
+        List<Map.Entry<List<String>, List<Double>>> set =
+            PostFlatAggregateSort.sort(result, sortOptions, 0);
+        JsonFactory factory = new JsonFactory();
+        ObjectMapper mapper = new ObjectMapper(factory);
+        Assert.assertEquals(2, set.size());
+        Iterator<Map.Entry<List<String>, List<Double>>> it = set.iterator();
+        Map.Entry<List<String>, List<Double>> e = it.next();
+        Assert.assertTrue(e.getKey().get(0).equals(aggField1Value2));
+        Assert.assertTrue(e.getValue().get(0).equals(d1));
+        e = it.next();
+        Assert.assertTrue(e.getKey().get(0).equals(aggField1Value1));
+        Assert.assertTrue(e.getValue().get(0).equals(d2));
+        try {
+            String value = mapper.writeValueAsString(set);
+            logger.info(value);
+        } catch (Exception ex) {
+            logger.error("fail with mapping", ex);
+            Assert.fail("fail with mapping");
+        }
+
+
+        // sort by function2
+        so = new SortOption();
+        so.setIndex(1);
+        so.setAscendant(true);
+        sortOptions = Arrays.asList(so);
+        set = PostFlatAggregateSort.sort(result, sortOptions, 0);
+        factory = new JsonFactory();
+        mapper = new ObjectMapper(factory);
+        Assert.assertEquals(2, set.size());
+        it = set.iterator();
+        e = it.next();
+        Assert.assertTrue(e.getKey().get(0).equals(aggField1Value1));
+        Assert.assertTrue(e.getValue().get(0).equals(d2));
+        e = it.next();
+        Assert.assertTrue(e.getKey().get(0).equals(aggField1Value2));
+        Assert.assertTrue(e.getValue().get(0).equals(d1));
+        try {
+            String value = mapper.writeValueAsString(set);
+            logger.info(value);
+        } catch (Exception ex) {
+            logger.error("fail with mapping", ex);
+            Assert.fail("fail with mapping");
+        }
+    }
+
+    @Test
+    public void testDefaultSort() {
+        final String aggField1Value1 = "xyz";
+        final String aggField1Value2 = "xyz";
+        final String aggField2Value1 = "abd";
+        final String aggField2Value2 = "abc";
+        final Double d1 = new Double(1);
+        final Double d2 = new Double(1);
+        @SuppressWarnings("serial")
+        Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>() {{
+            put(Arrays.asList(aggField1Value1, aggField2Value1), Arrays.asList(d2));
+            put(Arrays.asList(aggField1Value2, aggField2Value2), Arrays.asList(d1));
+        }};
+
+        // sort by function1
+        SortOption so = new SortOption();
+        so.setIndex(0);
+        so.setAscendant(true);
+        List<SortOption> sortOptions = Arrays.asList(so);
+        List<Map.Entry<List<String>, List<Double>>> set =
+            PostFlatAggregateSort.sort(result, sortOptions, 0);
+        JsonFactory factory = new JsonFactory();
+        ObjectMapper mapper = new ObjectMapper(factory);
+        Assert.assertEquals(2, set.size());
+        Iterator<Map.Entry<List<String>, List<Double>>> it = set.iterator();
+        Map.Entry<List<String>, List<Double>> e = it.next();
+        Assert.assertTrue(e.getKey().get(0).equals(aggField1Value2));
+        Assert.assertTrue(e.getValue().get(0).equals(d1));
+        e = it.next();
+        Assert.assertTrue(e.getKey().get(0).equals(aggField1Value1));
+        Assert.assertTrue(e.getValue().get(0).equals(d2));
+        try {
+            String value = mapper.writeValueAsString(set);
+            logger.info(value);
+        } catch (Exception ex) {
+            logger.error("fail with mapping", ex);
+            Assert.fail("fail with mapping");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestTimeSeriesAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestTimeSeriesAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestTimeSeriesAggregator.java
index b72bdb7..0ec00d5 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestTimeSeriesAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestTimeSeriesAggregator.java
@@ -32,144 +32,145 @@ import org.slf4j.LoggerFactory;
 import org.apache.eagle.log.entity.test.TestEntity;
 
 public class TestTimeSeriesAggregator {
-	private static final Logger LOG = LoggerFactory.getLogger(TestFlatAggregator.class);
-	@SuppressWarnings("serial")
-	private TestEntity createEntity(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters, long timestamp){
-		TestEntity entity = new TestEntity();
-		Map<String, String> tags = new HashMap<String, String>(){{
-			put("cluster", cluster);
-			put("datacenter", datacenter);
-			put("rack", rack);
-		}}; 
-		entity.setTags(tags);
-		entity.setNumHosts(numHosts);
-		entity.setNumClusters(numClusters);
-		entity.setTimestamp(timestamp);
-		return entity;
-	}
-	
-	@Test
-	public void testTimeSeriesAggregator(){
-		TestEntity[] entities = new TestEntity[8];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2, 1386120000*1000); // bucket 0
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1, 1386121060*1000); // bucket 17
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0, 1386121070*1000); // bucket 17
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9,   2, 1386122122*1000); // bucket 35
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15,  5, 1386123210*1000); // bucket 53
-		entities[5] = createEntity("cluster2", "dc1", "rack234", 25,  1, 1386123480*1000); // bucket 58
-		entities[6] = createEntity("cluster2", "dc1", "rack234", 12,  0, 1386123481*1000); // bucket 58
-		entities[7] = createEntity("cluster1", "dc1", "rack123", 3,    2, 1386123482*1000); // bucket 58
-		
-		TimeSeriesAggregator tsAgg = new TimeSeriesAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"),
-				1386120000*1000, 1386123600*1000, 60*1000);
-		try{
-			for(TestEntity e : entities){
-				tsAgg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = tsAgg.result();
-			Assert.assertEquals(result.size(), 6);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "0")).get(0), (double)(entities[0].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "17")).get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "35")).get(0), (double)(entities[3].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "53")).get(0), (double)(entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "58")).get(0), (double)(entities[5].getNumHosts()+entities[6].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "58")).get(0), (double)(entities[7].getNumHosts()), 0.001);
-			
-			Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
-			Assert.assertEquals(tsResult.size(), 2);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0).length, 60);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[0], (double)(entities[0].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[17], (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[35], (double)(entities[3].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[53], (double)(entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[58], (double)(entities[5].getNumHosts()+entities[6].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[58], (double)(entities[7].getNumHosts()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		tsAgg = new TimeSeriesAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), 
-				1386120000*1000, 1386123600*1000, 60*1000);
-		try{
-			for(TestEntity e : entities){
-				tsAgg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = tsAgg.result();
-			Assert.assertEquals(result.size(), 5);
-			Assert.assertEquals(result.get(Arrays.asList("0")).get(0), (double)(entities[0].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("17")).get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("35")).get(0), (double)(entities[3].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("53")).get(0), (double)(entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("58")).get(0), (double)(entities[5].getNumHosts()+entities[6].getNumHosts()+entities[7].getNumHosts()), 0.001);
-			
-			Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
-			Assert.assertEquals(tsResult.size(), 1);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0).length, 60);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[0], (double)(entities[0].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[17], (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[35], (double)(entities[3].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[53], (double)(entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[58], (double)(entities[5].getNumHosts()+entities[6].getNumHosts()+entities[7].getNumHosts()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		tsAgg = new TimeSeriesAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), 
-				1386120000*1000, 1386123600*1000, 60*1000);
-		try{
-			for(TestEntity e : entities){
-				tsAgg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = tsAgg.result();
-			Assert.assertEquals(result.size(), 6);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "0")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "17")).get(0), (double)(2), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "35")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "53")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "58")).get(0), (double)(2), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "58")).get(0), (double)(1), 0.001);
-			
-			Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
-			Assert.assertEquals(tsResult.size(), 2);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0).length, 60);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[0], (double)(1), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[17], (double)(2), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[35], (double)(1), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[53], (double)(1), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[58], (double)(2), 0.001);
-			Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[58], (double)(1), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		tsAgg = new TimeSeriesAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), 
-				1386120000*1000, 1386123600*1000, 60*1000);
-		try{
-			for(TestEntity e : entities){
-				tsAgg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = tsAgg.result();
-			Assert.assertEquals(result.size(), 5);
-			Assert.assertEquals(result.get(Arrays.asList("0")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("17")).get(0), (double)(2), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("35")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("53")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("58")).get(0), (double)(3), 0.001);
-			
-			Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
-			Assert.assertEquals(tsResult.size(), 1);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0).length, 60);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[0], (double)(1), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[17], (double)(2), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[35], (double)(1), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[53], (double)(1), 0.001);
-			Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[58], (double)(3), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(TestFlatAggregator.class);
+
+    @SuppressWarnings("serial")
+    private TestEntity createEntity(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters, long timestamp) {
+        TestEntity entity = new TestEntity();
+        Map<String, String> tags = new HashMap<String, String>() {{
+            put("cluster", cluster);
+            put("datacenter", datacenter);
+            put("rack", rack);
+        }};
+        entity.setTags(tags);
+        entity.setNumHosts(numHosts);
+        entity.setNumClusters(numClusters);
+        entity.setTimestamp(timestamp);
+        return entity;
+    }
+
+    @Test
+    public void testTimeSeriesAggregator() {
+        TestEntity[] entities = new TestEntity[8];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2, 1386120000*1000); // bucket 0
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1, 1386121060*1000); // bucket 17
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0, 1386121070*1000); // bucket 17
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9,   2, 1386122122*1000); // bucket 35
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15,  5, 1386123210*1000); // bucket 53
+        entities[5] = createEntity("cluster2", "dc1", "rack234", 25,  1, 1386123480*1000); // bucket 58
+        entities[6] = createEntity("cluster2", "dc1", "rack234", 12,  0, 1386123481*1000); // bucket 58
+        entities[7] = createEntity("cluster1", "dc1", "rack123", 3,    2, 1386123482*1000); // bucket 58
+
+        TimeSeriesAggregator tsAgg = new TimeSeriesAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"),
+                                                              1386120000*1000, 1386123600*1000, 60*1000);
+        try {
+            for (TestEntity e : entities) {
+                tsAgg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = tsAgg.result();
+            Assert.assertEquals(result.size(), 6);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "0")).get(0), (double)(entities[0].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "17")).get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "35")).get(0), (double)(entities[3].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "53")).get(0), (double)(entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "58")).get(0), (double)(entities[5].getNumHosts()+entities[6].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "58")).get(0), (double)(entities[7].getNumHosts()), 0.001);
+
+            Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
+            Assert.assertEquals(tsResult.size(), 2);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0).length, 60);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[0], (double)(entities[0].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[17], (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[35], (double)(entities[3].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[53], (double)(entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[58], (double)(entities[5].getNumHosts()+entities[6].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[58], (double)(entities[7].getNumHosts()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        tsAgg = new TimeSeriesAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"),
+                                         1386120000*1000, 1386123600*1000, 60*1000);
+        try {
+            for (TestEntity e : entities) {
+                tsAgg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = tsAgg.result();
+            Assert.assertEquals(result.size(), 5);
+            Assert.assertEquals(result.get(Arrays.asList("0")).get(0), (double)(entities[0].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("17")).get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("35")).get(0), (double)(entities[3].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("53")).get(0), (double)(entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("58")).get(0), (double)(entities[5].getNumHosts()+entities[6].getNumHosts()+entities[7].getNumHosts()), 0.001);
+
+            Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
+            Assert.assertEquals(tsResult.size(), 1);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0).length, 60);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[0], (double)(entities[0].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[17], (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[35], (double)(entities[3].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[53], (double)(entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[58], (double)(entities[5].getNumHosts()+entities[6].getNumHosts()+entities[7].getNumHosts()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        tsAgg = new TimeSeriesAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"),
+                                         1386120000*1000, 1386123600*1000, 60*1000);
+        try {
+            for (TestEntity e : entities) {
+                tsAgg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = tsAgg.result();
+            Assert.assertEquals(result.size(), 6);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "0")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "17")).get(0), (double)(2), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "35")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "53")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "58")).get(0), (double)(2), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "58")).get(0), (double)(1), 0.001);
+
+            Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
+            Assert.assertEquals(tsResult.size(), 2);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0).length, 60);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[0], (double)(1), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[17], (double)(2), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[35], (double)(1), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[53], (double)(1), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster2")).get(0)[58], (double)(2), 0.001);
+            Assert.assertEquals(tsResult.get(Arrays.asList("cluster1")).get(0)[58], (double)(1), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        tsAgg = new TimeSeriesAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"),
+                                         1386120000*1000, 1386123600*1000, 60*1000);
+        try {
+            for (TestEntity e : entities) {
+                tsAgg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = tsAgg.result();
+            Assert.assertEquals(result.size(), 5);
+            Assert.assertEquals(result.get(Arrays.asList("0")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("17")).get(0), (double)(2), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("35")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("53")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("58")).get(0), (double)(3), 0.001);
+
+            Map<List<String>, List<double[]>> tsResult = tsAgg.getMetric();
+            Assert.assertEquals(tsResult.size(), 1);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0).length, 60);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[0], (double)(1), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[17], (double)(2), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[35], (double)(1), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[53], (double)(1), 0.001);
+            Assert.assertEquals(tsResult.get(new ArrayList<String>()).get(0)[58], (double)(3), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-dev/checkstyle-suppressions.xml
----------------------------------------------------------------------
diff --git a/eagle-dev/checkstyle-suppressions.xml b/eagle-dev/checkstyle-suppressions.xml
index 74b63c5..81431ba 100644
--- a/eagle-dev/checkstyle-suppressions.xml
+++ b/eagle-dev/checkstyle-suppressions.xml
@@ -20,4 +20,6 @@
     <!-- Suppresses files in the src/main folder. To be used for rules which only apply to test
          code. -->
     <suppress files="[\\/]src[\\/]main[\\/].*" id="TestScope"/>
+
+    <suppress checks="Javadoc" files="."/>
 </suppressions>


[7/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

Posted by ja...@apache.org.
[EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

<!--
{% comment %}
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
-->

Be sure to do all of the following to help us incorporate your contribution
quickly and easily:

 - [ ] Make sure the PR title is formatted like:
   `[EAGLE-<Jira issue #>] Description of pull request`
 - [ ] Make sure tests pass via `mvn clean verify`. (Even better, enable
       Travis-CI on your fork and ensure the whole test matrix passes).
 - [ ] Replace `<Jira issue #>` in the title with the actual Jira issue
       number, if there is one.
 - [ ] If this contribution is large, please file an Apache
       [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.txt).

---

Author: Colm O hEigeartaigh <co...@apache.org>

Closes #983 from coheigea/eagle-query-base-checkstyle.


Project: http://git-wip-us.apache.org/repos/asf/eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/eagle/commit/c970bb42
Tree: http://git-wip-us.apache.org/repos/asf/eagle/tree/c970bb42
Diff: http://git-wip-us.apache.org/repos/asf/eagle/diff/c970bb42

Branch: refs/heads/master
Commit: c970bb426b9460939e7283e77e2f505b6ba3c9d5
Parents: 06a828f
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Feb 6 23:05:37 2018 -0800
Committer: Jay Sen <js...@paypal.com>
Committed: Tue Feb 6 23:05:37 2018 -0800

----------------------------------------------------------------------
 .../apache/eagle/query/GenericEntityQuery.java  |  82 +-
 .../org/apache/eagle/query/GenericQuery.java    |  36 +-
 .../apache/eagle/query/ListQueryCompiler.java   | 697 +++++++-------
 .../org/apache/eagle/query/QueryConstants.java  |   4 +-
 .../query/aggregate/AggregateAPIEntity.java     |  89 +-
 .../aggregate/AggregateAPIEntityFactory.java    |   2 +-
 .../query/aggregate/AggregateCondition.java     |  74 +-
 .../AggregateFunctionNotSupportedException.java |  19 +-
 .../query/aggregate/AggregateFunctionType.java  | 108 +--
 .../aggregate/AggregateFunctionTypeMatcher.java |  40 +-
 .../eagle/query/aggregate/AggregateParams.java  | 121 +--
 .../aggregate/AggregateParamsValidator.java     | 138 +--
 .../aggregate/AggregateResultAPIEntity.java     |  67 +-
 .../eagle/query/aggregate/Aggregator.java       | 276 +++---
 .../eagle/query/aggregate/BucketQuery.java      | 115 +--
 .../IllegalAggregateFieldTypeException.java     |  19 +-
 .../query/aggregate/PostAggregateSorting.java   | 140 +--
 .../query/aggregate/SortFieldOrderType.java     |  71 +-
 .../aggregate/SortFieldOrderTypeMatcher.java    |  32 +-
 .../eagle/query/aggregate/raw/Function.java     | 195 ++--
 .../query/aggregate/raw/FunctionFactory.java    |  88 +-
 .../eagle/query/aggregate/raw/GroupbyKey.java   | 197 ++--
 .../aggregate/raw/GroupbyKeyAggregatable.java   |  16 +-
 .../aggregate/raw/GroupbyKeyComparator.java     |  38 +-
 .../query/aggregate/raw/GroupbyKeyValue.java    |  97 +-
 .../raw/GroupbyKeyValueCreationListener.java    |   2 +-
 .../eagle/query/aggregate/raw/GroupbyValue.java | 196 ++--
 .../query/aggregate/raw/RawAggregator.java      |  78 +-
 .../query/aggregate/raw/RawGroupbyBucket.java   | 319 ++++---
 .../eagle/query/aggregate/raw/WritableList.java | 129 ++-
 .../timeseries/AbstractAggregator.java          | 310 +++---
 .../query/aggregate/timeseries/Aggregator.java  |   2 +-
 .../EntityCreationListenerFactory.java          |   7 +-
 .../aggregate/timeseries/FlatAggregator.java    |  52 +-
 .../aggregate/timeseries/GroupbyBucket.java     | 433 +++++----
 .../timeseries/GroupbyFieldsComparator.java     |  31 +-
 .../timeseries/HierarchicalAggregateEntity.java |  83 +-
 .../timeseries/HierarchicalAggregator.java      | 104 +-
 .../timeseries/PostFlatAggregateSort.java       | 130 +--
 .../PostHierarchicalAggregateSort.java          | 112 +--
 .../query/aggregate/timeseries/SortOption.java  |  51 +-
 .../aggregate/timeseries/SortOptionsParser.java |  82 +-
 .../timeseries/SynchronizedAggregator.java      |  30 +-
 .../SynchronizedEntityCreationListener.java     |  28 +-
 .../timeseries/TimeSeriesAggregator.java        | 252 ++---
 .../aggregate/timeseries/TimeSeriesBucket.java  |  94 +-
 .../TimeSeriesPostFlatAggregateSort.java        | 244 ++---
 .../apache/eagle/query/TestHBaseLogReader2.java | 234 ++---
 .../eagle/query/TestListQueryCompiler.java      | 406 ++++----
 .../query/aggregate/raw/TestGroupbyKey.java     | 101 +-
 .../query/aggregate/raw/TestRawAggregator.java  | 955 ++++++++++---------
 .../raw/TestRawHBaseLogReaderAndAgg.java        |   8 +-
 .../query/aggregate/test/TestAggregator.java    | 426 ++++-----
 .../aggregate/test/TestAlertAggService.java     |  58 +-
 .../query/aggregate/test/TestBucketQuery.java   | 248 ++---
 .../query/aggregate/test/TestBucketQuery2.java  | 256 ++---
 .../aggregate/test/TestFlatAggregator.java      | 742 +++++++-------
 .../test/TestGroupbyFieldComparator.java        |  17 +-
 .../test/TestHierarchicalAggregator.java        | 570 +++++------
 .../aggregate/test/TestListQueryCompiler.java   |  12 +-
 .../test/TestPostFlatAggregateSort.java         | 215 ++---
 .../test/TestTimeSeriesAggregator.java          | 281 +++---
 eagle-dev/checkstyle-suppressions.xml           |   2 +
 63 files changed, 5119 insertions(+), 4942 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericEntityQuery.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericEntityQuery.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericEntityQuery.java
index 1319f43..e6e56d6 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericEntityQuery.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericEntityQuery.java
@@ -25,50 +25,56 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * @since : 10/30/14,2014
+ * @since : 10/30/14,2014.
  */
 public class GenericEntityQuery implements GenericQuery,EntityCreationListener {
-	private static final Logger LOG = LoggerFactory.getLogger(GenericEntityQuery.class);
+    private static final Logger LOG = LoggerFactory.getLogger(GenericEntityQuery.class);
 
-	private List<TaggedLogAPIEntity> entities = new ArrayList<TaggedLogAPIEntity>();
-	private StreamReader reader;
+    private List<TaggedLogAPIEntity> entities = new ArrayList<TaggedLogAPIEntity>();
+    private StreamReader reader;
 
-	public GenericEntityQuery(String serviceName, SearchCondition condition, String metricName) throws IllegalAccessException, InstantiationException {
-		if(serviceName.equals(GenericMetricEntity.GENERIC_METRIC_SERVICE)){
-			if(LOG.isDebugEnabled()) LOG.debug("List metric query");
-			if(metricName == null || metricName.isEmpty()){
-				throw new IllegalArgumentException("metricName should not be empty for metric list query");
-			}
-			if(!condition.getOutputFields().contains(GenericMetricEntity.VALUE_FIELD)){
-				condition.getOutputFields().add(GenericMetricEntity.VALUE_FIELD);
-			}
-			reader = new GenericEntityStreamReader(serviceName, condition,metricName);
-		}else{
-			if(LOG.isDebugEnabled()) LOG.debug("List entity query");
-			reader = new GenericEntityStreamReader(serviceName, condition);
-		}
-		reader.register(this);
-	}
+    public GenericEntityQuery(String serviceName, SearchCondition condition, String metricName) throws IllegalAccessException, InstantiationException {
+        if (serviceName.equals(GenericMetricEntity.GENERIC_METRIC_SERVICE)) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("List metric query");
+            }
+            if (metricName == null || metricName.isEmpty()) {
+                throw new IllegalArgumentException("metricName should not be empty for metric list query");
+            }
+            if (!condition.getOutputFields().contains(GenericMetricEntity.VALUE_FIELD)) {
+                condition.getOutputFields().add(GenericMetricEntity.VALUE_FIELD);
+            }
+            reader = new GenericEntityStreamReader(serviceName, condition,metricName);
+        } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("List entity query");
+            }
+            reader = new GenericEntityStreamReader(serviceName, condition);
+        }
+        reader.register(this);
+    }
 
-	@Override
-	public long getLastTimestamp() {
-		return reader.getLastTimestamp();
-	}
+    @Override
+    public long getLastTimestamp() {
+        return reader.getLastTimestamp();
+    }
 
-	@Override
-	public void entityCreated(TaggedLogAPIEntity entity){
-		entities.add(entity);
-	}
+    @Override
+    public void entityCreated(TaggedLogAPIEntity entity) {
+        entities.add(entity);
+    }
 
-	@Override
-	public List<TaggedLogAPIEntity> result() throws Exception{
-		if(LOG.isDebugEnabled()) LOG.debug("Start reading as batch mode");
-		reader.readAsStream();
-		return entities;
-	}
+    @Override
+    public List<TaggedLogAPIEntity> result() throws Exception {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Start reading as batch mode");
+        }
+        reader.readAsStream();
+        return entities;
+    }
 
-	@Override
-	public long getFirstTimeStamp() {
-		return reader.getFirstTimestamp();
-	}
+    @Override
+    public long getFirstTimeStamp() {
+        return reader.getFirstTimestamp();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericQuery.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericQuery.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericQuery.java
index d3af151..698de4e 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericQuery.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/GenericQuery.java
@@ -19,28 +19,28 @@ package org.apache.eagle.query;
 import java.util.List;
 
 /**
- * @since : 10/30/14,2014
+ * @since : 10/30/14,2014.
  */
 public interface GenericQuery {
-	/**
-	 * Throw all exceptions to http server
-	 *
+    /**
+     * Throw all exceptions to http server.
+     *
      * @param <T> result entity type
-	 * @return result entities list
-	 *
+     * @return result entities list
+     *
      * @throws Exception
-	 */
-	<T> List<T> result() throws Exception;
+     */
+    <T> List<T> result() throws Exception;
 
-	/**
-	 * Get last/largest timestamp on all rows
-	 *
-	 * @return last timestamp
-	 */
-	long getLastTimestamp();
+    /**
+     * Get last/largest timestamp on all rows.
+     *
+     * @return last timestamp
+     */
+    long getLastTimestamp();
 
-	/**
-	 * Get first timestamp on all rows
-	 */
-	long getFirstTimeStamp();
+    /**
+     * Get first timestamp on all rows.
+     */
+    long getFirstTimeStamp();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java
index ab01064..b83818b 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java
@@ -38,343 +38,364 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class ListQueryCompiler {
-	private final static Logger LOG = LoggerFactory.getLogger(ListQueryCompiler.class);
-	/**
-	 * syntax is <EntityName>[<Filter>]{<Projection>}
-	 */
-	private final static String listRegex = "^([^\\[]+)\\[(.*)\\]\\{(.+)\\}$";
-	private final static Pattern _listPattern = Pattern.compile(listRegex);
-
-	/**
-	 * syntax is @<fieldname>
-	 */
-	private final static String _fnAnyPattern = "*";
-	private final static Pattern _fnPattern = TokenConstant.ID_PATTERN;
-
-	/**
-	 * syntax is @<expression>
-	 */
-	private final static String expRegex = "^(EXP\\{.*\\})(\\s+AS)?(\\s+.*)?$";
-	private final static Pattern _expPattern = Pattern.compile(expRegex,Pattern.CASE_INSENSITIVE);
-
-	/**
-	 * syntax is <EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}
-	 */
-
-	/** The regular expression before add EXP{<Expression>} in query **/
-	private final static String aggRegex = "^([^\\[]+)\\[(.*)\\]<([^>]*)>\\{(.+)\\}$";
-	private final static Pattern _aggPattern = Pattern.compile(aggRegex);
-
-	private final static String sortRegex = "^([^\\[]+)\\[(.*)\\]<([^>]*)>\\{(.+)\\}\\.\\{(.+)\\}$";
-	private final static Pattern _sortPattern = Pattern.compile(sortRegex);
-	
-	private String _serviceName;
-	private Filter _filter;
-	private List<String> _outputFields;
-	private List<String> _groupbyFields;
-	private List<AggregateFunctionType> _aggregateFunctionTypes;
-	private List<String> _aggregateFields;
-	private List<AggregateFunctionType> _sortFunctionTypes;
-	private List<String> _sortFields;
-	private Map<String,String> _outputAlias;
-
-	/**
-	 * Filed that must be required in filter
-	 *
-	 * @return
-	 */
-	public Set<String> getFilterFields() {
-		return _filterFields;
-	}
-
-	private Set<String> _filterFields;
-	private List<SortOption> _sortOptions;
-	private boolean _hasAgg;
-	private List<String[]> _partitionValues;
-	private boolean _filterIfMissing;
-	private ORExpression _queryExpression;
-	private boolean _outputAll = false;
-
-	public ListQueryCompiler(String query) throws Exception {
-		this(query, false);
-	}
-	
-	public ListQueryCompiler(String query, boolean filterIfMissing) throws Exception{
-		this._filterIfMissing = filterIfMissing;
-		Matcher m = _listPattern.matcher(query);
-		if(m.find()){
-			if(m.groupCount() != 3)
-				throw new IllegalArgumentException("List query syntax is <EntityName>[<Filter>]{<Projection>}");
-			compileCollectionQuery(m);
-			_hasAgg = false;
-			partitionConstraintValidate(query);
-			return;
-		}
-		
-		/** match sort pattern fist, otherwise some sort query will be mismatch as agg pattern */
-		m = _sortPattern.matcher(query);
-		if(m.find()){
-			if(m.groupCount() != 5)
-				throw new IllegalArgumentException("Aggregate query syntax is <EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}.{<SortOptions>}");
-			compileAggregateQuery(m);
-			_hasAgg = true;
-			partitionConstraintValidate(query);
-			return;
-		}
-		
-		m = _aggPattern.matcher(query);
-		if(m.find()){
-			if(m.groupCount() != 4)
-			//if(m.groupCount() < 4 || m.groupCount() > 5)
-				throw new IllegalArgumentException("Aggregate query syntax is <EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}.{<SortOptions>}");
-			compileAggregateQuery(m);
-			_hasAgg = true;
-			partitionConstraintValidate(query);
-			return;
-		}
-		
-		throw new IllegalArgumentException("List query syntax is <EntityName>[<Filter>]{<Projection>} \n Aggregate query syntax is <EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}.{<SortOptions>}");
-	}
-	
-	/**
-	 * TODO: For now we don't support one query to query multiple partitions. In future if partition is defined 
-	 * for the entity, internally We need to spawn multiple queries and send one query for each search condition 
-	 * for each partition
-	 * 
-	 * @param query input query to compile
-	 */
-	private void partitionConstraintValidate(String query) {
-		if (_partitionValues != null && _partitionValues.size() > 1) {
-			final String[] values = _partitionValues.get(0);
-			for (int i = 1; i < _partitionValues.size(); ++i) {
-				final String[] tmpValues = _partitionValues.get(i);
-				for (int j = 0; j < values.length; ++j) {
-					if (values[j] == null || (!values[j].equals(tmpValues[j]))) {
-						final String errMsg = "One query for multiple partitions is NOT allowed for now! Query: " + query;
-						LOG.error(errMsg);
-						throw new IllegalArgumentException(errMsg);
-					}
-				}
-			}
-		}
-	}
-
-	public boolean hasAgg(){
-		return _hasAgg;
-	}
-	
-	public List<String[]> getQueryPartitionValues() {
-		return _partitionValues;
-	}
-	
-	public ORExpression getQueryExpression() {
-		return _queryExpression;
-	}
-	
-	private void checkEntityExistence(String entityName) throws EagleQueryParseException {
-		try {
-			if(EntityDefinitionManager.getEntityByServiceName(entityName) == null)
-				throw new EagleQueryParseException(entityName + " entity does not exist!");
-		} catch (InstantiationException e) {
-			final String errMsg = "Got an InstantiationException: " + e.getMessage();
-			throw new EagleQueryParseException(entityName + " entity does not exist! " + errMsg);
-		} catch (IllegalAccessException e) {
-			final String errMsg = "Got an IllegalAccessException: " + e.getMessage();
-			throw new EagleQueryParseException(entityName + " entity does not exist! " + errMsg);
-		}
-	}
-	
-	public String deleteAtSign(String expression) {
-		return expression.replace("@", "");
-	}
-	
-	private void compileCollectionQuery(Matcher m) throws EagleQueryParseException{
-		_serviceName = m.group(1);
-		checkEntityExistence(_serviceName);
-		if(_outputFields==null) _outputFields = new ArrayList<String>();
-		String qy = m.group(2);
-		_filter = compileQy(qy);
-		String prjFields = m.group(3);
-		String[] tmp = prjFields.split(",");
-		for(String str : tmp){
-			str = str.trim();
-			Matcher fnMatcher = _fnPattern.matcher(str);
-			Matcher expMatcher = _expPattern.matcher(str);
-			if(fnMatcher.find()) {
-				if (fnMatcher.groupCount() == 1)
-					_outputFields.add(fnMatcher.group(1));				
-			}else if(_fnAnyPattern.equals(str)){
-				if(LOG.isDebugEnabled()) LOG.debug("Output all fields");
-				// _outputFields.add(_fnAnyPattern);
-				this._outputAll = true;
-			}else if (expMatcher.find()) {
-				String expr = deleteAtSign(expMatcher.group(1));
-				String alias = expMatcher.group(3);
-				try {
-					String exprContent = TokenConstant.parseExpressionContent(expr);
-					_outputFields.addAll(ExpressionParser.parse(exprContent).getDependentFields());
-					if(alias!=null) {
-						if(_outputAlias == null) _outputAlias = new HashMap<String, String>();
-						_outputAlias.put(exprContent,alias.trim());
-					}
-				} catch (Exception ex){
-					LOG.error("Failed to parse expression: " + expr + ", exception: " + ex.getMessage(), ex);
-				} finally {
-					_outputFields.add(expr);
-				}
-			} else {
-				throw new IllegalArgumentException("Field name syntax must be @<FieldName> or * or Expression in syntax EXP{<Expression>}");
-			}
-		}
-	}
-	
-	private void compileAggregateQuery(Matcher m) throws EagleQueryParseException{
-		_serviceName = m.group(1);
-		checkEntityExistence(_serviceName);
-		String qy = m.group(2);
-		_filter = compileQy(qy);
-		String groupbyFields = m.group(3);
-		// groupbyFields could be empty
-		List<String> groupbyFieldList = null;
-		_groupbyFields = new ArrayList<String>();
-		if(!groupbyFields.isEmpty()){
-			groupbyFieldList = Arrays.asList(groupbyFields.split(","));
-			for(String str : groupbyFieldList){
-				Matcher fnMatcher = _fnPattern.matcher(str.trim());
-				if(!fnMatcher.find() || fnMatcher.groupCount() != 1)
-					throw new IllegalArgumentException("Field name syntax must be @<FieldName>");
-				_groupbyFields.add(fnMatcher.group(1));
-			}
-		}
-		String functions = m.group(4);
-		// functions
-		List<String> functionList = Arrays.asList(functions.split(","));
-		_aggregateFunctionTypes = new ArrayList<AggregateFunctionType>();
-		_aggregateFields = new ArrayList<String>();
-		for(String function : functionList){
-			AggregateFunctionTypeMatcher matcher = AggregateFunctionType.matchAll(function.trim());
-			if(!matcher.find()){
-				throw new IllegalArgumentException("Aggregate function must have format of count|sum|avg|max|min(<fieldname|expression>)");
-			}
-			_aggregateFunctionTypes.add(matcher.type());
-			String aggField = deleteAtSign(matcher.field().trim());
-			try {
-				if(_outputFields == null) _outputFields = new ArrayList<String>();
-				if(TokenConstant.isExpression(aggField)) {
-					_outputFields.addAll(ExpressionParser.parse(TokenConstant.parseExpressionContent(aggField)).getDependentFields());
-				}else{
-					_outputFields.add(aggField);
-				}
-			} catch (Exception ex){
-				LOG.error("Failed to parse expression: " + aggField + ", exception: " + ex.getMessage(), ex);
-			} finally {
-				_aggregateFields.add(aggField);
-			}
-		}
-		
-		// sort options
-		if(m.groupCount() < 5 || m.group(5) == null) // no sort options
-			return;
-		String sortOptions = m.group(5);
-		if(sortOptions != null){
-			LOG.info("SortOptions: " + sortOptions);
-			List<String> sortOptionList = Arrays.asList(sortOptions.split(","));
-			List<String> rawSortFields = new ArrayList<String>();
-			this._sortOptions = SortOptionsParser.parse(groupbyFieldList, functionList, sortOptionList, rawSortFields);
-			this._sortFunctionTypes = new ArrayList<>();
-			this._sortFields = new ArrayList<>();
-			for (String sortField : rawSortFields) {
-				AggregateFunctionTypeMatcher matcher = AggregateFunctionType.matchAll(sortField);
-				if(matcher.find()) {
-					_sortFunctionTypes.add(matcher.type());
-					_sortFields.add(deleteAtSign(matcher.field().trim()));
-				}
-			}
-		}
-	}
-	
-	/**
-	 * 1. syntax level - use antlr to pass the queries
-	 * 2. semantics level - can't distinguish tag or qualifier
-	 * @param qy
-	 * @return
-	 */
-	private Filter compileQy(String qy) throws EagleQueryParseException{
-		try {
-			EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName(_serviceName);
-			if(qy == null || qy.isEmpty()){
-				if (ed.getPartitions() == null) {
-					if(LOG.isDebugEnabled()) LOG.warn("Query string is empty, full table scan query: " + qy);
-					// For hbase 0.98+, empty FilterList() will filter all rows, so we need return null instead
+    private static final Logger LOG = LoggerFactory.getLogger(ListQueryCompiler.class);
+    /*
+     * syntax is <EntityName>[<Filter>]{<Projection>}
+     */
+    private static final String listRegex = "^([^\\[]+)\\[(.*)\\]\\{(.+)\\}$";
+    private static final Pattern listPattern = Pattern.compile(listRegex);
+
+    /*
+     * syntax is @<fieldname>
+     */
+    private static final String fnAnyPattern = "*";
+    private static final Pattern fnPattern = TokenConstant.ID_PATTERN;
+
+    /*
+     * syntax is @<expression>
+     */
+    private static final String expRegex = "^(EXP\\{.*\\})(\\s+AS)?(\\s+.*)?$";
+    private static final Pattern expPattern = Pattern.compile(expRegex,Pattern.CASE_INSENSITIVE);
+
+    /*
+     * syntax is <EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}
+     */
+
+    /** The regular expression before add EXP{<Expression>} in query **/
+    private static final String aggRegex = "^([^\\[]+)\\[(.*)\\]<([^>]*)>\\{(.+)\\}$";
+    private static final Pattern aggPattern = Pattern.compile(aggRegex);
+
+    private static final String sortRegex = "^([^\\[]+)\\[(.*)\\]<([^>]*)>\\{(.+)\\}\\.\\{(.+)\\}$";
+    private static final Pattern sortPattern = Pattern.compile(sortRegex);
+
+    private String serviceName;
+    private Filter filter;
+    private List<String> outputFields;
+    private List<String> groupbyFields;
+    private List<AggregateFunctionType> aggregateFunctionTypes;
+    private List<String> aggregateFields;
+    private List<AggregateFunctionType> sortFunctionTypes;
+    private List<String> sortFields;
+    private Map<String,String> outputAlias;
+
+    /**
+     * Filed that must be required in filter
+     *
+     * @return
+     */
+    public Set<String> getFilterFields() {
+        return filterFields;
+    }
+
+    private Set<String> filterFields;
+    private List<SortOption> sortOptions;
+    private boolean hasAgg;
+    private List<String[]> partitionValues;
+    private boolean filterIfMissing;
+    private ORExpression queryExpression;
+    private boolean outputAll = false;
+
+    public ListQueryCompiler(String query) throws Exception {
+        this(query, false);
+    }
+
+    public ListQueryCompiler(String query, boolean filterIfMissing) throws Exception {
+        this.filterIfMissing = filterIfMissing;
+        Matcher m = listPattern.matcher(query);
+        if (m.find()) {
+            if (m.groupCount() != 3) {
+                throw new IllegalArgumentException("List query syntax is <EntityName>[<Filter>]{<Projection>}");
+            }
+            compileCollectionQuery(m);
+            hasAgg = false;
+            partitionConstraintValidate(query);
+            return;
+        }
+
+        /** match sort pattern fist, otherwise some sort query will be mismatch as agg pattern */
+        m = sortPattern.matcher(query);
+        if (m.find()) {
+            if (m.groupCount() != 5) {
+                throw new IllegalArgumentException("Aggregate query syntax is <EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}.{<SortOptions>}");
+            }
+            compileAggregateQuery(m);
+            hasAgg = true;
+            partitionConstraintValidate(query);
+            return;
+        }
+
+        m = aggPattern.matcher(query);
+        if (m.find()) {
+            if (m.groupCount() != 4) {
+                //if(m.groupCount() < 4 || m.groupCount() > 5)
+                throw new IllegalArgumentException("Aggregate query syntax is <EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}.{<SortOptions>}");
+            }
+            compileAggregateQuery(m);
+            hasAgg = true;
+            partitionConstraintValidate(query);
+            return;
+        }
+
+        throw new IllegalArgumentException("List query syntax is <EntityName>[<Filter>]{<Projection>} \n Aggregate query syntax is "
+                                           + "<EntityName>[<Filter>]<GroupbyFields>{<AggregateFunctions>}.{<SortOptions>}");
+    }
+
+    /**
+     * TODO: For now we don't support one query to query multiple partitions. In future if partition is defined
+     * for the entity, internally We need to spawn multiple queries and send one query for each search condition
+     * for each partition
+     *
+     * @param query input query to compile
+     */
+    private void partitionConstraintValidate(String query) {
+        if (partitionValues != null && partitionValues.size() > 1) {
+            final String[] values = partitionValues.get(0);
+            for (int i = 1; i < partitionValues.size(); ++i) {
+                final String[] tmpValues = partitionValues.get(i);
+                for (int j = 0; j < values.length; ++j) {
+                    if (values[j] == null || (!values[j].equals(tmpValues[j]))) {
+                        final String errMsg = "One query for multiple partitions is NOT allowed for now! Query: " + query;
+                        LOG.error(errMsg);
+                        throw new IllegalArgumentException(errMsg);
+                    }
+                }
+            }
+        }
+    }
+
+    public boolean hasAgg() {
+        return hasAgg;
+    }
+
+    public List<String[]> getQueryPartitionValues() {
+        return partitionValues;
+    }
+
+    public ORExpression getQueryExpression() {
+        return queryExpression;
+    }
+
+    private void checkEntityExistence(String entityName) throws EagleQueryParseException {
+        try {
+            if (EntityDefinitionManager.getEntityByServiceName(entityName) == null) {
+                throw new EagleQueryParseException(entityName + " entity does not exist!");
+            }
+        } catch (InstantiationException e) {
+            final String errMsg = "Got an InstantiationException: " + e.getMessage();
+            throw new EagleQueryParseException(entityName + " entity does not exist! " + errMsg);
+        } catch (IllegalAccessException e) {
+            final String errMsg = "Got an IllegalAccessException: " + e.getMessage();
+            throw new EagleQueryParseException(entityName + " entity does not exist! " + errMsg);
+        }
+    }
+
+    public String deleteAtSign(String expression) {
+        return expression.replace("@", "");
+    }
+
+    private void compileCollectionQuery(Matcher m) throws EagleQueryParseException {
+        serviceName = m.group(1);
+        checkEntityExistence(serviceName);
+        if (outputFields == null) {
+            outputFields = new ArrayList<String>();
+        }
+        String qy = m.group(2);
+        filter = compileQy(qy);
+        String prjFields = m.group(3);
+        String[] tmp = prjFields.split(",");
+        for (String str : tmp) {
+            str = str.trim();
+            Matcher fnMatcher = fnPattern.matcher(str);
+            Matcher expMatcher = expPattern.matcher(str);
+            if (fnMatcher.find()) {
+                if (fnMatcher.groupCount() == 1) {
+                    outputFields.add(fnMatcher.group(1));
+                }
+            } else if (fnAnyPattern.equals(str)) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Output all fields");
+                }
+                // outputFields.add(fnAnyPattern);
+                this.outputAll = true;
+            } else if (expMatcher.find()) {
+                String expr = deleteAtSign(expMatcher.group(1));
+                String alias = expMatcher.group(3);
+                try {
+                    String exprContent = TokenConstant.parseExpressionContent(expr);
+                    outputFields.addAll(ExpressionParser.parse(exprContent).getDependentFields());
+                    if (alias != null) {
+                        if (outputAlias == null) {
+                            outputAlias = new HashMap<String, String>();
+                        }
+                        outputAlias.put(exprContent,alias.trim());
+                    }
+                } catch (Exception ex) {
+                    LOG.error("Failed to parse expression: " + expr + ", exception: " + ex.getMessage(), ex);
+                } finally {
+                    outputFields.add(expr);
+                }
+            } else {
+                throw new IllegalArgumentException("Field name syntax must be @<FieldName> or * or Expression in syntax EXP{<Expression>}");
+            }
+        }
+    }
+
+    private void compileAggregateQuery(Matcher m) throws EagleQueryParseException {
+        serviceName = m.group(1);
+        checkEntityExistence(serviceName);
+        String qy = m.group(2);
+        filter = compileQy(qy);
+        String groupbyField = m.group(3);
+        // groupbyFields could be empty
+        List<String> groupbyFieldList = null;
+        groupbyFields = new ArrayList<String>();
+        if (!groupbyField.isEmpty()) {
+            groupbyFieldList = Arrays.asList(groupbyField.split(","));
+            for (String str : groupbyFieldList) {
+                Matcher fnMatcher = fnPattern.matcher(str.trim());
+                if (!fnMatcher.find() || fnMatcher.groupCount() != 1) {
+                    throw new IllegalArgumentException("Field name syntax must be @<FieldName>");
+                }
+                groupbyFields.add(fnMatcher.group(1));
+            }
+        }
+        String functions = m.group(4);
+        // functions
+        List<String> functionList = Arrays.asList(functions.split(","));
+        aggregateFunctionTypes = new ArrayList<AggregateFunctionType>();
+        aggregateFields = new ArrayList<String>();
+        for (String function : functionList) {
+            AggregateFunctionTypeMatcher matcher = AggregateFunctionType.matchAll(function.trim());
+            if (!matcher.find()) {
+                throw new IllegalArgumentException("Aggregate function must have format of count|sum|avg|max|min(<fieldname|expression>)");
+            }
+            aggregateFunctionTypes.add(matcher.type());
+            String aggField = deleteAtSign(matcher.field().trim());
+            try {
+                if (outputFields == null) {
+                    outputFields = new ArrayList<String>();
+                }
+                if (TokenConstant.isExpression(aggField)) {
+                    outputFields.addAll(ExpressionParser.parse(TokenConstant.parseExpressionContent(aggField)).getDependentFields());
+                } else {
+                    outputFields.add(aggField);
+                }
+            } catch (Exception ex) {
+                LOG.error("Failed to parse expression: " + aggField + ", exception: " + ex.getMessage(), ex);
+            } finally {
+                aggregateFields.add(aggField);
+            }
+        }
+
+        // sort options
+        if (m.groupCount() < 5 || m.group(5) == null) { // no sort options
+            return;
+        }
+        String sortOptions = m.group(5);
+        if (sortOptions != null) {
+            LOG.info("SortOptions: " + sortOptions);
+            List<String> sortOptionList = Arrays.asList(sortOptions.split(","));
+            List<String> rawSortFields = new ArrayList<String>();
+            this.sortOptions = SortOptionsParser.parse(groupbyFieldList, functionList, sortOptionList, rawSortFields);
+            this.sortFunctionTypes = new ArrayList<>();
+            this.sortFields = new ArrayList<>();
+            for (String sortField : rawSortFields) {
+                AggregateFunctionTypeMatcher matcher = AggregateFunctionType.matchAll(sortField);
+                if (matcher.find()) {
+                    sortFunctionTypes.add(matcher.type());
+                    sortFields.add(deleteAtSign(matcher.field().trim()));
+                }
+            }
+        }
+    }
+
+    /**
+     * 1. syntax level - use antlr to pass the queries
+     * 2. semantics level - can't distinguish tag or qualifier
+     * @param qy
+     * @return
+     */
+    private Filter compileQy(String qy) throws EagleQueryParseException {
+        try {
+            EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName(serviceName);
+            if (qy == null || qy.isEmpty()) {
+                if (ed.getPartitions() == null) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.warn("Query string is empty, full table scan query: " + qy);
+                    }
+                    // For hbase 0.98+, empty FilterList() will filter all rows, so we need return null instead
                     return null;
-				} else {
-					final String errMsg = "Entity " + ed.getEntityClass().getSimpleName() + " defined partition, "
-							+ "but query doesn't provide partition condition! Query: " + qy; 
-					LOG.error(errMsg);
-					throw new IllegalArgumentException(errMsg);
-				}
-			}
-			EagleQueryParser parser = new EagleQueryParser(qy);
-			_queryExpression = parser.parse();
-			
-			//TODO: build customize filter for EXP{<Expression>}
-			HBaseFilterBuilder builder = new HBaseFilterBuilder(ed, _queryExpression, _filterIfMissing);
-			FilterList flist = builder.buildFilters();
-			_partitionValues = builder.getPartitionValues();
-			_filterFields = builder.getFilterFields();
-			return flist;
-		} catch (InstantiationException e) {
-			final String errMsg = "Got an InstantiationException: " + e.getMessage();
-			throw new EagleQueryParseException(_serviceName + " entity does not exist! " + errMsg);
-		} catch (IllegalAccessException e) {
-			final String errMsg = "Got an IllegalAccessException: " + e.getMessage();
-			throw new EagleQueryParseException(_serviceName + " entity does not exist! " + errMsg);
-		}
-	}
-	
-	public String serviceName(){
-		return _serviceName;
-	}
-	
-	public List<String> outputFields(){
-		return _outputFields;
-	}
-
-	public Filter filter(){
-		return _filter;
-	}
-	
-	public List<String> groupbyFields(){
-		return _groupbyFields;
-	}
-	
-	public List<AggregateFunctionType> aggregateFunctionTypes(){
-		return _aggregateFunctionTypes;
-	}
-	
-	public List<String> aggregateFields(){
-		return _aggregateFields;
-	}
-	
-	public List<SortOption> sortOptions(){
-		return _sortOptions;
-	}
-
-	public List<AggregateFunctionType> sortFunctions() {
-		return _sortFunctionTypes;
-	}
-	
-	public List<String> sortFields() {
-		return _sortFields;
-	}
-
-	/**
-	 * Output all fields (i.e. has * in out fields)
-	 *
-	 * @return
-	 */
-	public boolean isOutputAll(){ return _outputAll;}
-	public Map<String,String> getOutputAlias(){
-		return _outputAlias;
-	}
+                } else {
+                    final String errMsg = "Entity " + ed.getEntityClass().getSimpleName() + " defined partition, "
+                        + "but query doesn't provide partition condition! Query: " + qy;
+                    LOG.error(errMsg);
+                    throw new IllegalArgumentException(errMsg);
+                }
+            }
+            EagleQueryParser parser = new EagleQueryParser(qy);
+            queryExpression = parser.parse();
+
+            //TODO: build customize filter for EXP{<Expression>}
+            HBaseFilterBuilder builder = new HBaseFilterBuilder(ed, queryExpression, filterIfMissing);
+            FilterList flist = builder.buildFilters();
+            partitionValues = builder.getPartitionValues();
+            filterFields = builder.getFilterFields();
+            return flist;
+        } catch (InstantiationException e) {
+            final String errMsg = "Got an InstantiationException: " + e.getMessage();
+            throw new EagleQueryParseException(serviceName + " entity does not exist! " + errMsg);
+        } catch (IllegalAccessException e) {
+            final String errMsg = "Got an IllegalAccessException: " + e.getMessage();
+            throw new EagleQueryParseException(serviceName + " entity does not exist! " + errMsg);
+        }
+    }
+
+    public String serviceName() {
+        return serviceName;
+    }
+
+    public List<String> outputFields() {
+        return outputFields;
+    }
+
+    public Filter filter() {
+        return filter;
+    }
+
+    public List<String> groupbyFields() {
+        return groupbyFields;
+    }
+
+    public List<AggregateFunctionType> aggregateFunctionTypes() {
+        return aggregateFunctionTypes;
+    }
+
+    public List<String> aggregateFields() {
+        return aggregateFields;
+    }
+
+    public List<SortOption> sortOptions() {
+        return sortOptions;
+    }
+
+    public List<AggregateFunctionType> sortFunctions() {
+        return sortFunctionTypes;
+    }
+
+    public List<String> sortFields() {
+        return sortFields;
+    }
+
+    /**
+     * Output all fields (i.e. has * in out fields)
+     *
+     * @return
+     */
+    public boolean isOutputAll() {
+        return outputAll;
+    }
+
+    public Map<String,String> getOutputAlias() {
+        return outputAlias;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/QueryConstants.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/QueryConstants.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/QueryConstants.java
index 231cc99..7205568 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/QueryConstants.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/QueryConstants.java
@@ -17,8 +17,8 @@
 package org.apache.eagle.query;
 
 /**
- * @since 3/25/15
+ * @since 3/25/15.
  */
 public class QueryConstants {
-    public final static String CHARSET ="UTF-8";
+    public static final String CHARSET = "UTF-8";
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntity.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntity.java
index 8081c88..ed7e8af 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntity.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntity.java
@@ -24,46 +24,55 @@ import java.util.TreeMap;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
 public class AggregateAPIEntity {
-	private long numDirectDescendants;
-	private long numTotalDescendants;
-	private String key;
-	private SortedMap<String, AggregateAPIEntity> entityList = new TreeMap<String, AggregateAPIEntity>();
-	private List<AggregateAPIEntity> sortedList = new ArrayList<AggregateAPIEntity>();
+    private long numDirectDescendants;
+    private long numTotalDescendants;
+    private String key;
+    private SortedMap<String, AggregateAPIEntity> entityList = new TreeMap<String, AggregateAPIEntity>();
+    private List<AggregateAPIEntity> sortedList = new ArrayList<AggregateAPIEntity>();
 
-	public String getKey() {
-		return key;
-	}
-	public void setKey(String key) {
-		this.key = key;
-	}
-	@JsonProperty("sL")
-	public List<AggregateAPIEntity> getSortedList() {
-		return sortedList;
-	}
-	public void setSortedList(List<AggregateAPIEntity> sortedList) {
-		this.sortedList = sortedList;
-	}
-	@JsonProperty("eL")
-	public SortedMap<String, AggregateAPIEntity> getEntityList() {
-		return entityList;
-	}
-	public void setEntityList(SortedMap<String, AggregateAPIEntity> entityList) {
-		this.entityList = entityList;
-	}
-	@JsonProperty("nDD")
-	public long getNumDirectDescendants() {
-		return numDirectDescendants;
-	}
-	public void setNumDirectDescendants(long numDirectDescendants) {
-		this.numDirectDescendants = numDirectDescendants;
-	}
-	@JsonProperty("nTD")
-	public long getNumTotalDescendants() {
-		return numTotalDescendants;
-	}
-	public void setNumTotalDescendants(long numTotalDescendants) {
-		this.numTotalDescendants = numTotalDescendants;
-	}
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    @JsonProperty("sL")
+    public List<AggregateAPIEntity> getSortedList() {
+        return sortedList;
+    }
+
+    public void setSortedList(List<AggregateAPIEntity> sortedList) {
+        this.sortedList = sortedList;
+    }
+
+    @JsonProperty("eL")
+    public SortedMap<String, AggregateAPIEntity> getEntityList() {
+        return entityList;
+    }
+
+    public void setEntityList(SortedMap<String, AggregateAPIEntity> entityList) {
+        this.entityList = entityList;
+    }
+
+    @JsonProperty("nDD")
+    public long getNumDirectDescendants() {
+        return numDirectDescendants;
+    }
+
+    public void setNumDirectDescendants(long numDirectDescendants) {
+        this.numDirectDescendants = numDirectDescendants;
+    }
+
+    @JsonProperty("nTD")
+    public long getNumTotalDescendants() {
+        return numTotalDescendants;
+    }
+
+    public void setNumTotalDescendants(long numTotalDescendants) {
+        this.numTotalDescendants = numTotalDescendants;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntityFactory.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntityFactory.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntityFactory.java
index 8e18b39..050569d 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntityFactory.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateAPIEntityFactory.java
@@ -17,5 +17,5 @@
 package org.apache.eagle.query.aggregate;
 
 public interface AggregateAPIEntityFactory {
-	public AggregateAPIEntity create();
+    AggregateAPIEntity create();
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateCondition.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateCondition.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateCondition.java
index 5555cfd..c62a05a 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateCondition.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateCondition.java
@@ -23,51 +23,51 @@ import java.util.List;
  *
  * @since : 11/7/14,2014
  */
-public class AggregateCondition implements Serializable{
-	private static final long serialVersionUID = 1L;
-	private List<String> groupbyFields;
-	private List<AggregateFunctionType> aggregateFunctionTypes;
-	private List<String> aggregateFields;
-	private boolean timeSeries;
-	private long intervalMS;
+public class AggregateCondition implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private List<String> groupbyFields;
+    private List<AggregateFunctionType> aggregateFunctionTypes;
+    private List<String> aggregateFields;
+    private boolean timeSeries;
+    private long intervalMS;
 
-	public List<String> getGroupbyFields() {
-		return groupbyFields;
-	}
+    public List<String> getGroupbyFields() {
+        return groupbyFields;
+    }
 
-	public void setGroupbyFields(List<String> groupbyFields) {
-		this.groupbyFields = groupbyFields;
-	}
+    public void setGroupbyFields(List<String> groupbyFields) {
+        this.groupbyFields = groupbyFields;
+    }
 
-	public List<AggregateFunctionType> getAggregateFunctionTypes() {
-		return aggregateFunctionTypes;
-	}
+    public List<AggregateFunctionType> getAggregateFunctionTypes() {
+        return aggregateFunctionTypes;
+    }
 
-	public void setAggregateFunctionTypes(List<AggregateFunctionType> aggregateFunctionTypes) {
-		this.aggregateFunctionTypes = aggregateFunctionTypes;
-	}
+    public void setAggregateFunctionTypes(List<AggregateFunctionType> aggregateFunctionTypes) {
+        this.aggregateFunctionTypes = aggregateFunctionTypes;
+    }
 
-	public List<String> getAggregateFields() {
-		return aggregateFields;
-	}
+    public List<String> getAggregateFields() {
+        return aggregateFields;
+    }
 
-	public void setAggregateFields(List<String> aggregateFields) {
-		this.aggregateFields = aggregateFields;
-	}
+    public void setAggregateFields(List<String> aggregateFields) {
+        this.aggregateFields = aggregateFields;
+    }
 
-	public boolean isTimeSeries() {
-		return timeSeries;
-	}
+    public boolean isTimeSeries() {
+        return timeSeries;
+    }
 
-	public void setTimeSeries(boolean timeSeries) {
-		this.timeSeries = timeSeries;
-	}
+    public void setTimeSeries(boolean timeSeries) {
+        this.timeSeries = timeSeries;
+    }
 
-	public long getIntervalMS() {
-		return intervalMS;
-	}
+    public long getIntervalMS() {
+        return intervalMS;
+    }
 
-	public void setIntervalMS(long intervalMS) {
-		this.intervalMS = intervalMS;
-	}
+    public void setIntervalMS(long intervalMS) {
+        this.intervalMS = intervalMS;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionNotSupportedException.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionNotSupportedException.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionNotSupportedException.java
index df35c8b..09ce4b7 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionNotSupportedException.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionNotSupportedException.java
@@ -16,13 +16,14 @@
  */
 package org.apache.eagle.query.aggregate;
 
-public class AggregateFunctionNotSupportedException extends RuntimeException{
-	static final long serialVersionUID = -4548788354899625887L;
-	public AggregateFunctionNotSupportedException(){
-		super();
-	}
-	
-	public AggregateFunctionNotSupportedException(String message){
-		super(message);
-	}
+public class AggregateFunctionNotSupportedException extends RuntimeException {
+    static final long serialVersionUID = -4548788354899625887L;
+
+    public AggregateFunctionNotSupportedException() {
+        super();
+    }
+
+    public AggregateFunctionNotSupportedException(String message) {
+        super(message);
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionType.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionType.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionType.java
index 8ac3b8c..73d4dc0 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionType.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionType.java
@@ -21,65 +21,65 @@ import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-public enum AggregateFunctionType{
-	count("^(count)$"),
-	sum("^sum\\((.*)\\)$"),
-	avg("^avg\\((.*)\\)$"),
-	max("^max\\((.*)\\)$"),
-	min("^min\\((.*)\\)$");
-	
-	private Pattern pattern;
-	private AggregateFunctionType(String patternString){
-		this.pattern = Pattern.compile(patternString);
-	}
+public enum AggregateFunctionType {
+    count("^(count)$"),
+    sum("^sum\\((.*)\\)$"),
+    avg("^avg\\((.*)\\)$"),
+    max("^max\\((.*)\\)$"),
+    min("^min\\((.*)\\)$");
 
-	/**
-	 * This method is thread safe
-	 * match and retrieve back the aggregated fields, for count, aggregateFields can be null
-	 * @param function
-	 * @return
-	 */
-	public AggregateFunctionTypeMatcher matcher(String function){
-		Matcher m = pattern.matcher(function);
+    private Pattern pattern;
+    private AggregateFunctionType(String patternString) {
+        this.pattern = Pattern.compile(patternString);
+    }
 
-		if(m.find()){
-			return new AggregateFunctionTypeMatcher(this, true, m.group(1));
-		}else{
-			return new AggregateFunctionTypeMatcher(this, false, null);
-		}
-	}
+    /**
+     * This method is thread safe
+     * match and retrieve back the aggregated fields, for count, aggregateFields can be null
+     * @param function
+     * @return
+     */
+    public AggregateFunctionTypeMatcher matcher(String function) {
+        Matcher m = pattern.matcher(function);
 
-	public static AggregateFunctionTypeMatcher matchAll(String function){
-		for(AggregateFunctionType type : values()){
-			Matcher m = type.pattern.matcher(function);
-			if(m.find()){
-				return new AggregateFunctionTypeMatcher(type, true, m.group(1));
-			}
-		}
-		return new AggregateFunctionTypeMatcher(null, false, null);
-	}
+        if (m.find()) {
+            return new AggregateFunctionTypeMatcher(this, true, m.group(1));
+        } else {
+            return new AggregateFunctionTypeMatcher(this, false, null);
+        }
+    }
 
-	public static byte[] serialize(AggregateFunctionType type){
-		return type.name().getBytes();
-	}
+    public static AggregateFunctionTypeMatcher matchAll(String function) {
+        for (AggregateFunctionType type : values()) {
+            Matcher m = type.pattern.matcher(function);
+            if (m.find()) {
+                return new AggregateFunctionTypeMatcher(type, true, m.group(1));
+            }
+        }
+        return new AggregateFunctionTypeMatcher(null, false, null);
+    }
 
-	public static AggregateFunctionType deserialize(byte[] type){
-		return valueOf(new String(type));
-	}
+    public static byte[] serialize(AggregateFunctionType type) {
+        return type.name().getBytes();
+    }
 
-	public static List<byte[]> toBytesList(List<AggregateFunctionType> types){
-		List<byte[]> result = new ArrayList<byte[]>();
-		for(AggregateFunctionType type:types){
-			result.add(serialize(type));
-		}
-		return result;
-	}
+    public static AggregateFunctionType deserialize(byte[] type) {
+        return valueOf(new String(type));
+    }
 
-	public static List<AggregateFunctionType> fromBytesList(List<byte[]> types){
-		List<AggregateFunctionType> result = new ArrayList<AggregateFunctionType>();
-		for(byte[] bs:types){
-			result.add(deserialize(bs));
-		}
-		return result;
-	}
+    public static List<byte[]> toBytesList(List<AggregateFunctionType> types) {
+        List<byte[]> result = new ArrayList<byte[]>();
+        for (AggregateFunctionType type:types) {
+            result.add(serialize(type));
+        }
+        return result;
+    }
+
+    public static List<AggregateFunctionType> fromBytesList(List<byte[]> types) {
+        List<AggregateFunctionType> result = new ArrayList<AggregateFunctionType>();
+        for (byte[] bs:types) {
+            result.add(deserialize(bs));
+        }
+        return result;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionTypeMatcher.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionTypeMatcher.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionTypeMatcher.java
index 6b2bc13..c829227 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionTypeMatcher.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateFunctionTypeMatcher.java
@@ -17,25 +17,25 @@
 package org.apache.eagle.query.aggregate;
 
 public class AggregateFunctionTypeMatcher {
-	private final AggregateFunctionType type;
-	private final boolean matched;
-	private final String field;
+    private final AggregateFunctionType type;
+    private final boolean matched;
+    private final String field;
 
-	public AggregateFunctionTypeMatcher(AggregateFunctionType type, boolean matched, String field){
-		this.type = type;
-		this.matched = matched;
-		this.field = field;
-	}
-	
-	public boolean find(){
-		return this.matched;
-	}
-	
-	public String field(){
-		return this.field;
-	}
-	
-	public AggregateFunctionType type(){
-		return this.type;
-	}
+    public AggregateFunctionTypeMatcher(AggregateFunctionType type, boolean matched, String field) {
+        this.type = type;
+        this.matched = matched;
+        this.field = field;
+    }
+
+    public boolean find() {
+        return this.matched;
+    }
+
+    public String field() {
+        return this.field;
+    }
+
+    public AggregateFunctionType type() {
+        return this.type;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParams.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParams.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParams.java
index 616184d..7790f1e 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParams.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParams.java
@@ -19,59 +19,70 @@ package org.apache.eagle.query.aggregate;
 import java.util.ArrayList;
 import java.util.List;
 
-public class AggregateParams{
-	List<String> groupbyFields;
-	boolean counting;
-	List<String> sumFunctionFields = new ArrayList<String>();
-	List<SortFieldOrder> sortFieldOrders = new ArrayList<SortFieldOrder>();
-	
-	public List<SortFieldOrder> getSortFieldOrders() {
-		return sortFieldOrders;
-	}
-	public void setSortFieldOrders(List<SortFieldOrder> sortFieldOrders) {
-		this.sortFieldOrders = sortFieldOrders;
-	}
-	public List<String> getGroupbyFields() {
-		return groupbyFields;
-	}
-	public void setGroupbyFields(List<String> groupbyFields) {
-		this.groupbyFields = groupbyFields;
-	}
-	public boolean isCounting() {
-		return counting;
-	}
-	public void setCounting(boolean counting) {
-		this.counting = counting;
-	}
-	public List<String> getSumFunctionFields() {
-		return sumFunctionFields;
-	}
-	public void setSumFunctionFields(List<String> sumFunctionFields) {
-		this.sumFunctionFields = sumFunctionFields;
-	}
-
-	public static class SortFieldOrder{
-		public static final String SORT_BY_AGGREGATE_KEY = "key";
-		public static final String SORT_BY_COUNT = "count";
-		private String field;
-		private boolean ascendant;
-		
-		public SortFieldOrder(String field, boolean ascendant) {
-			super();
-			this.field = field;
-			this.ascendant = ascendant;
-		}
-		public String getField() {
-			return field;
-		}
-		public void setField(String field) {
-			this.field = field;
-		}
-		public boolean isAscendant() {
-			return ascendant;
-		}
-		public void setAscendant(boolean ascendant) {
-			this.ascendant = ascendant;
-		} 
-	}
+public class AggregateParams {
+    List<String> groupbyFields;
+    boolean counting;
+    List<String> sumFunctionFields = new ArrayList<String>();
+    List<SortFieldOrder> sortFieldOrders = new ArrayList<SortFieldOrder>();
+
+    public List<SortFieldOrder> getSortFieldOrders() {
+        return sortFieldOrders;
+    }
+
+    public void setSortFieldOrders(List<SortFieldOrder> sortFieldOrders) {
+        this.sortFieldOrders = sortFieldOrders;
+    }
+
+    public List<String> getGroupbyFields() {
+        return groupbyFields;
+    }
+
+    public void setGroupbyFields(List<String> groupbyFields) {
+        this.groupbyFields = groupbyFields;
+    }
+
+    public boolean isCounting() {
+        return counting;
+    }
+
+    public void setCounting(boolean counting) {
+        this.counting = counting;
+    }
+
+    public List<String> getSumFunctionFields() {
+        return sumFunctionFields;
+    }
+
+    public void setSumFunctionFields(List<String> sumFunctionFields) {
+        this.sumFunctionFields = sumFunctionFields;
+    }
+
+    public static class SortFieldOrder {
+        public static final String SORT_BY_AGGREGATE_KEY = "key";
+        public static final String SORT_BY_COUNT = "count";
+        private String field;
+        private boolean ascendant;
+
+        public SortFieldOrder(String field, boolean ascendant) {
+            super();
+            this.field = field;
+            this.ascendant = ascendant;
+        }
+
+        public String getField() {
+            return field;
+        }
+
+        public void setField(String field) {
+            this.field = field;
+        }
+
+        public boolean isAscendant() {
+            return ascendant;
+        }
+
+        public void setAscendant(boolean ascendant) {
+            this.ascendant = ascendant;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParamsValidator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParamsValidator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParamsValidator.java
index 9500574..ee58197 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParamsValidator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateParamsValidator.java
@@ -20,75 +20,75 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class AggregateParamsValidator {
-	/**
-	 * This method handle the following sytle syntax
-	 * sum(numConfiguredMapSlots), count group by cluster, rack 
-	 * 1. ensure that all gb fields must occur in outputField or outputTag
-	 * 2. ensure that all summarized fields must occur in outputField, 
-	 *    for example, for function=sum(numConfiguredMapSlots), numConfiguredMapSlots must occur in outputField  
-	 * 3. groupby should be pre-appended with a root groupby field  
-	 * @param outputTags
-	 * @param outputFields
-	 * @param groupbys
-	 * @param functions
-	 * @throws IllegalArgumentException
-	 */
-	public static AggregateParams compileAggregateParams(List<String> outputTags, List<String> outputFields, List<String> groupbys, List<String> functions, List<String> sortFieldOrders)
-			throws IllegalArgumentException, AggregateFunctionNotSupportedException{
-		AggregateParams aggParams = new AggregateParams();
-		// ensure that all gb fields must occur in outputField or outputTag
-		for(String groupby : groupbys){
-			if(!outputTags.contains(groupby) && !outputFields.contains(groupby)){
-				throw new IllegalArgumentException(groupby + ", All gb fields should appear in outputField list or outputTag list");
-			}
-		}
-		
-		// parse functions and ensure that all summarized fields must occur in outputField
-		for(String function : functions){
-			AggregateFunctionTypeMatcher m = AggregateFunctionType.count.matcher(function);
-			if(m.find()){
-				aggParams.setCounting(true);
-				continue;
-			}
+    /**
+     * This method handle the following sytle syntax
+     * sum(numConfiguredMapSlots), count group by cluster, rack
+     * 1. ensure that all gb fields must occur in outputField or outputTag
+     * 2. ensure that all summarized fields must occur in outputField,
+     *    for example, for function = sum(numConfiguredMapSlots), numConfiguredMapSlots must occur in outputField
+     * 3. groupby should be pre-appended with a root groupby field
+     * @param outputTags
+     * @param outputFields
+     * @param groupbys
+     * @param functions
+     * @throws IllegalArgumentException
+     */
+    public static AggregateParams compileAggregateParams(List<String> outputTags, List<String> outputFields, List<String> groupbys, List<String> functions, List<String> sortFieldOrders)
+        throws IllegalArgumentException, AggregateFunctionNotSupportedException {
+        AggregateParams aggParams = new AggregateParams();
+        // ensure that all gb fields must occur in outputField or outputTag
+        for (String groupby : groupbys) {
+            if (!outputTags.contains(groupby) && !outputFields.contains(groupby)) {
+                throw new IllegalArgumentException(groupby + ", All gb fields should appear in outputField list or outputTag list");
+            }
+        }
 
-			m = AggregateFunctionType.sum.matcher(function);
-			if(m.find()){
-				if(!outputFields.contains(m.field())){
-					throw new IllegalArgumentException(m.field() + ", All summary function fields should appear in outputField list");
-				}
-				aggParams.getSumFunctionFields().add(m.field());
-				continue;
-			}
-			
-			throw new AggregateFunctionNotSupportedException("function " + function + " is not supported, only count, sum aggregate functions are now supported");
-		}
-		
-		//  groupby should be pre-appended with a root groupby field
-		List<String> groupbyFields = new ArrayList<String>();
-		groupbyFields.add(Aggregator.GROUPBY_ROOT_FIELD_NAME);
-		groupbyFields.addAll(groupbys);
-		aggParams.setGroupbyFields(groupbyFields);
+        // parse functions and ensure that all summarized fields must occur in outputField
+        for (String function : functions) {
+            AggregateFunctionTypeMatcher m = AggregateFunctionType.count.matcher(function);
+            if (m.find()) {
+                aggParams.setCounting(true);
+                continue;
+            }
 
-		// check sort field orders
-		boolean byKeySorting = false;
-		for(String sortFieldOrder : sortFieldOrders){
-			AggregateParams.SortFieldOrder sfo = SortFieldOrderType.matchAll(sortFieldOrder);
-			if(sfo == null){
-				throw new IllegalArgumentException(sortFieldOrder + ", All sort field order should be <field>=(asc|desc)");
-			}
-			if(sfo.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_AGGREGATE_KEY)){
-				byKeySorting =  true;
-			}else if(!sfo.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_COUNT)){
-				if(!groupbys.contains(sfo.getField()) && !aggParams.getSumFunctionFields().contains(sfo.getField())){
-					throw new IllegalArgumentException(sortFieldOrder + ", All sort field order should appear in gb or function fields");
-				}
-			}
-			aggParams.getSortFieldOrders().add(sfo);
-		}
-		// always add key ascendant to the last aggregation key if not specified
-		if(!byKeySorting){
-			aggParams.getSortFieldOrders().add(new AggregateParams.SortFieldOrder(AggregateParams.SortFieldOrder.SORT_BY_AGGREGATE_KEY, true));
-		}
-		return aggParams;
-	}
+            m = AggregateFunctionType.sum.matcher(function);
+            if (m.find()) {
+                if (!outputFields.contains(m.field())) {
+                    throw new IllegalArgumentException(m.field() + ", All summary function fields should appear in outputField list");
+                }
+                aggParams.getSumFunctionFields().add(m.field());
+                continue;
+            }
+
+            throw new AggregateFunctionNotSupportedException("function " + function + " is not supported, only count, sum aggregate functions are now supported");
+        }
+
+        //  groupby should be pre-appended with a root groupby field
+        List<String> groupbyFields = new ArrayList<String>();
+        groupbyFields.add(Aggregator.GROUPBY_ROOT_FIELD_NAME);
+        groupbyFields.addAll(groupbys);
+        aggParams.setGroupbyFields(groupbyFields);
+
+        // check sort field orders
+        boolean byKeySorting = false;
+        for (String sortFieldOrder : sortFieldOrders) {
+            AggregateParams.SortFieldOrder sfo = SortFieldOrderType.matchAll(sortFieldOrder);
+            if (sfo == null) {
+                throw new IllegalArgumentException(sortFieldOrder + ", All sort field order should be <field>=(asc|desc)");
+            }
+            if (sfo.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_AGGREGATE_KEY)) {
+                byKeySorting =  true;
+            } else if (!sfo.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_COUNT)) {
+                if (!groupbys.contains(sfo.getField()) && !aggParams.getSumFunctionFields().contains(sfo.getField())) {
+                    throw new IllegalArgumentException(sortFieldOrder + ", All sort field order should appear in gb or function fields");
+                }
+            }
+            aggParams.getSortFieldOrders().add(sfo);
+        }
+        // always add key ascendant to the last aggregation key if not specified
+        if (!byKeySorting) {
+            aggParams.getSortFieldOrders().add(new AggregateParams.SortFieldOrder(AggregateParams.SortFieldOrder.SORT_BY_AGGREGATE_KEY, true));
+        }
+        return aggParams;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateResultAPIEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateResultAPIEntity.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateResultAPIEntity.java
index 1015c2a..23ebf4f 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateResultAPIEntity.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/AggregateResultAPIEntity.java
@@ -18,35 +18,42 @@ package org.apache.eagle.query.aggregate;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
 public class AggregateResultAPIEntity {
-	private boolean success;
-	private String exception;
-	private long elapsedms;
-	private AggregateAPIEntity entity;
-
-	public long getElapsedms() {
-		return elapsedms;
-	}
-	public void setElapsedms(long elapsedms) {
-		this.elapsedms = elapsedms;
-	}
-	public AggregateAPIEntity getEntity() {
-		return entity;
-	}
-	public void setEntity(AggregateAPIEntity entity) {
-		this.entity = entity;
-	}
-	public boolean isSuccess() {
-		return success;
-	}
-	public void setSuccess(boolean success) {
-		this.success = success;
-	}
-	public String getException() {
-		return exception;
-	}
-	public void setException(String exception) {
-		this.exception = exception;
-	}
+    private boolean success;
+    private String exception;
+    private long elapsedms;
+    private AggregateAPIEntity entity;
+
+    public long getElapsedms() {
+        return elapsedms;
+    }
+
+    public void setElapsedms(long elapsedms) {
+        this.elapsedms = elapsedms;
+    }
+
+    public AggregateAPIEntity getEntity() {
+        return entity;
+    }
+
+    public void setEntity(AggregateAPIEntity entity) {
+        this.entity = entity;
+    }
+
+    public boolean isSuccess() {
+        return success;
+    }
+
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+
+    public String getException() {
+        return exception;
+    }
+
+    public void setException(String exception) {
+        this.exception = exception;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/Aggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/Aggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/Aggregator.java
index de911e5..890b7ea 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/Aggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/Aggregator.java
@@ -26,143 +26,145 @@ import org.slf4j.LoggerFactory;
 import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
 
 public class Aggregator {
-	private static final Logger LOG = LoggerFactory.getLogger(Aggregator.class);
-	public static final String GROUPBY_ROOT_FIELD_NAME = "site";
-	public static final String GROUPBY_ROOT_FIELD_VALUE = "xyz";
-	public static final String UNASSIGNED_GROUPBY_ROOT_FIELD_NAME = "unassigned";
-	
-	private final AggregateAPIEntityFactory factory;
-	private final AggregateAPIEntity root;
-	private final List<String> groupbys;
-	private final List<String> sumFunctionFields;
-	private final boolean counting;
-	
-	public Aggregator(AggregateAPIEntityFactory factory, AggregateAPIEntity root, List<String> groupbys, boolean counting, List<String> sumFunctionFields){
-		this.factory = factory;
-		this.root = root;
-		this.groupbys = groupbys;
-		this.sumFunctionFields = sumFunctionFields;
-		this.counting = counting;
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(Aggregator.class);
+    public static final String GROUPBY_ROOT_FIELD_NAME = "site";
+    public static final String GROUPBY_ROOT_FIELD_VALUE = "xyz";
+    public static final String UNASSIGNED_GROUPBY_ROOT_FIELD_NAME = "unassigned";
 
-	/**
-	 * this locate result can be cached? we don't need check if it's TaggedLogAPIEntity each time when iterating entities
-	 * @param groupby
-	 * @param obj
-	 * @return
-	 * @throws Exception
-	 */
-	private String locateGroupbyField(String groupby, TaggedLogAPIEntity obj){
-		if(groupby.equals(GROUPBY_ROOT_FIELD_NAME)){
-			return GROUPBY_ROOT_FIELD_VALUE;
-		}
-		// check tag first
-		String tagv = obj.getTags().get(groupby);
-		if(tagv != null)
-			return tagv;
-		// check against pojo, or qualifierValues
-		String fn = groupby.substring(0,1).toUpperCase()+groupby.substring(1, groupby.length());
-		try{
-			Method getM = obj.getClass().getMethod("get"+fn);
-			Object value = getM.invoke(obj);
-			return (String)value;
-		}catch(Exception ex){
-			LOG.warn(groupby + " field is in neither tags nor fields, " + ex.getMessage());
-			return null;
-		}
-	}
-	
-	/**
-	 * accumulate a list of entities
-	 * @param entities
-	 * @throws Exception
-	 */
-	public void accumulateAll(List<TaggedLogAPIEntity> entities) throws Exception{
-		for(TaggedLogAPIEntity entity : entities){
-			accumulate(entity);
-		}
-	}
-	
-	/**
-	 * currently only group by tags
-	 * groupbys' first item always is site, which is a reserved field 
-	 */
-	public void accumulate(TaggedLogAPIEntity entity) throws Exception{
-		AggregateAPIEntity current = root;
-		for(String groupby : groupbys){
-			// TODO tagv is empty, so what to do? use a reserved field_name "unassigned" ?
-			// TODO we should support all Pojo with java bean style object
-			String tagv = locateGroupbyField(groupby, entity);
-			if(tagv == null || tagv.isEmpty()){
-				tagv = UNASSIGNED_GROUPBY_ROOT_FIELD_NAME;
-			}
-			Map<String, AggregateAPIEntity> children = current.getEntityList();
-			if(children.get(tagv) == null){
-				children.put(tagv, factory.create());
-				current.setNumDirectDescendants(current.getNumDirectDescendants()+1);
-			}
-			AggregateAPIEntity child = children.get(tagv);
-			// go through all aggregate functions including count, summary etc.			
-			if(counting)
-				count(child);
-			for(String sumFunctionField : sumFunctionFields){
-				sum(child, entity, sumFunctionField);
-			}
-			
-			current = child;
-		}
-		
-	}
+    private final AggregateAPIEntityFactory factory;
+    private final AggregateAPIEntity root;
+    private final List<String> groupbys;
+    private final List<String> sumFunctionFields;
+    private final boolean counting;
 
-	
-	/**
-	 * use java bean specifications?
-	 * reflection is not efficient, let us find out solutions
-	 */
-	private void sum(Object targetObj, TaggedLogAPIEntity srcObj, String fieldName) throws Exception{
-		try{
-			String fn = fieldName.substring(0,1).toUpperCase()+fieldName.substring(1, fieldName.length());
-			Method srcGetMethod = srcObj.getClass().getMethod("get"+fn);
-			Object srcValue = srcGetMethod.invoke(srcObj);
-			if(srcValue == null){
-				return;  // silently don't count this source object
-			}
-			Method targetGetMethod = targetObj.getClass().getMethod("get"+fn);
-			Object targetValue = targetGetMethod.invoke(targetObj);
-			if(targetValue instanceof Long){
-				Method setM = targetObj.getClass().getMethod("set"+fn, long.class);
-				Long tmp1 = (Long)targetValue;
-				// TODO, now source object always have type "java.lang.String", later on we should support various type including integer type
-				Long tmp2 = null;
-				if(srcValue instanceof String){
-					tmp2 = Long.valueOf((String)srcValue);
-				}else if(srcValue instanceof Long){
-					tmp2 = (Long)srcValue;
-				}else{
-					throw new IllegalAggregateFieldTypeException(srcValue.getClass().toString() + " type is not support. The source type must be Long or String");
-				}
-				setM.invoke(targetObj, tmp1.longValue()+tmp2.longValue());
-			}else if(targetValue instanceof Double){
-				Method setM = targetObj.getClass().getMethod("set"+fn, double.class);
-				Double tmp1 = (Double)targetValue;
-				String src = (String) srcValue;
-				Double tmp2 = Double.valueOf(src);
-				setM.invoke(targetObj, tmp1.doubleValue()+tmp2.doubleValue());
-			}else{
-				throw new IllegalAggregateFieldTypeException(targetValue.getClass().toString() + " type is not support. The target type must be long or double");
-			}
-		}catch(Exception ex){
-			LOG.error("Cannot do sum aggregation for field " + fieldName, ex);
-			throw ex;
-		}
-	}
-	
-	/**
-	 * count possible not only count for number of descendants but also count for not-null fields 
-	 * @param targetObj
-	 * @throws Exception
-	 */
-	private void count(AggregateAPIEntity targetObj) throws Exception{
-		targetObj.setNumTotalDescendants(targetObj.getNumTotalDescendants()+1);
-	}
+    public Aggregator(AggregateAPIEntityFactory factory, AggregateAPIEntity root, List<String> groupbys, boolean counting, List<String> sumFunctionFields) {
+        this.factory = factory;
+        this.root = root;
+        this.groupbys = groupbys;
+        this.sumFunctionFields = sumFunctionFields;
+        this.counting = counting;
+    }
+
+    /**
+     * this locate result can be cached? we don't need check if it's TaggedLogAPIEntity each time when iterating entities
+     * @param groupby
+     * @param obj
+     * @return
+     * @throws Exception
+     */
+    private String locateGroupbyField(String groupby, TaggedLogAPIEntity obj) {
+        if (groupby.equals(GROUPBY_ROOT_FIELD_NAME)) {
+            return GROUPBY_ROOT_FIELD_VALUE;
+        }
+        // check tag first
+        String tagv = obj.getTags().get(groupby);
+        if (tagv != null) {
+            return tagv;
+        }
+        // check against pojo, or qualifierValues
+        String fn = groupby.substring(0,1).toUpperCase() + groupby.substring(1, groupby.length());
+        try {
+            Method getM = obj.getClass().getMethod("get" + fn);
+            Object value = getM.invoke(obj);
+            return (String)value;
+        } catch (Exception ex) {
+            LOG.warn(groupby + " field is in neither tags nor fields, " + ex.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * accumulate a list of entities
+     * @param entities
+     * @throws Exception
+     */
+    public void accumulateAll(List<TaggedLogAPIEntity> entities) throws Exception {
+        for (TaggedLogAPIEntity entity : entities) {
+            accumulate(entity);
+        }
+    }
+
+    /**
+     * currently only group by tags
+     * groupbys' first item always is site, which is a reserved field
+     */
+    public void accumulate(TaggedLogAPIEntity entity) throws Exception {
+        AggregateAPIEntity current = root;
+        for (String groupby : groupbys) {
+            // TODO tagv is empty, so what to do? use a reserved field_name "unassigned" ?
+            // TODO we should support all Pojo with java bean style object
+            String tagv = locateGroupbyField(groupby, entity);
+            if (tagv == null || tagv.isEmpty()) {
+                tagv = UNASSIGNED_GROUPBY_ROOT_FIELD_NAME;
+            }
+            Map<String, AggregateAPIEntity> children = current.getEntityList();
+            if (children.get(tagv) == null) {
+                children.put(tagv, factory.create());
+                current.setNumDirectDescendants(current.getNumDirectDescendants() + 1);
+            }
+            AggregateAPIEntity child = children.get(tagv);
+            // go through all aggregate functions including count, summary etc.
+            if (counting) {
+                count(child);
+            }
+            for (String sumFunctionField : sumFunctionFields) {
+                sum(child, entity, sumFunctionField);
+            }
+
+            current = child;
+        }
+
+    }
+
+
+    /**
+     * use java bean specifications?
+     * reflection is not efficient, let us find out solutions
+     */
+    private void sum(Object targetObj, TaggedLogAPIEntity srcObj, String fieldName) throws Exception {
+        try {
+            String fn = fieldName.substring(0,1).toUpperCase() + fieldName.substring(1, fieldName.length());
+            Method srcGetMethod = srcObj.getClass().getMethod("get" + fn);
+            Object srcValue = srcGetMethod.invoke(srcObj);
+            if (srcValue == null) {
+                return;  // silently don't count this source object
+            }
+            Method targetGetMethod = targetObj.getClass().getMethod("get" + fn);
+            Object targetValue = targetGetMethod.invoke(targetObj);
+            if (targetValue instanceof Long) {
+                Method setM = targetObj.getClass().getMethod("set" + fn, long.class);
+                Long tmp1 = (Long)targetValue;
+                // TODO, now source object always have type "java.lang.String", later on we should support various type including integer type
+                Long tmp2 = null;
+                if (srcValue instanceof String) {
+                    tmp2 = Long.valueOf((String)srcValue);
+                } else if (srcValue instanceof Long) {
+                    tmp2 = (Long)srcValue;
+                } else {
+                    throw new IllegalAggregateFieldTypeException(srcValue.getClass().toString() + " type is not support. The source type must be Long or String");
+                }
+                setM.invoke(targetObj, tmp1.longValue() + tmp2.longValue());
+            } else if (targetValue instanceof Double) {
+                Method setM = targetObj.getClass().getMethod("set" + fn, double.class);
+                Double tmp1 = (Double)targetValue;
+                String src = (String) srcValue;
+                Double tmp2 = Double.valueOf(src);
+                setM.invoke(targetObj, tmp1.doubleValue() + tmp2.doubleValue());
+            } else {
+                throw new IllegalAggregateFieldTypeException(targetValue.getClass().toString() + " type is not support. The target type must be long or double");
+            }
+        } catch (Exception ex) {
+            LOG.error("Cannot do sum aggregation for field " + fieldName, ex);
+            throw ex;
+        }
+    }
+
+    /**
+     * count possible not only count for number of descendants but also count for not-null fields
+     * @param targetObj
+     * @throws Exception
+     */
+    private void count(AggregateAPIEntity targetObj) throws Exception {
+        targetObj.setNumTotalDescendants(targetObj.getNumTotalDescendants() + 1);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/BucketQuery.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/BucketQuery.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/BucketQuery.java
index a00c5ad..be2c636 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/BucketQuery.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/BucketQuery.java
@@ -24,61 +24,62 @@ import java.util.Map;
 import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
 
 public class BucketQuery {
-	public final static String UNASSIGNED_BUCKET = "unassigned"; 
-	private List<String> bucketFields;
-	private int limit;
-	private Map<String, Object> root = new HashMap<String, Object>();
-	
-	public BucketQuery(List<String> bucketFields, int limit){
-		this.bucketFields = bucketFields;
-		this.limit = limit;
-	}
-	
-	@SuppressWarnings("unchecked")
-	public void put(TaggedLogAPIEntity entity){
-		Map<String, Object> current = root;
-		int bucketCount = bucketFields.size();
-		if(bucketCount <= 0)
-			return; // silently return
-		int i = 0;
-		String bucketFieldValue = null;
-		for(; i<bucketCount; i++){
-			String bucketField = bucketFields.get(i);
-			bucketFieldValue = entity.getTags().get(bucketField);
-			if(bucketFieldValue == null || bucketFieldValue.isEmpty()){
-				bucketFieldValue = UNASSIGNED_BUCKET;
-			}
-			// for last bucket, bypass the following logic
-			if(i == bucketCount-1){
-				break;
-			}
-				
-			if(current.get(bucketFieldValue) == null){
-				current.put(bucketFieldValue, new HashMap<String, Object>());
-			}
-			// for the last level of bucket, it is not Map, instead it is List<TaggedLogAPIEntity> 
-			current = (Map<String, Object>)current.get(bucketFieldValue);
-		}
-		List<TaggedLogAPIEntity> bucketContent = (List<TaggedLogAPIEntity>)current.get(bucketFieldValue);
-		if(bucketContent == null){
-			bucketContent = new ArrayList<TaggedLogAPIEntity>();
-			current.put(bucketFieldValue, bucketContent);
-		}
-		
-		if(bucketContent.size() >= limit){
-			return;
-		}else{
-			bucketContent.add(entity);
-		}
-	}
-	
-	public void batchPut(List<TaggedLogAPIEntity> entities){
-		for(TaggedLogAPIEntity entity : entities){
-			put(entity);
-		}
-	}
-	
-	public Map<String, Object> get(){
-		return root;
-	}
+    public static final String UNASSIGNED_BUCKET = "unassigned";
+    private List<String> bucketFields;
+    private int limit;
+    private Map<String, Object> root = new HashMap<String, Object>();
+
+    public BucketQuery(List<String> bucketFields, int limit) {
+        this.bucketFields = bucketFields;
+        this.limit = limit;
+    }
+
+    @SuppressWarnings("unchecked")
+    public void put(TaggedLogAPIEntity entity) {
+        Map<String, Object> current = root;
+        int bucketCount = bucketFields.size();
+        if (bucketCount <= 0) {
+            return; // silently return
+        }
+        int i = 0;
+        String bucketFieldValue = null;
+        for (; i < bucketCount; i++) {
+            String bucketField = bucketFields.get(i);
+            bucketFieldValue = entity.getTags().get(bucketField);
+            if (bucketFieldValue == null || bucketFieldValue.isEmpty()) {
+                bucketFieldValue = UNASSIGNED_BUCKET;
+            }
+            // for last bucket, bypass the following logic
+            if (i == bucketCount - 1) {
+                break;
+            }
+
+            if (current.get(bucketFieldValue) == null) {
+                current.put(bucketFieldValue, new HashMap<String, Object>());
+            }
+            // for the last level of bucket, it is not Map, instead it is List<TaggedLogAPIEntity>
+            current = (Map<String, Object>)current.get(bucketFieldValue);
+        }
+        List<TaggedLogAPIEntity> bucketContent = (List<TaggedLogAPIEntity>)current.get(bucketFieldValue);
+        if (bucketContent == null) {
+            bucketContent = new ArrayList<TaggedLogAPIEntity>();
+            current.put(bucketFieldValue, bucketContent);
+        }
+
+        if (bucketContent.size() >= limit) {
+            return;
+        } else {
+            bucketContent.add(entity);
+        }
+    }
+
+    public void batchPut(List<TaggedLogAPIEntity> entities) {
+        for (TaggedLogAPIEntity entity : entities) {
+            put(entity);
+        }
+    }
+
+    public Map<String, Object> get() {
+        return root;
+    }
 }


[4/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestHBaseLogReader2.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestHBaseLogReader2.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestHBaseLogReader2.java
index 6406b13..5de8d87 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestHBaseLogReader2.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestHBaseLogReader2.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.eagle.query;;
+package org.apache.eagle.query;
 
 import org.apache.eagle.common.ByteUtil;
 import org.apache.eagle.common.DateTimeUtil;
@@ -34,121 +34,121 @@ import org.slf4j.LoggerFactory;
 import java.util.*;
 
 public class TestHBaseLogReader2 {
-	private final static Logger LOG = LoggerFactory.getLogger(TestHBaseLogReader2.class);
+    private static final Logger LOG = LoggerFactory.getLogger(TestHBaseLogReader2.class);
     private static EmbeddedHBase hbase = EmbeddedHBase.getInstance();
-	
-	@SuppressWarnings("serial")
-	@Test
-	public void testStartTimeInclusiveEndTimeExclusive() throws Exception {
-		EntityDefinition entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class);
-		hbase.createTable(entityDefinition.getTable(), entityDefinition.getColumnFamily());
-
-		EntityDefinitionManager.registerEntity(TestTimeSeriesAPIEntity.class);
-
-		final String cluster = "cluster1";
-		final String datacenter = "dc1";
-		String serviceName = "TestTimeSeriesAPIEntity";
-		GenericEntityWriter writer = new GenericEntityWriter(serviceName);
-		List<TestTimeSeriesAPIEntity> entities = new ArrayList<TestTimeSeriesAPIEntity>();
-		TestTimeSeriesAPIEntity entity = new TestTimeSeriesAPIEntity();
-		long timestamp1 = DateTimeUtil.humanDateToSeconds("2014-04-08 03:00:00")*1000;
-		LOG.info("First entity timestamp:" + timestamp1);
-		entity.setTimestamp(timestamp1);
-		entity.setTags(new HashMap<String, String>(){{
-			put("cluster", cluster);
-			put("datacenter", datacenter);
-		}});
-		entity.setField7("field7");
-		entities.add(entity);
-
-		entity = new TestTimeSeriesAPIEntity();
-		long timestamp2 = DateTimeUtil.humanDateToSeconds("2014-05-08 04:00:00")*1000;
-		LOG.info("Second entity timestamp:" + timestamp2);
-		entity.setTimestamp(timestamp2);
-		entity.setTags(new HashMap<String, String>(){{
-			put("cluster", cluster);
-			put("datacenter", datacenter);
-		}});
-		entity.setField7("field7_2");
-		entities.add(entity);
-		writer.write(entities);
-
-		// for timezone difference between UTC & localtime, enlarge the search range
-		long queryStartTimestamp = timestamp1 - DateTimeUtil.ONEDAY;
-		long queryEndTimestamp = timestamp1 + DateTimeUtil.ONEDAY;
-		LOG.info("Query start timestamp:" + queryStartTimestamp);
-		LOG.info("Query end  timestamp:" + queryEndTimestamp);
-
-		String format = "%s[@cluster=\"%s\" AND @datacenter=\"%s\"]{%s}";
-		String query = String.format(format, serviceName, cluster, datacenter, "@field7");
-		ListQueryCompiler comp = new ListQueryCompiler(query);
-		SearchCondition condition = new SearchCondition();
-		condition.setFilter(comp.filter());
-		condition.setQueryExpression(comp.getQueryExpression());
-		condition.setOutputFields(comp.outputFields());
-
-		final List<String[]> partitionValues = comp.getQueryPartitionValues();
-		if (partitionValues != null) {
-			condition.setPartitionValues(Arrays.asList(partitionValues.get(0)));
-		}
-
-		condition.setStartRowkey(null);
-		condition.setPageSize(Integer.MAX_VALUE);
-		condition.setStartTime(0);
-		condition.setEndTime(queryEndTimestamp);
-
-		GenericEntityBatchReader reader = new GenericEntityBatchReader(serviceName, condition);
-		List<TestTimeSeriesAPIEntity> list = reader.read();
-
-		Assert.assertEquals(1, list.size());
-		Assert.assertEquals(timestamp1, list.get(0).getTimestamp());
-		Assert.assertEquals("field7", list.get(0).getField7());
-
-		// for timezone difference between UTC & localtime, enlarge the search range
-		queryStartTimestamp = timestamp1 - DateTimeUtil.ONEDAY;
-		queryEndTimestamp = timestamp2 + DateTimeUtil.ONEDAY;  // eagle timestamp is rounded to seconds
-		condition.setStartTime(queryStartTimestamp);
-		condition.setEndTime(queryEndTimestamp);
-		reader = new GenericEntityBatchReader(serviceName, condition);
-		list = reader.read();
-		Assert.assertEquals(2, list.size());
-
-		queryStartTimestamp = timestamp1;
-		queryEndTimestamp = timestamp1;  // eagle timestamp is rounded to seconds
-		condition.setStartTime(queryStartTimestamp);
-		condition.setEndTime(queryEndTimestamp);
-		reader = new GenericEntityBatchReader(serviceName, condition);
-		list = reader.read();
-		Assert.assertEquals(0, list.size());
-		hbase.deleteTable(entityDefinition.getTable());
-
-	}
-	
-	@Test
-	public void testByteComparison(){
-		byte[] byte1 = new byte[]{-23, 12, 63};
-		byte[] byte2 = ByteUtil.concat(byte1, new byte[]{0});
-		Assert.assertTrue(Bytes.compareTo(byte1, byte2) < 0);
-		byte[] byte3 = ByteUtil.concat(byte1, new byte[]{127});
-		Assert.assertTrue(Bytes.compareTo(byte2, byte3) < 0);
-		byte[] byte4 = ByteUtil.concat(byte1, new byte[]{-128});
-		Assert.assertTrue(Bytes.compareTo(byte4, byte3) > 0);
-	}
-	
-	@Test
-	public void testMaxByteInBytesComparision(){
-		int max = -1000000;
-//		int maxb = -1000000;
-		System.out.println("Byte MaxValue: " + Byte.MAX_VALUE);
-		System.out.println("Byte MaxValue: " + Byte.MIN_VALUE);
-		for(int i=-128; i<128; i++){
-			byte b = (byte)i;
-			int tmp = b & 0xff;
-			max = Math.max(max, tmp);
-		}
-		System.out.println(max);
-		
-		byte b = -1;
-		System.out.println(b & 0xff);
-	}
+
+    @SuppressWarnings("serial")
+    @Test
+    public void testStartTimeInclusiveEndTimeExclusive() throws Exception {
+        EntityDefinition entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class);
+        hbase.createTable(entityDefinition.getTable(), entityDefinition.getColumnFamily());
+
+        EntityDefinitionManager.registerEntity(TestTimeSeriesAPIEntity.class);
+
+        final String cluster = "cluster1";
+        final String datacenter = "dc1";
+        String serviceName = "TestTimeSeriesAPIEntity";
+        GenericEntityWriter writer = new GenericEntityWriter(serviceName);
+        List<TestTimeSeriesAPIEntity> entities = new ArrayList<TestTimeSeriesAPIEntity>();
+        TestTimeSeriesAPIEntity entity = new TestTimeSeriesAPIEntity();
+        long timestamp1 = DateTimeUtil.humanDateToSeconds("2014-04-08 03:00:00")*1000;
+        LOG.info("First entity timestamp:" + timestamp1);
+        entity.setTimestamp(timestamp1);
+        entity.setTags(new HashMap<String, String>() {{
+            put("cluster", cluster);
+            put("datacenter", datacenter);
+        }});
+        entity.setField7("field7");
+        entities.add(entity);
+
+        entity = new TestTimeSeriesAPIEntity();
+        long timestamp2 = DateTimeUtil.humanDateToSeconds("2014-05-08 04:00:00")*1000;
+        LOG.info("Second entity timestamp:" + timestamp2);
+        entity.setTimestamp(timestamp2);
+        entity.setTags(new HashMap<String, String>() {{
+            put("cluster", cluster);
+            put("datacenter", datacenter);
+        }});
+        entity.setField7("field7_2");
+        entities.add(entity);
+        writer.write(entities);
+
+        // for timezone difference between UTC & localtime, enlarge the search range
+        long queryStartTimestamp = timestamp1 - DateTimeUtil.ONEDAY;
+        long queryEndTimestamp = timestamp1 + DateTimeUtil.ONEDAY;
+        LOG.info("Query start timestamp:" + queryStartTimestamp);
+        LOG.info("Query end  timestamp:" + queryEndTimestamp);
+
+        String format = "%s[@cluster =\"%s\" AND @datacenter=\"%s\"]{%s}";
+        String query = String.format(format, serviceName, cluster, datacenter, "@field7");
+        ListQueryCompiler comp = new ListQueryCompiler(query);
+        SearchCondition condition = new SearchCondition();
+        condition.setFilter(comp.filter());
+        condition.setQueryExpression(comp.getQueryExpression());
+        condition.setOutputFields(comp.outputFields());
+
+        final List<String[]> partitionValues = comp.getQueryPartitionValues();
+        if (partitionValues != null) {
+            condition.setPartitionValues(Arrays.asList(partitionValues.get(0)));
+        }
+
+        condition.setStartRowkey(null);
+        condition.setPageSize(Integer.MAX_VALUE);
+        condition.setStartTime(0);
+        condition.setEndTime(queryEndTimestamp);
+
+        GenericEntityBatchReader reader = new GenericEntityBatchReader(serviceName, condition);
+        List<TestTimeSeriesAPIEntity> list = reader.read();
+
+        Assert.assertEquals(1, list.size());
+        Assert.assertEquals(timestamp1, list.get(0).getTimestamp());
+        Assert.assertEquals("field7", list.get(0).getField7());
+
+        // for timezone difference between UTC & localtime, enlarge the search range
+        queryStartTimestamp = timestamp1 - DateTimeUtil.ONEDAY;
+        queryEndTimestamp = timestamp2 + DateTimeUtil.ONEDAY;  // eagle timestamp is rounded to seconds
+        condition.setStartTime(queryStartTimestamp);
+        condition.setEndTime(queryEndTimestamp);
+        reader = new GenericEntityBatchReader(serviceName, condition);
+        list = reader.read();
+        Assert.assertEquals(2, list.size());
+
+        queryStartTimestamp = timestamp1;
+        queryEndTimestamp = timestamp1;  // eagle timestamp is rounded to seconds
+        condition.setStartTime(queryStartTimestamp);
+        condition.setEndTime(queryEndTimestamp);
+        reader = new GenericEntityBatchReader(serviceName, condition);
+        list = reader.read();
+        Assert.assertEquals(0, list.size());
+        hbase.deleteTable(entityDefinition.getTable());
+
+    }
+
+    @Test
+    public void testByteComparison() {
+        byte[] byte1 = new byte[]{-23, 12, 63};
+        byte[] byte2 = ByteUtil.concat(byte1, new byte[]{0});
+        Assert.assertTrue(Bytes.compareTo(byte1, byte2) < 0);
+        byte[] byte3 = ByteUtil.concat(byte1, new byte[]{127});
+        Assert.assertTrue(Bytes.compareTo(byte2, byte3) < 0);
+        byte[] byte4 = ByteUtil.concat(byte1, new byte[]{-128});
+        Assert.assertTrue(Bytes.compareTo(byte4, byte3) > 0);
+    }
+
+    @Test
+    public void testMaxByteInBytesComparision() {
+        int max = -1000000;
+        //		int maxb = -1000000;
+        System.out.println("Byte MaxValue: " + Byte.MAX_VALUE);
+        System.out.println("Byte MaxValue: " + Byte.MIN_VALUE);
+        for (int i = -128; i < 128; i++) {
+            byte b = (byte)i;
+            int tmp = b & 0xff;
+            max = Math.max(max, tmp);
+        }
+        System.out.println(max);
+
+        byte b = -1;
+        System.out.println(b & 0xff);
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestListQueryCompiler.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestListQueryCompiler.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestListQueryCompiler.java
index 341c976..7aa72a9 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestListQueryCompiler.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/TestListQueryCompiler.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 /**
- * 
+ *
  */
 package org.apache.eagle.query;
 
@@ -38,206 +38,206 @@ import java.util.List;
  */
 public class TestListQueryCompiler {
 
-	private static final Logger LOG = LoggerFactory.getLogger(TestListQueryCompiler.class);
-	
-	@Before 
-	public void prepare() throws Exception{
-		String[] partitions =  new String[2];
-		partitions[0] = "cluster";
-		partitions[1] = "datacenter";
-		EntityDefinitionManager.registerEntity(TestLogAPIEntity.class);
-		EntityDefinition entityDef = EntityDefinitionManager.getEntityByServiceName("TestLogAPIEntity");
-		entityDef.setPartitions(partitions);
-		entityDef.setTimeSeries(true);
-	}
-	
-	 /**************************************************************************************************/
-	 /*********************************** Test Expression In List Query*********************************/
-	 /**************************************************************************************************/
-	
-	@Test
-	public void testListQueryWithoutExpression() throws Exception{	
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND @field5 > 0.05]{@cluster, @field1}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND @field5>0.05)");
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertTrue(aggFields == null);
-		List<String> outputFields = compiler.outputFields();
-		Assert.assertEquals(outputFields.size(), 2);
-		Assert.assertTrue(outputFields.contains("cluster"));
-		Assert.assertTrue(outputFields.contains("field1"));
-	}
-	
-	@Test
-	public void testListQueryWithExpressionEndWithNumberInFilter() throws Exception{	
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@field5 + @field6} > 0.05]{@cluster, @field1}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND field5 + field6>0.05)");
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertTrue(aggFields == null);
-		List<String> outputFields = compiler.outputFields();
-		Assert.assertEquals(outputFields.size(), 2);
-		Assert.assertTrue(outputFields.contains("cluster"));
-		Assert.assertTrue(outputFields.contains("field1"));
-	}
-	
-	@Test
-	public void testListQueryWithExpressionEndWithRPARENInFilter() throws Exception{	
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND (EXP{@field5 + @field6} > 0.05)]{@cluster, @field1}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		LOG.info(filter.toString());
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND field5 + field6>0.05)");
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertTrue(aggFields == null);
-		List<String> outputFields = compiler.outputFields();
-		Assert.assertEquals(outputFields.size(), 2);
-		Assert.assertTrue(outputFields.contains("cluster"));
-		Assert.assertTrue(outputFields.contains("field1"));
-		
-		query = "TestLogAPIEntity[(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND (EXP{@field5 + @field6} > 0.05))]{@cluster, @field1}";
-		compiler = new ListQueryCompiler(query, false);
-		filter = compiler.getQueryExpression();
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND field5 + field6>0.05)");
-		aggFields = compiler.aggregateFields();
-		Assert.assertTrue(aggFields == null);
-		outputFields = compiler.outputFields();
-		Assert.assertEquals(outputFields.size(), 2);
-		Assert.assertTrue(outputFields.contains("cluster"));
-		Assert.assertTrue(outputFields.contains("field1"));
-	}
-	
-	@Test
-	public void testListQueryWithExpressionEndWithRBRACEInFilter() throws Exception{			
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{0.05 + @c + @d}]{@cluster, EXP{@a + @b}}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>0.05 + c + d)");
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertTrue(aggFields == null);
-		List<String> outputFields = compiler.outputFields();
-//		Assert.assertEquals(outputFields.size(), 2);
-		Assert.assertTrue(outputFields.contains("cluster"));
-		Assert.assertTrue(outputFields.contains("EXP{a + b}"));
-	}
-	
-	/**************************************************************************************************/
-	/*********************************** Test Expression In Group By Query*********************************/	
-	/**************************************************************************************************/
-	
-	@Test
-	public void testGroupByQueryAggWithoutExpressionInAggFunc() throws Exception{
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d + 0.05}]<@cluster, @datacenter>{sum(@a), avg(@b)}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		LOG.info(filter.toString());
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d + 0.05)");
-		
-		List<String> groupByFields = compiler.groupbyFields();
-		Assert.assertEquals(groupByFields.size(), 2);		
-		Assert.assertTrue(groupByFields.contains("cluster"));
-		Assert.assertTrue(groupByFields.contains("datacenter"));
-		
-		List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
-		Assert.assertEquals(functions.size(), 2);		
-		Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
-		Assert.assertTrue(functions.contains(AggregateFunctionType.avg));
-	
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertEquals(aggFields.size(), 2);
-		Assert.assertTrue(aggFields.contains("a"));
-		Assert.assertTrue(aggFields.contains("b"));
-	}
-	
-	@Test
-	public void testGroupByQueryAggWithExpressionInAggFunc() throws Exception{
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d + 0.07}]<@cluster, @datacenter>{sum(EXP{@a+@b+20.0}), avg(EXP{(@a+@c + 2.5)/@d}), count}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		LOG.info(filter.toString());
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d + 0.07)");
-		
-		List<String> groupByFields = compiler.groupbyFields();
-		Assert.assertEquals(groupByFields.size(), 2);		
-		Assert.assertTrue(groupByFields.contains("cluster"));
-		Assert.assertTrue(groupByFields.contains("datacenter"));
-		
-		List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
-		Assert.assertEquals(functions.size(), 3);		
-		Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
-		Assert.assertTrue(functions.contains(AggregateFunctionType.avg));
-		Assert.assertTrue(functions.contains(AggregateFunctionType.count));
-				
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertEquals(aggFields.size(), 3);
-		Assert.assertTrue(aggFields.contains("EXP{a+b+20.0}"));
-		Assert.assertTrue(aggFields.contains("EXP{(a+c + 2.5)/d}"));
-		Assert.assertTrue(aggFields.contains("count"));
-	}
-	
-	/**************************************************************************************************/
-	/*********************************** Test Expression In Sort Query*********************************/	
-	/**************************************************************************************************/
-	
-	@Test
-	public void testSortQueryWithoutExpressionInSort() throws Exception{
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d}]<@cluster, @datacenter>"
-				+ "{sum(@a), count}.{sum(@a) asc}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		LOG.info(filter.toString());
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d)");
-		
-		List<String> groupByFields = compiler.groupbyFields();
-		Assert.assertEquals(groupByFields.size(), 2);		
-		Assert.assertTrue(groupByFields.contains("cluster"));
-		Assert.assertTrue(groupByFields.contains("datacenter"));
-		
-		List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
-		Assert.assertEquals(functions.size(), 2);		
-		Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
-		Assert.assertTrue(functions.contains(AggregateFunctionType.count));
-		
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertEquals(aggFields.size(), 2);
-		Assert.assertTrue(aggFields.contains("a"));
-		Assert.assertTrue(aggFields.contains("count"));
-		
-		List<String> sortFields = compiler.sortFields();
-		Assert.assertEquals(sortFields.size(), 1);
-		Assert.assertTrue(sortFields.contains("a"));
-	}
-	
-	@Test
-	public void testSortQuerySortWithExpressionInSort() throws Exception{
-		String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d + 0.05}]<@cluster, @datacenter>"
-				+ "{sum(EXP{@a+@b+0.07}), max(EXP{(@a+@c)/@d}), min(EXP{@a+@b})}.{sum(EXP{@a+@b+0.07}) asc}";
-		ListQueryCompiler compiler = new ListQueryCompiler(query, false);
-		ORExpression filter = compiler.getQueryExpression();
-		LOG.info(filter.toString());
-		Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d + 0.05)");
-		
-		List<String> groupByFields = compiler.groupbyFields();
-		Assert.assertEquals(groupByFields.size(), 2);		
-		Assert.assertTrue(groupByFields.contains("cluster"));
-		Assert.assertTrue(groupByFields.contains("datacenter"));
-		
-		List<String> aggFields = compiler.aggregateFields();
-		Assert.assertEquals(aggFields.size(), 3);
-		Assert.assertTrue(aggFields.contains("EXP{a+b+0.07}"));
-		Assert.assertTrue(aggFields.contains("EXP{(a+c)/d}"));
-		Assert.assertTrue(aggFields.contains("EXP{a+b}"));
-		
-		List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
-		Assert.assertEquals(functions.size(), 3);		
-		Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
-		Assert.assertTrue(functions.contains(AggregateFunctionType.max));
-		Assert.assertTrue(functions.contains(AggregateFunctionType.min));
-		
-		List<String> sortFields = compiler.sortFields();
-		Assert.assertEquals(sortFields.size(), 1);
-		Assert.assertTrue(sortFields.contains("EXP{a+b+0.07}"));
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(TestListQueryCompiler.class);
+
+    @Before
+    public void prepare() throws Exception{
+        String[] partitions =  new String[2];
+        partitions[0] = "cluster";
+        partitions[1] = "datacenter";
+        EntityDefinitionManager.registerEntity(TestLogAPIEntity.class);
+        EntityDefinition entityDef = EntityDefinitionManager.getEntityByServiceName("TestLogAPIEntity");
+        entityDef.setPartitions(partitions);
+        entityDef.setTimeSeries(true);
+    }
+
+    /**************************************************************************************************/
+    /*********************************** Test Expression In List Query*********************************/
+    /**************************************************************************************************/
+
+    @Test
+    public void testListQueryWithoutExpression() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND @field5 > 0.05]{@cluster, @field1}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND @field5>0.05)");
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertTrue(aggFields == null);
+        List<String> outputFields = compiler.outputFields();
+        Assert.assertEquals(outputFields.size(), 2);
+        Assert.assertTrue(outputFields.contains("cluster"));
+        Assert.assertTrue(outputFields.contains("field1"));
+    }
+
+    @Test
+    public void testListQueryWithExpressionEndWithNumberInFilter() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@field5 + @field6} > 0.05]{@cluster, @field1}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND field5 + field6>0.05)");
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertTrue(aggFields == null);
+        List<String> outputFields = compiler.outputFields();
+        Assert.assertEquals(outputFields.size(), 2);
+        Assert.assertTrue(outputFields.contains("cluster"));
+        Assert.assertTrue(outputFields.contains("field1"));
+    }
+
+    @Test
+    public void testListQueryWithExpressionEndWithRPARENInFilter() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND (EXP{@field5 + @field6} > 0.05)]{@cluster, @field1}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        LOG.info(filter.toString());
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND field5 + field6>0.05)");
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertTrue(aggFields == null);
+        List<String> outputFields = compiler.outputFields();
+        Assert.assertEquals(outputFields.size(), 2);
+        Assert.assertTrue(outputFields.contains("cluster"));
+        Assert.assertTrue(outputFields.contains("field1"));
+
+        query = "TestLogAPIEntity[(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND (EXP{@field5 + @field6} > 0.05))]{@cluster, @field1}";
+        compiler = new ListQueryCompiler(query, false);
+        filter = compiler.getQueryExpression();
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND field5 + field6>0.05)");
+        aggFields = compiler.aggregateFields();
+        Assert.assertTrue(aggFields == null);
+        outputFields = compiler.outputFields();
+        Assert.assertEquals(outputFields.size(), 2);
+        Assert.assertTrue(outputFields.contains("cluster"));
+        Assert.assertTrue(outputFields.contains("field1"));
+    }
+
+    @Test
+    public void testListQueryWithExpressionEndWithRBRACEInFilter() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{0.05 + @c + @d}]{@cluster, EXP{@a + @b}}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>0.05 + c + d)");
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertTrue(aggFields == null);
+        List<String> outputFields = compiler.outputFields();
+        //		Assert.assertEquals(outputFields.size(), 2);
+        Assert.assertTrue(outputFields.contains("cluster"));
+        Assert.assertTrue(outputFields.contains("EXP{a + b}"));
+    }
+
+    /**************************************************************************************************/
+    /*********************************** Test Expression In Group By Query*********************************/
+    /**************************************************************************************************/
+
+    @Test
+    public void testGroupByQueryAggWithoutExpressionInAggFunc() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d + 0.05}]<@cluster, @datacenter>{sum(@a), avg(@b)}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        LOG.info(filter.toString());
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d + 0.05)");
+
+        List<String> groupByFields = compiler.groupbyFields();
+        Assert.assertEquals(groupByFields.size(), 2);
+        Assert.assertTrue(groupByFields.contains("cluster"));
+        Assert.assertTrue(groupByFields.contains("datacenter"));
+
+        List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
+        Assert.assertEquals(functions.size(), 2);
+        Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
+        Assert.assertTrue(functions.contains(AggregateFunctionType.avg));
+
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertEquals(aggFields.size(), 2);
+        Assert.assertTrue(aggFields.contains("a"));
+        Assert.assertTrue(aggFields.contains("b"));
+    }
+
+    @Test
+    public void testGroupByQueryAggWithExpressionInAggFunc() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d + 0.07}]<@cluster, @datacenter>{sum(EXP{@a+@b+20.0}), avg(EXP{(@a+@c + 2.5)/@d}), count}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        LOG.info(filter.toString());
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d + 0.07)");
+
+        List<String> groupByFields = compiler.groupbyFields();
+        Assert.assertEquals(groupByFields.size(), 2);
+        Assert.assertTrue(groupByFields.contains("cluster"));
+        Assert.assertTrue(groupByFields.contains("datacenter"));
+
+        List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
+        Assert.assertEquals(functions.size(), 3);
+        Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
+        Assert.assertTrue(functions.contains(AggregateFunctionType.avg));
+        Assert.assertTrue(functions.contains(AggregateFunctionType.count));
+
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertEquals(aggFields.size(), 3);
+        Assert.assertTrue(aggFields.contains("EXP{a+b+20.0}"));
+        Assert.assertTrue(aggFields.contains("EXP{(a+c + 2.5)/d}"));
+        Assert.assertTrue(aggFields.contains("count"));
+    }
+
+    /**************************************************************************************************/
+    /*********************************** Test Expression In Sort Query*********************************/
+    /**************************************************************************************************/
+
+    @Test
+    public void testSortQueryWithoutExpressionInSort() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d}]<@cluster, @datacenter>"
+            + "{sum(@a), count}.{sum(@a) asc}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        LOG.info(filter.toString());
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d)");
+
+        List<String> groupByFields = compiler.groupbyFields();
+        Assert.assertEquals(groupByFields.size(), 2);
+        Assert.assertTrue(groupByFields.contains("cluster"));
+        Assert.assertTrue(groupByFields.contains("datacenter"));
+
+        List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
+        Assert.assertEquals(functions.size(), 2);
+        Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
+        Assert.assertTrue(functions.contains(AggregateFunctionType.count));
+
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertEquals(aggFields.size(), 2);
+        Assert.assertTrue(aggFields.contains("a"));
+        Assert.assertTrue(aggFields.contains("count"));
+
+        List<String> sortFields = compiler.sortFields();
+        Assert.assertEquals(sortFields.size(), 1);
+        Assert.assertTrue(sortFields.contains("a"));
+    }
+
+    @Test
+    public void testSortQuerySortWithExpressionInSort() throws Exception{
+        String query = "TestLogAPIEntity[@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND EXP{@a + @b} > EXP{@c + @d} AND EXP{@a + @c} < EXP{@b + @d + 0.05}]<@cluster, @datacenter>"
+            + "{sum(EXP{@a+@b+0.07}), max(EXP{(@a+@c)/@d}), min(EXP{@a+@b})}.{sum(EXP{@a+@b+0.07}) asc}";
+        ListQueryCompiler compiler = new ListQueryCompiler(query, false);
+        ORExpression filter = compiler.getQueryExpression();
+        LOG.info(filter.toString());
+        Assert.assertEquals(filter.toString(), "(@cluster=\"cluster\" AND @datacenter=\"datacenter\" AND a + b>c + d AND a + c<b + d + 0.05)");
+
+        List<String> groupByFields = compiler.groupbyFields();
+        Assert.assertEquals(groupByFields.size(), 2);
+        Assert.assertTrue(groupByFields.contains("cluster"));
+        Assert.assertTrue(groupByFields.contains("datacenter"));
+
+        List<String> aggFields = compiler.aggregateFields();
+        Assert.assertEquals(aggFields.size(), 3);
+        Assert.assertTrue(aggFields.contains("EXP{a+b+0.07}"));
+        Assert.assertTrue(aggFields.contains("EXP{(a+c)/d}"));
+        Assert.assertTrue(aggFields.contains("EXP{a+b}"));
+
+        List<AggregateFunctionType> functions = compiler.aggregateFunctionTypes();
+        Assert.assertEquals(functions.size(), 3);
+        Assert.assertTrue(functions.contains(AggregateFunctionType.sum));
+        Assert.assertTrue(functions.contains(AggregateFunctionType.max));
+        Assert.assertTrue(functions.contains(AggregateFunctionType.min));
+
+        List<String> sortFields = compiler.sortFields();
+        Assert.assertEquals(sortFields.size(), 1);
+        Assert.assertTrue(sortFields.contains("EXP{a+b+0.07}"));
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestGroupbyKey.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestGroupbyKey.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestGroupbyKey.java
index 2683220..9371656 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestGroupbyKey.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestGroupbyKey.java
@@ -20,54 +20,55 @@ import org.junit.Assert;
 import org.junit.Test;
 
 public class TestGroupbyKey {
-	@Test
-	public void testGroupbyKey(){
-		GroupbyKey key1 = new GroupbyKey();
-		Assert.assertEquals(0, key1.getValue().size());
-		
-		key1.addValue(new byte[]{1, 3, 5});
-		Assert.assertEquals(1, key1.getValue().size());
-		
-		key1.clear();
-		Assert.assertEquals(0, key1.getValue().size());
-		
-		key1.addValue(new byte[]{1, 3, 5});
-		GroupbyKey key2 = new GroupbyKey();
-		key2.addValue(new byte[]{1, 3, 5});
-		Assert.assertEquals(key1, key2);
-		
-		GroupbyKey key3 = new GroupbyKey(key1);
-		Assert.assertEquals(key1, key3);
-		Assert.assertEquals(key2, key3);
-	}
-	
-	@Test
-	public void testGroupbyKeyComparator(){
-		GroupbyKeyComparator comparator = new GroupbyKeyComparator();
-		GroupbyKey key1 = new GroupbyKey();
-		key1.addValue("hello".getBytes());
-		GroupbyKey key2 = new GroupbyKey();
-		key2.addValue("world".getBytes());
-		int r = comparator.compare(key1, key2);
-		Assert.assertTrue(r < 0);
-		
-		key2.clear();
-		key2.addValue("friend".getBytes());
-		r = comparator.compare(key1, key2);
-		Assert.assertTrue(r > 0);
-		
-		key2.clear();
-		key2.addValue("hello".getBytes());
-		r = comparator.compare(key1, key2);
-		Assert.assertTrue(r == 0);
-		
-		key1.clear();
-		key2.clear();
-		key1.addValue("hello".getBytes());
-		key1.addValue("tom".getBytes());
-		key2.addValue("hello".getBytes());
-		key2.addValue("jackie".getBytes());
-		r = comparator.compare(key1, key2);
-		Assert.assertTrue(r > 0);
-	}
+
+    @Test
+    public void testGroupbyKey() {
+        GroupbyKey key1 = new GroupbyKey();
+        Assert.assertEquals(0, key1.getValue().size());
+
+        key1.addValue(new byte[]{1, 3, 5});
+        Assert.assertEquals(1, key1.getValue().size());
+
+        key1.clear();
+        Assert.assertEquals(0, key1.getValue().size());
+
+        key1.addValue(new byte[]{1, 3, 5});
+        GroupbyKey key2 = new GroupbyKey();
+        key2.addValue(new byte[]{1, 3, 5});
+        Assert.assertEquals(key1, key2);
+
+        GroupbyKey key3 = new GroupbyKey(key1);
+        Assert.assertEquals(key1, key3);
+        Assert.assertEquals(key2, key3);
+    }
+
+    @Test
+    public void testGroupbyKeyComparator() {
+        GroupbyKeyComparator comparator = new GroupbyKeyComparator();
+        GroupbyKey key1 = new GroupbyKey();
+        key1.addValue("hello".getBytes());
+        GroupbyKey key2 = new GroupbyKey();
+        key2.addValue("world".getBytes());
+        int r = comparator.compare(key1, key2);
+        Assert.assertTrue(r < 0);
+
+        key2.clear();
+        key2.addValue("friend".getBytes());
+        r = comparator.compare(key1, key2);
+        Assert.assertTrue(r > 0);
+
+        key2.clear();
+        key2.addValue("hello".getBytes());
+        r = comparator.compare(key1, key2);
+        Assert.assertTrue(r == 0);
+
+        key1.clear();
+        key2.clear();
+        key1.addValue("hello".getBytes());
+        key1.addValue("tom".getBytes());
+        key2.addValue("hello".getBytes());
+        key2.addValue("jackie".getBytes());
+        r = comparator.compare(key1, key2);
+        Assert.assertTrue(r > 0);
+    }
 }


[2/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery2.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery2.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery2.java
index 2ecb9d0..e6358fd 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery2.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery2.java
@@ -29,132 +29,132 @@ import java.util.List;
 import java.util.Map;
 
 public class TestBucketQuery2 {
-	private static class SampleTaggedLogAPIEntity extends TaggedLogAPIEntity{
-		private String description;
-
-		@SuppressWarnings("unused")
-		public String getDescription() {
-			return description;
-		}
-
-		public void setDescription(String description) {
-			this.description = description;
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-//	@Test
-	public void testBucketQuery(){
-		SampleTaggedLogAPIEntity e1 = new SampleTaggedLogAPIEntity();
-		e1.setTags(new HashMap<String, String>());
-		e1.getTags().put("cluster", "cluster1");
-		e1.getTags().put("rack", "rack123");
-		e1.setDescription("this is description 1");
-		
-		SampleTaggedLogAPIEntity e2 = new SampleTaggedLogAPIEntity();
-		e2.setTags(new HashMap<String, String>());
-		e2.getTags().put("cluster", "cluster1");
-		e2.getTags().put("rack", "rack123");
-		e2.setDescription("this is description 2");
-		
-		List<String> bucketFields = new ArrayList<String>();
-		bucketFields.add("cluster");
-		int limit = 1;
-		
-		BucketQuery query1 = new BucketQuery(bucketFields, limit);
-		query1.put(e1);
-		query1.put(e2);
-		
-		Map<String, Object> map = query1.get();
-		
-		List<TaggedLogAPIEntity> o = (List<TaggedLogAPIEntity>)map.get("cluster1");
-		Assert.assertEquals(limit, o.size());
-		
-		JsonFactory factory = new JsonFactory();
-		ObjectMapper mapper = new ObjectMapper(factory);
-		try{
-			String result = mapper.writeValueAsString(map);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-		
-		limit = 2;
-		BucketQuery query2 = new BucketQuery(bucketFields, limit);
-		query2.put(e1);
-		query2.put(e2);
-		Map<String, Object> map2 = query2.get();
-		o = (List<TaggedLogAPIEntity>)map2.get("cluster1");
-		try{
-			String result = mapper.writeValueAsString(map2);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-		Assert.assertEquals(limit, o.size());
-		
-		
-		SampleTaggedLogAPIEntity e3 = new SampleTaggedLogAPIEntity();
-		e3.setTags(new HashMap<String, String>());
-		e3.getTags().put("cluster", "cluster1");
-		e3.getTags().put("rack", "rack124");
-		e3.setDescription("this is description 3");
-		bucketFields.add("rack");
-		limit = 2;
-		BucketQuery query3 = new BucketQuery(bucketFields, limit);
-		query3.put(e1);
-		query3.put(e2);
-		query3.put(e3);
-		Map<String, Object> map3 = query3.get();
-		Map<String, Object> o3 = (Map<String, Object>)map3.get("cluster1");
-		List<TaggedLogAPIEntity> o4 = (List<TaggedLogAPIEntity>)o3.get("rack124");
-		Assert.assertEquals(1, o4.size());
-		List<TaggedLogAPIEntity> o5 = (List<TaggedLogAPIEntity>)o3.get("rack123");
-		Assert.assertEquals(o5.size(), 2);
-		
-		try{
-			String result = mapper.writeValueAsString(map3);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-		
-		
-		SampleTaggedLogAPIEntity e4 = new SampleTaggedLogAPIEntity();
-		e4.setTags(new HashMap<String, String>());
-		e4.getTags().put("cluster", "cluster1");
-		// rack is set to null
-//		e4.getTags().put("rack", "rack124");
-		e4.setDescription("this is description 3");
-		limit = 2;
-		BucketQuery query4 = new BucketQuery(bucketFields, limit);
-		query4.put(e1);
-		query4.put(e2);
-		query4.put(e3);
-		query4.put(e4);
-		Map<String, Object> map4 = query4.get();
-		Map<String, Object> o6 = (Map<String, Object>)map4.get("cluster1");
-		List<TaggedLogAPIEntity> o7 = (List<TaggedLogAPIEntity>)o6.get("rack124");
-		Assert.assertEquals(1, o7.size());
-		List<TaggedLogAPIEntity> o8 = (List<TaggedLogAPIEntity>)o6.get("rack123");
-		Assert.assertEquals(o8.size(), 2);
-		List<TaggedLogAPIEntity> o9 = (List<TaggedLogAPIEntity>)o6.get("unassigned");
-		Assert.assertEquals(o9.size(), 1);
-		
-		try{
-			String result = mapper.writeValueAsString(map4);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-	}
-
-	@Test
-	public void test() {
-
-	}
+    private static class SampleTaggedLogAPIEntity extends TaggedLogAPIEntity {
+        private String description;
+
+        @SuppressWarnings("unused")
+        public String getDescription() {
+            return description;
+        }
+
+        public void setDescription(String description) {
+            this.description = description;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    //	@Test
+    public void testBucketQuery() {
+        SampleTaggedLogAPIEntity e1 = new SampleTaggedLogAPIEntity();
+        e1.setTags(new HashMap<String, String>());
+        e1.getTags().put("cluster", "cluster1");
+        e1.getTags().put("rack", "rack123");
+        e1.setDescription("this is description 1");
+
+        SampleTaggedLogAPIEntity e2 = new SampleTaggedLogAPIEntity();
+        e2.setTags(new HashMap<String, String>());
+        e2.getTags().put("cluster", "cluster1");
+        e2.getTags().put("rack", "rack123");
+        e2.setDescription("this is description 2");
+
+        List<String> bucketFields = new ArrayList<String>();
+        bucketFields.add("cluster");
+        int limit = 1;
+
+        BucketQuery query1 = new BucketQuery(bucketFields, limit);
+        query1.put(e1);
+        query1.put(e2);
+
+        Map<String, Object> map = query1.get();
+
+        List<TaggedLogAPIEntity> o = (List<TaggedLogAPIEntity>)map.get("cluster1");
+        Assert.assertEquals(limit, o.size());
+
+        JsonFactory factory = new JsonFactory();
+        ObjectMapper mapper = new ObjectMapper(factory);
+        try {
+            String result = mapper.writeValueAsString(map);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+
+        limit = 2;
+        BucketQuery query2 = new BucketQuery(bucketFields, limit);
+        query2.put(e1);
+        query2.put(e2);
+        Map<String, Object> map2 = query2.get();
+        o = (List<TaggedLogAPIEntity>)map2.get("cluster1");
+        try {
+            String result = mapper.writeValueAsString(map2);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+        Assert.assertEquals(limit, o.size());
+
+
+        SampleTaggedLogAPIEntity e3 = new SampleTaggedLogAPIEntity();
+        e3.setTags(new HashMap<String, String>());
+        e3.getTags().put("cluster", "cluster1");
+        e3.getTags().put("rack", "rack124");
+        e3.setDescription("this is description 3");
+        bucketFields.add("rack");
+        limit = 2;
+        BucketQuery query3 = new BucketQuery(bucketFields, limit);
+        query3.put(e1);
+        query3.put(e2);
+        query3.put(e3);
+        Map<String, Object> map3 = query3.get();
+        Map<String, Object> o3 = (Map<String, Object>)map3.get("cluster1");
+        List<TaggedLogAPIEntity> o4 = (List<TaggedLogAPIEntity>)o3.get("rack124");
+        Assert.assertEquals(1, o4.size());
+        List<TaggedLogAPIEntity> o5 = (List<TaggedLogAPIEntity>)o3.get("rack123");
+        Assert.assertEquals(o5.size(), 2);
+
+        try {
+            String result = mapper.writeValueAsString(map3);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+
+
+        SampleTaggedLogAPIEntity e4 = new SampleTaggedLogAPIEntity();
+        e4.setTags(new HashMap<String, String>());
+        e4.getTags().put("cluster", "cluster1");
+        // rack is set to null
+        //		e4.getTags().put("rack", "rack124");
+        e4.setDescription("this is description 3");
+        limit = 2;
+        BucketQuery query4 = new BucketQuery(bucketFields, limit);
+        query4.put(e1);
+        query4.put(e2);
+        query4.put(e3);
+        query4.put(e4);
+        Map<String, Object> map4 = query4.get();
+        Map<String, Object> o6 = (Map<String, Object>)map4.get("cluster1");
+        List<TaggedLogAPIEntity> o7 = (List<TaggedLogAPIEntity>)o6.get("rack124");
+        Assert.assertEquals(1, o7.size());
+        List<TaggedLogAPIEntity> o8 = (List<TaggedLogAPIEntity>)o6.get("rack123");
+        Assert.assertEquals(o8.size(), 2);
+        List<TaggedLogAPIEntity> o9 = (List<TaggedLogAPIEntity>)o6.get("unassigned");
+        Assert.assertEquals(o9.size(), 1);
+
+        try {
+            String result = mapper.writeValueAsString(map4);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+    }
+
+    @Test
+    public void test() {
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestFlatAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestFlatAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestFlatAggregator.java
index b6b9439..037e26c 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestFlatAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestFlatAggregator.java
@@ -32,368 +32,382 @@ import org.slf4j.LoggerFactory;
 import org.apache.eagle.log.entity.test.TestEntity;
 
 public class TestFlatAggregator {
-	private static final Logger LOG = LoggerFactory.getLogger(TestFlatAggregator.class);
-	@Test
-	public void testCounting(){
-		
-	}
-	
-	@Test
-	public void testSummary(){
-		
-	}
-	
-	@Test
-	public void testAverage(){
-		
-	}
-	
-	@Test
-	public void testIterativeAggregation(){
-		
-	}
-	
-	@SuppressWarnings("serial")
-	private TestEntity createEntity(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters){
-		TestEntity entity = new TestEntity();
-		Map<String, String> tags = new HashMap<String, String>(){{
-			put("cluster", cluster);
-			put("datacenter", datacenter);
-			put("rack", rack);
-		}}; 
-		entity.setTags(tags);
-		entity.setNumHosts(numHosts);
-		entity.setNumClusters(numClusters);
-		return entity;
-	}
-
-	@Test
-	public void testZeroGroupbyFieldSingleFunctionForSummary(){
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		
-		FlatAggregator agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+
-					entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+
-					entities[2].getNumClusters()+entities[3].getNumClusters()+entities[4].getNumClusters()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(5), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testSingleGroupbyFieldSingleFunctionForSummary(){
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc2", "rack126", 15, 2);
-		
-		FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts())+entities[3].getNumHosts(), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(entities[4].getNumHosts()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumClusters()+entities[4].getNumClusters()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters())+entities[3].getNumClusters(), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(entities[4].getNumClusters()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	
-	@Test
-	public void testSingleGroupbyFieldSingleFunctionForCount(){
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc2", "rack126", 15, 2);
-		
-		FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(3), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(2), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(1), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testMultipleFieldsSingleFunctionForSummary(){
-		TestEntity[] entities = new TestEntity[6];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		entities[5] = createEntity("cluster2", null, "rack126", 1, 3);
-		
-		FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(3, result.size());
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(entities[5].getNumHosts()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(5, result.size());
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(entities[3].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(entities[5].getNumHosts()), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testMultipleFieldsSingleFunctionForCount(){
-		TestEntity[] entities = new TestEntity[6];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		entities[5] = createEntity("cluster2", null, "rack126", 1, 3);
-		
-		FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(3, result.size());
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), (double)(3), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(2), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(1), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(5, result.size());
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), (double)(2), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(1), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testSingleGroupbyFieldMultipleFunctions(){
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		
-		FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count), 
-				Arrays.asList("numHosts", "*"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(1), (double)(3), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(1), (double)(2), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum), Arrays.asList("*", "numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(5), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts())+entities[4].getNumHosts(), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum, AggregateFunctionType.sum), 
-				Arrays.asList("*", "numHosts", "numClusters"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(5), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts())+entities[4].getNumHosts(), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(2), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()+entities[3].getNumClusters())+entities[4].getNumClusters(), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testMultipleGroupbyFieldsMultipleFunctions(){
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		
-		FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "rack"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count), 
-				Arrays.asList("numHosts", "*"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 4);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(1), (double)(2), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(0), (double)(entities[2].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(1), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(0), (double)(entities[3].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(1), (double)(1), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(0), (double)(entities[4].getNumHosts()), 0.001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(1), (double)(1), 0.001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(TestFlatAggregator.class);
+    @Test
+    public void testCounting() {
+
+    }
+
+    @Test
+    public void testSummary() {
+
+    }
+
+    @Test
+    public void testAverage() {
+
+    }
+
+    @Test
+    public void testIterativeAggregation() {
+
+    }
+
+    @SuppressWarnings("serial")
+    private TestEntity createEntity(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters) {
+        TestEntity entity = new TestEntity();
+        Map<String, String> tags = new HashMap<String, String>() {{
+            put("cluster", cluster);
+            put("datacenter", datacenter);
+            put("rack", rack);
+        }};
+        entity.setTags(tags);
+        entity.setNumHosts(numHosts);
+        entity.setNumClusters(numClusters);
+        return entity;
+    }
+
+    @Test
+    public void testZeroGroupbyFieldSingleFunctionForSummary() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+
+        FlatAggregator agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+            Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(entities[0].getNumHosts() + entities[1].getNumHosts()+
+                entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+            Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(entities[0].getNumClusters() + entities[1].getNumClusters() +
+                entities[2].getNumClusters() + entities[3].getNumClusters() + entities[4].getNumClusters()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+            Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(5), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testSingleGroupbyFieldSingleFunctionForSummary() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc2", "rack126", 15, 2);
+
+        FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0),
+                                (double)(entities[0].getNumHosts() + entities[1].getNumHosts() + entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumHosts() + entities[4].getNumHosts()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0),
+                                (double)(entities[0].getNumHosts() + entities[1].getNumHosts() + entities[2].getNumHosts()) + entities[3].getNumHosts(), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(entities[4].getNumHosts()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0),
+                                (double)(entities[0].getNumClusters() + entities[1].getNumClusters() + entities[2].getNumClusters()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumClusters() + entities[4].getNumClusters()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0),
+                                (double)(entities[0].getNumClusters() + entities[1].getNumClusters() + entities[2].getNumClusters()) + entities[3].getNumClusters(), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(entities[4].getNumClusters()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+
+    @Test
+    public void testSingleGroupbyFieldSingleFunctionForCount() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc2", "rack126", 15, 2);
+
+        FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(3), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(2), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(1), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testMultipleFieldsSingleFunctionForSummary() {
+        TestEntity[] entities = new TestEntity[6];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+        entities[5] = createEntity("cluster2", null, "rack126", 1, 3);
+
+        FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(3, result.size());
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0),
+                                (double)(entities[0].getNumHosts() + entities[1].getNumHosts() + entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(entities[3].getNumHosts() + entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(entities[5].getNumHosts()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(5, result.size());
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0),
+                                (double)(entities[0].getNumHosts() + entities[1].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(entities[3].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(entities[5].getNumHosts()), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testMultipleFieldsSingleFunctionForCount() {
+        TestEntity[] entities = new TestEntity[6];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+        entities[5] = createEntity("cluster2", null, "rack126", 1, 3);
+
+        FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(3, result.size());
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), (double)(3), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(2), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(1), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(5, result.size());
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), (double)(2), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(1), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testSingleGroupbyFieldMultipleFunctions() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+
+        FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
+                                                Arrays.asList("numHosts", "*"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0),
+                                (double)(entities[0].getNumHosts() + entities[1].getNumHosts() + entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(1), (double)(3), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumHosts() + entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(1), (double)(2), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum),
+                                 Arrays.asList("*", "numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(5), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1),
+                                (double)(entities[0].getNumHosts() + entities[1].getNumHosts() + entities[2].getNumHosts()
+                                    + entities[3].getNumHosts()) + entities[4].getNumHosts(), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum, AggregateFunctionType.sum),
+                                 Arrays.asList("*", "numHosts", "numClusters"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(5), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1),
+                                (double)(entities[0].getNumHosts() + entities[1].getNumHosts() + entities[2].getNumHosts()
+                                    + entities[3].getNumHosts()) + entities[4].getNumHosts(), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(2),
+                                (double)(entities[0].getNumClusters() + entities[1].getNumClusters() + entities[2].getNumClusters()
+                                    + entities[3].getNumClusters()) + entities[4].getNumClusters(), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testMultipleGroupbyFieldsMultipleFunctions() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+
+        FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "rack"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
+                                                Arrays.asList("numHosts", "*"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 4);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(1), (double)(2), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(0), (double)(entities[2].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(1), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(0), (double)(entities[3].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(1), (double)(1), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(0), (double)(entities[4].getNumHosts()), 0.001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(1), (double)(1), 0.001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestGroupbyFieldComparator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestGroupbyFieldComparator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestGroupbyFieldComparator.java
index 5fec950..2643d98 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestGroupbyFieldComparator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestGroupbyFieldComparator.java
@@ -24,12 +24,13 @@ import org.junit.Test;
 
 
 public class TestGroupbyFieldComparator {
-	@Test
-	public void testStringListCompare(){
-		GroupbyFieldsComparator c = new GroupbyFieldsComparator();
-		Assert.assertTrue(c.compare(Arrays.asList("ab"), Arrays.asList("ac"))<0);
-		Assert.assertTrue(c.compare(Arrays.asList("xy"), Arrays.asList("cd"))>0);
-		Assert.assertTrue(c.compare(Arrays.asList("xy"), Arrays.asList("xy"))==0);
-		Assert.assertTrue(c.compare(Arrays.asList("xy", "ab"), Arrays.asList("xy", "ac"))<0);
-	}
+
+    @Test
+    public void testStringListCompare() {
+        GroupbyFieldsComparator c = new GroupbyFieldsComparator();
+        Assert.assertTrue(c.compare(Arrays.asList("ab"), Arrays.asList("ac")) < 0);
+        Assert.assertTrue(c.compare(Arrays.asList("xy"), Arrays.asList("cd")) > 0);
+        Assert.assertTrue(c.compare(Arrays.asList("xy"), Arrays.asList("xy")) == 0);
+        Assert.assertTrue(c.compare(Arrays.asList("xy", "ab"), Arrays.asList("xy", "ac")) < 0);
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestHierarchicalAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestHierarchicalAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestHierarchicalAggregator.java
index b6c9212..56f70e7 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestHierarchicalAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestHierarchicalAggregator.java
@@ -40,292 +40,292 @@ import org.apache.eagle.log.entity.test.TestEntity;
 
 
 public class TestHierarchicalAggregator {
-private final static Logger LOG = LoggerFactory.getLogger(TestHierarchicalAggregator.class);
+    private static final Logger LOG = LoggerFactory.getLogger(TestHierarchicalAggregator.class);
 
-	@SuppressWarnings("serial")
-	private TestEntity createEntity(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters){
-		TestEntity entity = new TestEntity();
-		Map<String, String> tags = new HashMap<String, String>(){{
-			put("cluster", cluster);
-			put("datacenter", datacenter);
-			put("rack", rack);
-		}}; 
-		entity.setTags(tags);
-		entity.setNumHosts(numHosts);
-		entity.setNumClusters(numClusters);
-		return entity;
-	}
-	
-	@SuppressWarnings("serial")
-	private TestEntity createEntityWithoutDatacenter(final String cluster, final String rack, int numHosts, long numClusters){
-		TestEntity entity = new TestEntity();
-		Map<String, String> tags = new HashMap<String, String>(){{
-			put("cluster", cluster);
-			put("rack", rack);
-		}}; 
-		entity.setTags(tags);
-		entity.setNumHosts(numHosts);
-		entity.setNumClusters(numClusters);
-		return entity;
-	}
+    @SuppressWarnings("serial")
+    private TestEntity createEntity(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters) {
+        TestEntity entity = new TestEntity();
+        Map<String, String> tags = new HashMap<String, String>() {{
+            put("cluster", cluster);
+            put("datacenter", datacenter);
+            put("rack", rack);
+        }};
+        entity.setTags(tags);
+        entity.setNumHosts(numHosts);
+        entity.setNumClusters(numClusters);
+        return entity;
+    }
 
-	private void writeToJson(String message, Object obj){
-		JsonFactory factory = new JsonFactory();
-		ObjectMapper mapper = new ObjectMapper(factory);
-		try{
-			String result = mapper.writeValueAsString(obj);
-			LOG.info(message + ":\n" + result);
-		}catch(Exception ex){
-			LOG.error("Can not write json", ex);
-			Assert.fail("Can not write json");
-		}
-	}
-	
-	@Test
-	public void testZeroGropubyFieldHierarchicalAggregator(){ 
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		HierarchicalAggregator agg = new HierarchicalAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			HierarchicalAggregateEntity result = agg.result();
-			writeToJson("After aggregate", result);
-			Assert.assertEquals(result.getChildren().size(), 0);
-			Assert.assertEquals(result.getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+    @SuppressWarnings("serial")
+    private TestEntity createEntityWithoutDatacenter(final String cluster, final String rack, int numHosts, long numClusters) {
+        TestEntity entity = new TestEntity();
+        Map<String, String> tags = new HashMap<String, String>() {{
+            put("cluster", cluster);
+            put("rack", rack);
+        }};
+        entity.setTags(tags);
+        entity.setNumHosts(numHosts);
+        entity.setNumClusters(numClusters);
+        return entity;
+    }
 
-			// test sort by function1
-			SortOption so = new SortOption();
-			so.setIndex(0);
-			so.setAscendant(true);
-			List<SortOption> sortOptions = Arrays.asList(so);
-			PostHierarchicalAggregateSort.sort(result, sortOptions);
-			writeToJson("After sort" ,result);
-			Assert.assertEquals(null, result.getChildren());
-			Assert.assertEquals(0, result.getSortedList().size());
-			Assert.assertEquals(result.getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testSingleGropubyFieldHierarchicalAggregator(){ 
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc2", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		HierarchicalAggregator agg = new HierarchicalAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			HierarchicalAggregateEntity result = agg.result();
-			writeToJson("After aggregate" ,result);
-			Assert.assertEquals(result.getChildren().size(), 2);
-			Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			
-			// test sort by function 1
-			SortOption so = new SortOption();
-			so.setIndex(0);
-			so.setAscendant(true);
-			List<SortOption> sortOptions = Arrays.asList(so);
-			PostHierarchicalAggregateSort.sort(result, sortOptions);
-			writeToJson("After sort" ,result);
-			Assert.assertEquals(null, result.getChildren());
-			Assert.assertEquals(2, result.getSortedList().size(), 2);
-			Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
-			Assert.assertEquals(true, it.hasNext());
-			Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
-			Assert.assertEquals("cluster2", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			
-			Assert.assertEquals(true, it.hasNext());
-			entry = it.next();
-			Assert.assertEquals("cluster1", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new HierarchicalAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			HierarchicalAggregateEntity result = agg.result();
-			writeToJson("After aggregate" , result);
-			Assert.assertEquals(result.getChildren().size(), 2);
-			Assert.assertEquals(result.getChildren().get("dc1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("dc2").getValues().get(0), (double)(entities[2].getNumHosts()), 0.0001);
-			
-			// test sort by function 1
-			SortOption so = new SortOption();
-			so.setIndex(0);
-			so.setAscendant(true);
-			List<SortOption> sortOptions = Arrays.asList(so);
-			PostHierarchicalAggregateSort.sort(result, sortOptions);
-			writeToJson("After sort" ,result);
-			Assert.assertEquals(null, result.getChildren());
-			Assert.assertEquals(2, result.getSortedList().size(), 2);
-			Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
-			Assert.assertEquals(true, it.hasNext());
-			Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
-			Assert.assertEquals("dc2", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[2].getNumHosts()), 0.0001);
-			
-			Assert.assertEquals(true, it.hasNext());
-			entry = it.next();
-			Assert.assertEquals("dc1", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new HierarchicalAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.sum), Arrays.asList("numHosts", "numClusters"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			HierarchicalAggregateEntity result = agg.result();
-			writeToJson("After aggregate" , result);
-			Assert.assertEquals(result.getChildren().size(), 2);
-			Assert.assertEquals(2, result.getChildren().get("cluster1").getValues().size());
-			Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(1), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()), 0.0001);
-			Assert.assertEquals(2, result.getChildren().get("cluster2").getValues().size());
-			Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(1), (double)(entities[3].getNumClusters()+entities[4].getNumClusters()), 0.0001);
-			
-			// test sort by function 2
-			SortOption so = new SortOption();
-			so.setIndex(1);
-			so.setAscendant(true);
-			List<SortOption> sortOptions = Arrays.asList(so);
-			PostHierarchicalAggregateSort.sort(result, sortOptions);
-			writeToJson("After sort" ,result);
-			Assert.assertEquals(null, result.getChildren());
-			Assert.assertEquals(2, result.getSortedList().size(), 2);
-			Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
-			Assert.assertEquals(true, it.hasNext());
-			Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
-			Assert.assertEquals("cluster1", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(1), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()), 0.0001);
-			
-			Assert.assertEquals(true, it.hasNext());
-			entry = it.next();
-			Assert.assertEquals("cluster2", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(1), (double)(entities[3].getNumClusters()+entities[4].getNumClusters()), 0.0001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	
-	@Test
-	public void testMultipleGropubyFieldsHierarchicalAggregator(){ 
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc2", "rack128", 10, 0);
-		entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		HierarchicalAggregator agg = new HierarchicalAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			HierarchicalAggregateEntity result = agg.result();
-			writeToJson("After aggregate", result);
-			Assert.assertEquals(2, result.getChildren().size());
-			Assert.assertEquals(66.0, (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
-			Assert.assertEquals(2, result.getChildren().get("cluster1").getChildren().size());
-			Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("dc1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("dc2").getValues().get(0), (double)(entities[2].getNumHosts()), 0.0001);
-			
-			Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			Assert.assertEquals(1, result.getChildren().get("cluster2").getChildren().size());
-			Assert.assertEquals(result.getChildren().get("cluster2").getChildren().get("dc1").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			
-			// test sort by function 2
-			SortOption so = new SortOption();
-			so.setIndex(0);
-			so.setAscendant(true);
-			List<SortOption> sortOptions = Arrays.asList(so);
-			PostHierarchicalAggregateSort.sort(result, sortOptions);
-			writeToJson("After sort" ,result);
-			Assert.assertEquals(null, result.getChildren());
-			Assert.assertEquals(2, result.getSortedList().size());
-			Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
-			Assert.assertEquals(true, it.hasNext());
-			Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
-			Assert.assertEquals("cluster2", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
-			
-			Assert.assertEquals(true, it.hasNext());
-			entry = it.next();
-			Assert.assertEquals("cluster1", entry.getKey());
-			Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testUnassigned(){ 
-		TestEntity[] entities = new TestEntity[5];
-		entities[0] = createEntityWithoutDatacenter("cluster1", "rack123", 12, 2);
-		entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
-		entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
-		entities[3] = createEntityWithoutDatacenter("cluster2", "rack125", 9, 2);
-		entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-		HierarchicalAggregator agg = new HierarchicalAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			HierarchicalAggregateEntity result = agg.result();
-			writeToJson("After aggregate", result);
-			Assert.assertEquals(result.getChildren().size(), 2);
-			Assert.assertEquals(result.getChildren().get("dc1").getValues().get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts())+entities[4].getNumHosts(), 0.0001);
-			Assert.assertEquals(result.getChildren().get("unassigned").getValues().get(0), (double)(entities[0].getNumHosts()+entities[3].getNumHosts()), 0.0001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new HierarchicalAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
-		try{
-			for(TestEntity e : entities){
-				agg.accumulate(e);
-			}
-			HierarchicalAggregateEntity result = agg.result();
-			writeToJson("After aggregate", result);
-			Assert.assertEquals(result.getChildren().size(), 2);
-			Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
-			Assert.assertEquals(2, result.getChildren().get("cluster1").getChildren().size());
-			Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("dc1").getValues().get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("unassigned").getValues().get(0), (double)(entities[0].getNumHosts()), 0.0001);
-			
-			Assert.assertEquals(result.getChildren().get("cluster2").getChildren().get("dc1").getValues().get(0), (double)(entities[4].getNumHosts()), 0.0001);
-			Assert.assertEquals(result.getChildren().get("cluster2").getChildren().get("unassigned").getValues().get(0), (double)(entities[3].getNumHosts()), 0.0001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
+    private void writeToJson(String message, Object obj) {
+        JsonFactory factory = new JsonFactory();
+        ObjectMapper mapper = new ObjectMapper(factory);
+        try {
+            String result = mapper.writeValueAsString(obj);
+            LOG.info(message + ":\n" + result);
+        } catch (Exception ex) {
+            LOG.error("Can not write json", ex);
+            Assert.fail("Can not write json");
+        }
+    }
+
+    @Test
+    public void testZeroGropubyFieldHierarchicalAggregator() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+        HierarchicalAggregator agg = new HierarchicalAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            HierarchicalAggregateEntity result = agg.result();
+            writeToJson("After aggregate", result);
+            Assert.assertEquals(result.getChildren().size(), 0);
+            Assert.assertEquals(result.getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+
+            // test sort by function1
+            SortOption so = new SortOption();
+            so.setIndex(0);
+            so.setAscendant(true);
+            List<SortOption> sortOptions = Arrays.asList(so);
+            PostHierarchicalAggregateSort.sort(result, sortOptions);
+            writeToJson("After sort" ,result);
+            Assert.assertEquals(null, result.getChildren());
+            Assert.assertEquals(0, result.getSortedList().size());
+            Assert.assertEquals(result.getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testSingleGropubyFieldHierarchicalAggregator() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc2", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+        HierarchicalAggregator agg = new HierarchicalAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            HierarchicalAggregateEntity result = agg.result();
+            writeToJson("After aggregate" ,result);
+            Assert.assertEquals(result.getChildren().size(), 2);
+            Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+
+            // test sort by function 1
+            SortOption so = new SortOption();
+            so.setIndex(0);
+            so.setAscendant(true);
+            List<SortOption> sortOptions = Arrays.asList(so);
+            PostHierarchicalAggregateSort.sort(result, sortOptions);
+            writeToJson("After sort" ,result);
+            Assert.assertEquals(null, result.getChildren());
+            Assert.assertEquals(2, result.getSortedList().size(), 2);
+            Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
+            Assert.assertEquals(true, it.hasNext());
+            Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
+            Assert.assertEquals("cluster2", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+
+            Assert.assertEquals(true, it.hasNext());
+            entry = it.next();
+            Assert.assertEquals("cluster1", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new HierarchicalAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            HierarchicalAggregateEntity result = agg.result();
+            writeToJson("After aggregate" , result);
+            Assert.assertEquals(result.getChildren().size(), 2);
+            Assert.assertEquals(result.getChildren().get("dc1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("dc2").getValues().get(0), (double)(entities[2].getNumHosts()), 0.0001);
+
+            // test sort by function 1
+            SortOption so = new SortOption();
+            so.setIndex(0);
+            so.setAscendant(true);
+            List<SortOption> sortOptions = Arrays.asList(so);
+            PostHierarchicalAggregateSort.sort(result, sortOptions);
+            writeToJson("After sort" ,result);
+            Assert.assertEquals(null, result.getChildren());
+            Assert.assertEquals(2, result.getSortedList().size(), 2);
+            Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
+            Assert.assertEquals(true, it.hasNext());
+            Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
+            Assert.assertEquals("dc2", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[2].getNumHosts()), 0.0001);
+
+            Assert.assertEquals(true, it.hasNext());
+            entry = it.next();
+            Assert.assertEquals("dc1", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new HierarchicalAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.sum), Arrays.asList("numHosts", "numClusters"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            HierarchicalAggregateEntity result = agg.result();
+            writeToJson("After aggregate" , result);
+            Assert.assertEquals(result.getChildren().size(), 2);
+            Assert.assertEquals(2, result.getChildren().get("cluster1").getValues().size());
+            Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(1), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()), 0.0001);
+            Assert.assertEquals(2, result.getChildren().get("cluster2").getValues().size());
+            Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(1), (double)(entities[3].getNumClusters()+entities[4].getNumClusters()), 0.0001);
+
+            // test sort by function 2
+            SortOption so = new SortOption();
+            so.setIndex(1);
+            so.setAscendant(true);
+            List<SortOption> sortOptions = Arrays.asList(so);
+            PostHierarchicalAggregateSort.sort(result, sortOptions);
+            writeToJson("After sort" ,result);
+            Assert.assertEquals(null, result.getChildren());
+            Assert.assertEquals(2, result.getSortedList().size(), 2);
+            Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
+            Assert.assertEquals(true, it.hasNext());
+            Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
+            Assert.assertEquals("cluster1", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(1), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()), 0.0001);
+
+            Assert.assertEquals(true, it.hasNext());
+            entry = it.next();
+            Assert.assertEquals("cluster2", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(1), (double)(entities[3].getNumClusters()+entities[4].getNumClusters()), 0.0001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+
+    @Test
+    public void testMultipleGropubyFieldsHierarchicalAggregator() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc2", "rack128", 10, 0);
+        entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+        HierarchicalAggregator agg = new HierarchicalAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            HierarchicalAggregateEntity result = agg.result();
+            writeToJson("After aggregate", result);
+            Assert.assertEquals(2, result.getChildren().size());
+            Assert.assertEquals(66.0, (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
+            Assert.assertEquals(2, result.getChildren().get("cluster1").getChildren().size());
+            Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("dc1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("dc2").getValues().get(0), (double)(entities[2].getNumHosts()), 0.0001);
+
+            Assert.assertEquals(result.getChildren().get("cluster2").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+            Assert.assertEquals(1, result.getChildren().get("cluster2").getChildren().size());
+            Assert.assertEquals(result.getChildren().get("cluster2").getChildren().get("dc1").getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+
+            // test sort by function 2
+            SortOption so = new SortOption();
+            so.setIndex(0);
+            so.setAscendant(true);
+            List<SortOption> sortOptions = Arrays.asList(so);
+            PostHierarchicalAggregateSort.sort(result, sortOptions);
+            writeToJson("After sort" ,result);
+            Assert.assertEquals(null, result.getChildren());
+            Assert.assertEquals(2, result.getSortedList().size());
+            Iterator<Map.Entry<String, HierarchicalAggregateEntity>> it = result.getSortedList().iterator();
+            Assert.assertEquals(true, it.hasNext());
+            Map.Entry<String, HierarchicalAggregateEntity> entry = it.next();
+            Assert.assertEquals("cluster2", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()), 0.0001);
+
+            Assert.assertEquals(true, it.hasNext());
+            entry = it.next();
+            Assert.assertEquals("cluster1", entry.getKey());
+            Assert.assertEquals(entry.getValue().getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testUnassigned() {
+        TestEntity[] entities = new TestEntity[5];
+        entities[0] = createEntityWithoutDatacenter("cluster1", "rack123", 12, 2);
+        entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
+        entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
+        entities[3] = createEntityWithoutDatacenter("cluster2", "rack125", 9, 2);
+        entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
+        HierarchicalAggregator agg = new HierarchicalAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            HierarchicalAggregateEntity result = agg.result();
+            writeToJson("After aggregate", result);
+            Assert.assertEquals(result.getChildren().size(), 2);
+            Assert.assertEquals(result.getChildren().get("dc1").getValues().get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts())+entities[4].getNumHosts(), 0.0001);
+            Assert.assertEquals(result.getChildren().get("unassigned").getValues().get(0), (double)(entities[0].getNumHosts()+entities[3].getNumHosts()), 0.0001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new HierarchicalAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
+        try {
+            for (TestEntity e : entities) {
+                agg.accumulate(e);
+            }
+            HierarchicalAggregateEntity result = agg.result();
+            writeToJson("After aggregate", result);
+            Assert.assertEquals(result.getChildren().size(), 2);
+            Assert.assertEquals(result.getChildren().get("cluster1").getValues().get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
+            Assert.assertEquals(2, result.getChildren().get("cluster1").getChildren().size());
+            Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("dc1").getValues().get(0), (double)(entities[1].getNumHosts()+entities[2].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("cluster1").getChildren().get("unassigned").getValues().get(0), (double)(entities[0].getNumHosts()), 0.0001);
+
+            Assert.assertEquals(result.getChildren().get("cluster2").getChildren().get("dc1").getValues().get(0), (double)(entities[4].getNumHosts()), 0.0001);
+            Assert.assertEquals(result.getChildren().get("cluster2").getChildren().get("unassigned").getValues().get(0), (double)(entities[3].getNumHosts()), 0.0001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java
index 10f96dc..016f77e 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java
@@ -19,24 +19,24 @@
 package org.apache.eagle.query.aggregate.test;
 
 import org.apache.eagle.query.ListQueryCompiler;
-import org.apache.eagle.query.parser.EagleQueryParseException;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class TestListQueryCompiler {
-    private final static Logger LOG = LoggerFactory.getLogger(TestListQueryCompiler.class);
+    private static final Logger LOG = LoggerFactory.getLogger(TestListQueryCompiler.class);
+
     @Test
     public void test() throws Exception {
         try {
-            String queryWithCondition = "TestTimeSeriesAPIEntity[@site=\"test\"]{*}";
-            ListQueryCompiler compiler = new ListQueryCompiler(queryWithCondition);
-            String queryWithSquareBrackets = "TestTimeSeriesAPIEntity[@condition=\"[A9BB756BFB8] Data[site=2]/(4/5)\"]{*}";
+            String queryWithCondition = "TestTimeSeriesAPIEntity[@site =\"test\"]{*}";
+            new ListQueryCompiler(queryWithCondition);
+            String queryWithSquareBrackets = "TestTimeSeriesAPIEntity[@condition =\"[A9BB756BFB8] Data[site= 2]/(4/5)\"]{*}";
             new ListQueryCompiler(queryWithSquareBrackets);
             String queryWithoutCondition = "TestTimeSeriesAPIEntity[]{*}";
             new ListQueryCompiler(queryWithoutCondition);
-            String query = "TestTimeSeriesAPIEntity[@condition=\"[A9BB756BFB8]{4/5}\"]{*}";
+            String query = "TestTimeSeriesAPIEntity[@condition =\"[A9BB756BFB8]{4/5}\"]{*}";
             new ListQueryCompiler(query);
         } catch (IllegalArgumentException e) {
             LOG.error(e.getMessage());


[5/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/FlatAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/FlatAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/FlatAggregator.java
index e12fea3..15e89ad 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/FlatAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/FlatAggregator.java
@@ -26,36 +26,36 @@ import org.apache.eagle.query.aggregate.AggregateFunctionType;
 /**
  * Not thread safe
  */
-public class FlatAggregator extends AbstractAggregator{
-	protected GroupbyBucket bucket;
+public class FlatAggregator extends AbstractAggregator {
+    protected GroupbyBucket bucket;
 
     /**
      * @param groupbyFields
      * @param aggregateFuntionTypes
      * @param aggregatedFields
      */
-	public FlatAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields){
-		super(groupbyFields, aggregateFuntionTypes, aggregatedFields);
-		bucket = new GroupbyBucket(this.aggregateFunctionTypes);
-	}
-	
-	public void accumulate(TaggedLogAPIEntity entity) throws Exception{
-		List<String> groupbyFieldValues = createGroup(entity);
-		List<Double> preAggregatedValues = createPreAggregatedValues(entity);
-		bucket.addDatapoint(groupbyFieldValues, preAggregatedValues);
-	}
-	
-	public Map<List<String>, List<Double>> result(){
-		return bucket.result(); 
-	}
-	
-	protected List<String> createGroup(TaggedLogAPIEntity entity){
-		List<String> groupbyFieldValues = new ArrayList<String>();
-		int i = 0;
-		for(String groupbyField : groupbyFields){
-			String groupbyFieldValue = determineGroupbyFieldValue(entity, groupbyField, i++);
-			groupbyFieldValues.add(groupbyFieldValue);
-		}
-		return groupbyFieldValues;
-	}
+    public FlatAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields) {
+        super(groupbyFields, aggregateFuntionTypes, aggregatedFields);
+        bucket = new GroupbyBucket(this.aggregateFunctionTypes);
+    }
+
+    public void accumulate(TaggedLogAPIEntity entity) throws Exception {
+        List<String> groupbyFieldValues = createGroup(entity);
+        List<Double> preAggregatedValues = createPreAggregatedValues(entity);
+        bucket.addDatapoint(groupbyFieldValues, preAggregatedValues);
+    }
+
+    public Map<List<String>, List<Double>> result() {
+        return bucket.result();
+    }
+
+    protected List<String> createGroup(TaggedLogAPIEntity entity) {
+        List<String> groupbyFieldValues = new ArrayList<String>();
+        int i = 0;
+        for (String groupbyField : groupbyFields) {
+            String groupbyFieldValue = determineGroupbyFieldValue(entity, groupbyField, i++);
+            groupbyFieldValues.add(groupbyFieldValue);
+        }
+        return groupbyFieldValues;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyBucket.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyBucket.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyBucket.java
index ea57edb..93e65a9 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyBucket.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyBucket.java
@@ -31,211 +31,230 @@ import java.util.List;
 import java.util.Map;
 
 public class GroupbyBucket {
-	private final static Logger LOG = LoggerFactory.getLogger(GroupbyBucket.class);
-	
-	public static Map<String, FunctionFactory> _functionFactories = 
-			new HashMap<>();
-    
-	// TODO put this logic to AggregatorFunctionType
-	static{
-		_functionFactories.put(AggregateFunctionType.count.name(), new CountFactory());
-		_functionFactories.put(AggregateFunctionType.sum.name(), new SumFactory());
-		_functionFactories.put(AggregateFunctionType.min.name(), new MinFactory());
-		_functionFactories.put(AggregateFunctionType.max.name(), new MaxFactory());
-		_functionFactories.put(AggregateFunctionType.avg.name(), new AvgFactory());
-	}
-	
-	private List<AggregateFunctionType> types;
-//	private SortedMap<List<String>, List<Function>> group2FunctionMap = 
-//			new TreeMap<List<String>, List<Function>>(new GroupbyFieldsComparator());
-	
-	private Map<List<String>, List<Function>> group2FunctionMap = new HashMap<>(); //new GroupbyFieldsComparator());
-	
-	public GroupbyBucket(List<AggregateFunctionType> types){
-		this.types = types;
-	}
-	
-	public void addDatapoint(List<String> groupbyFieldValues, List<Double> values){
-		// LOG.info("DEBUG: addDatapoint: groupby=["+StringUtils.join(groupbyFieldValues,",")+"], values=["+StringUtils.join(values, ",")+"]");
-		
-		// locate groupby bucket
-		List<Function> functions = group2FunctionMap.get(groupbyFieldValues);
-		if(functions == null){
-			functions = new ArrayList<Function>();
-			for(AggregateFunctionType type : types){
-				functions.add(_functionFactories.get(type.name()).createFunction());
-			}
-			group2FunctionMap.put(groupbyFieldValues, functions);
-		}
-		int functionIndex = 0;
-		for(Double v : values){
-			functions.get(functionIndex).run(v);
-			functionIndex++;
-		}
-	}
-	
-	public Map<List<String>, List<Double>> result(){
-		Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>();
-		for(Map.Entry<List<String>, List<Function>> entry : this.group2FunctionMap.entrySet()){
-			List<Double> values = new ArrayList<Double>();
-			for(Function f : entry.getValue()){
-				values.add(f.result());
-			}
-			result.put(entry.getKey(), values);
-		}
-		return result;
-	}
-
-	public List<GroupbyKeyValue> getGroupbyKeyValue(){
-		List<GroupbyKeyValue>  results = new ArrayList<GroupbyKeyValue>();
-		
-		for(Map.Entry<List<String>, List<Function>> entry : this.group2FunctionMap.entrySet()){
-			GroupbyKey key = new GroupbyKey();
-			for(String keyStr:entry.getKey()){
-				try {
-					key.addValue(keyStr.getBytes(QueryConstants.CHARSET));
-				} catch (UnsupportedEncodingException e) {
-					LOG.error(e.getMessage(),e);
-				}
-			}
-			GroupbyValue value = new GroupbyValue();
-			for(Function f : entry.getValue()){
-				value.add(f.result());
-				value.addMeta(f.count());
-			}
-			results.add(new GroupbyKeyValue(key,value));
-		}
-		
-		return results;
-	}
-	
-	public static interface FunctionFactory{
-		public Function createFunction();
-	}
-	
-	public static abstract class Function{
-		protected int count;
-
-		public abstract void run(double v);
-		public abstract double result();
-		public int count(){
-			return count;
-		}
-		public void incrCount(){
-			count ++;
-		}
-	}
-
-	private static class CountFactory implements FunctionFactory{
-		@Override
-		public Function createFunction(){
-			return new Count();
-		}
-	}
-	
-	
-	private static class Count extends Sum{
-		public Count(){
-			super();
-		}
-	}
-	
-	private static class SumFactory implements FunctionFactory{
-		@Override
-		public Function createFunction(){
-			return new Sum();
-		}
-	}
-	
-	private static class Sum extends Function{
-		private double summary;
-		public Sum(){
-			this.summary = 0.0;
-		}
-		@Override
-		public void run(double v){
-			this.incrCount();
-			this.summary += v;
-		}
-		
-		@Override
-		public double result(){
-			return this.summary;
-		}
-	}
-	
-	private static class MinFactory implements FunctionFactory{
-		@Override
-		public Function createFunction(){
-			return new Min();
-		}
-	}
-	public static class Min extends Function{
-		private double minimum;
-		public Min(){
-			// TODO is this a bug, or only positive numeric calculation is supported
-			this.minimum = Double.MAX_VALUE;
-		}
-
-		@Override
-		public void run(double v){
-			if(v < minimum){
-				minimum = v;
-			}
-			this.incrCount();
-		}
-		
-		@Override
-		public double result(){
-			return minimum;
-		}
-	}
-	
-	private static class MaxFactory implements FunctionFactory{
-		@Override
-		public Function createFunction(){
-			return new Max();
-		}
-	}
-	public static class Max extends Function{
-		private double maximum;
-		public Max(){
-			// TODO is this a bug, or only positive numeric calculation is supported
-			this.maximum = 0.0;
-		}
-		@Override
-		public void run(double v){
-			if(v > maximum){
-				maximum = v;
-			}
-			this.incrCount();
-		}
-		
-		@Override
-		public double result(){
-			return maximum;
-		}
-	}
-	
-	private static class AvgFactory implements FunctionFactory{
-		@Override
-		public Function createFunction(){
-			return new Avg();
-		}
-	}
-	public static class Avg extends Function{
-		private double total;
-		public Avg(){
-			this.total = 0.0;
-		}
-		@Override
-		public void run(double v){
-			total += v;
-			this.incrCount();
-		}
-		@Override
-		public double result(){
-			return this.total/this.count;
-		}
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(GroupbyBucket.class);
+
+    public static Map<String, FunctionFactory> functionFactories = new HashMap<>();
+
+    // TODO put this logic to AggregatorFunctionType
+    static {
+        functionFactories.put(AggregateFunctionType.count.name(), new CountFactory());
+        functionFactories.put(AggregateFunctionType.sum.name(), new SumFactory());
+        functionFactories.put(AggregateFunctionType.min.name(), new MinFactory());
+        functionFactories.put(AggregateFunctionType.max.name(), new MaxFactory());
+        functionFactories.put(AggregateFunctionType.avg.name(), new AvgFactory());
+    }
+
+    private List<AggregateFunctionType> types;
+    // private SortedMap<List<String>, List<Function>> group2FunctionMap =
+    //     new TreeMap<List<String>, List<Function>>(new GroupbyFieldsComparator());
+
+    private Map<List<String>, List<Function>> group2FunctionMap = new HashMap<>(); //new GroupbyFieldsComparator());
+
+    public GroupbyBucket(List<AggregateFunctionType> types) {
+        this.types = types;
+    }
+
+    public void addDatapoint(List<String> groupbyFieldValues, List<Double> values) {
+        // LOG.info("DEBUG: addDatapoint: groupby =["+StringUtils.join(groupbyFieldValues,",")+"], values=["+StringUtils.join(values, ",")+"]");
+
+        // locate groupby bucket
+        List<Function> functions = group2FunctionMap.get(groupbyFieldValues);
+        if (functions == null) {
+            functions = new ArrayList<Function>();
+            for (AggregateFunctionType type : types) {
+                functions.add(functionFactories.get(type.name()).createFunction());
+            }
+            group2FunctionMap.put(groupbyFieldValues, functions);
+        }
+        int functionIndex = 0;
+        for (Double v : values) {
+            functions.get(functionIndex).run(v);
+            functionIndex++;
+        }
+    }
+
+    public Map<List<String>, List<Double>> result() {
+        Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>();
+        for (Map.Entry<List<String>, List<Function>> entry : this.group2FunctionMap.entrySet()) {
+            List<Double> values = new ArrayList<Double>();
+            for (Function f : entry.getValue()) {
+                values.add(f.result());
+            }
+            result.put(entry.getKey(), values);
+        }
+        return result;
+    }
+
+    public List<GroupbyKeyValue> getGroupbyKeyValue() {
+        List<GroupbyKeyValue>  results = new ArrayList<GroupbyKeyValue>();
+
+        for (Map.Entry<List<String>, List<Function>> entry : this.group2FunctionMap.entrySet()) {
+            GroupbyKey key = new GroupbyKey();
+            for (String keyStr:entry.getKey()) {
+                try {
+                    key.addValue(keyStr.getBytes(QueryConstants.CHARSET));
+                } catch (UnsupportedEncodingException e) {
+                    LOG.error(e.getMessage(),e);
+                }
+            }
+            GroupbyValue value = new GroupbyValue();
+            for (Function f : entry.getValue()) {
+                value.add(f.result());
+                value.addMeta(f.count());
+            }
+            results.add(new GroupbyKeyValue(key,value));
+        }
+
+        return results;
+    }
+
+    public static interface FunctionFactory {
+        public Function createFunction();
+    }
+
+    public abstract static class Function {
+        protected int count;
+
+        public abstract void run(double v);
+
+        public abstract double result();
+
+        public int count() {
+            return count;
+        }
+
+        public void incrCount() {
+            count ++;
+        }
+    }
+
+    private static class CountFactory implements FunctionFactory {
+
+        @Override
+        public Function createFunction() {
+            return new Count();
+        }
+    }
+
+
+    private static class Count extends Sum {
+
+        public Count() {
+            super();
+        }
+    }
+
+    private static class SumFactory implements FunctionFactory {
+
+        @Override
+        public Function createFunction() {
+            return new Sum();
+        }
+    }
+
+    private static class Sum extends Function {
+        private double summary;
+
+        public Sum() {
+            this.summary = 0.0;
+        }
+
+        @Override
+        public void run(double v) {
+            this.incrCount();
+            this.summary += v;
+        }
+
+        @Override
+        public double result() {
+            return this.summary;
+        }
+    }
+
+    private static class MinFactory implements FunctionFactory {
+
+        @Override
+        public Function createFunction() {
+            return new Min();
+        }
+    }
+
+    public static class Min extends Function {
+        private double minimum;
+
+        public Min() {
+            // TODO is this a bug, or only positive numeric calculation is supported
+            this.minimum = Double.MAX_VALUE;
+        }
+
+        @Override
+        public void run(double v) {
+            if (v < minimum) {
+                minimum = v;
+            }
+            this.incrCount();
+        }
+
+        @Override
+        public double result() {
+            return minimum;
+        }
+    }
+
+    private static class MaxFactory implements FunctionFactory {
+
+        @Override
+        public Function createFunction() {
+            return new Max();
+        }
+    }
+
+    public static class Max extends Function {
+        private double maximum;
+
+        public Max() {
+            // TODO is this a bug, or only positive numeric calculation is supported
+            this.maximum = 0.0;
+        }
+
+        @Override
+        public void run(double v) {
+            if (v > maximum) {
+                maximum = v;
+            }
+            this.incrCount();
+        }
+
+        @Override
+        public double result() {
+            return maximum;
+        }
+    }
+
+    private static class AvgFactory implements FunctionFactory {
+
+        @Override
+        public Function createFunction() {
+            return new Avg();
+        }
+    }
+
+    public static class Avg extends Function {
+        private double total;
+
+        public Avg() {
+            this.total = 0.0;
+        }
+
+        @Override
+        public void run(double v) {
+            total += v;
+            this.incrCount();
+        }
+
+        @Override
+        public double result() {
+            return this.total / this.count;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyFieldsComparator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyFieldsComparator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyFieldsComparator.java
index 6635483..b612ccf 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyFieldsComparator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/GroupbyFieldsComparator.java
@@ -22,18 +22,21 @@ import java.util.List;
 /**
  * this is default comparator for aggregation. The behavior is to sort by groupby fields ascendantly
  */
-public class GroupbyFieldsComparator implements Comparator<List<String>>{
-	@Override 
-    public int compare(List<String> list1, List<String> list2){
-		if(list1 == null || list2 == null || list1.size() != list2.size())
-			throw new IllegalArgumentException("2 list of groupby fields must be non-null and have the same size");
-		int r = 0;
-		int index = 0;
-		for(String s1 : list1){
-			r = s1.compareTo(list2.get(index++));
-			if(r != 0)
-				return r;
-		}
-		return r;
-	}
+public class GroupbyFieldsComparator implements Comparator<List<String>> {
+
+    @Override
+    public int compare(List<String> list1, List<String> list2) {
+        if (list1 == null || list2 == null || list1.size() != list2.size()) {
+            throw new IllegalArgumentException("2 list of groupby fields must be non-null and have the same size");
+        }
+        int r = 0;
+        int index = 0;
+        for (String s1 : list1) {
+            r = s1.compareTo(list2.get(index++));
+            if (r != 0) {
+                return r;
+            }
+        }
+        return r;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregateEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregateEntity.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregateEntity.java
index 341fa00..559061b 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregateEntity.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregateEntity.java
@@ -25,43 +25,52 @@ import java.util.TreeMap;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
 public class HierarchicalAggregateEntity {
-	private String key;
-	private List<GroupbyBucket.Function> tmpValues = new ArrayList<GroupbyBucket.Function>();
-	private List<Double> values = new ArrayList<Double>();
-	private SortedMap<String, HierarchicalAggregateEntity> children = new TreeMap<String, HierarchicalAggregateEntity>();
-	private SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortedList = null;
+    private String key;
+    private List<GroupbyBucket.Function> tmpValues = new ArrayList<GroupbyBucket.Function>();
+    private List<Double> values = new ArrayList<Double>();
+    private SortedMap<String, HierarchicalAggregateEntity> children = new TreeMap<String, HierarchicalAggregateEntity>();
+    private SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortedList = null;
 
-	public SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> getSortedList() {
-		return sortedList;
-	}
-	public void setSortedList(
-			SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortedList) {
-		this.sortedList = sortedList;
-	}
-	public List<GroupbyBucket.Function> getTmpValues() {
-		return tmpValues;
-	}
-	public void setTmpValues(List<GroupbyBucket.Function> tmpValues) {
-		this.tmpValues = tmpValues;
-	}
-	public String getKey() {
-		return key;
-	}
-	public void setKey(String key) {
-		this.key = key;
-	}
-	public List<Double> getValues() {
-		return values;
-	}
-	public void setValues(List<Double> values) {
-		this.values = values;
-	}
-	public SortedMap<String, HierarchicalAggregateEntity> getChildren() {
-		return children;
-	}
-	public void setChildren(SortedMap<String, HierarchicalAggregateEntity> children) {
-		this.children = children;
-	}
+    public SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> getSortedList() {
+        return sortedList;
+    }
+
+    public void setSortedList(
+                              SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortedList) {
+        this.sortedList = sortedList;
+    }
+
+    public List<GroupbyBucket.Function> getTmpValues() {
+        return tmpValues;
+    }
+
+    public void setTmpValues(List<GroupbyBucket.Function> tmpValues) {
+        this.tmpValues = tmpValues;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public List<Double> getValues() {
+        return values;
+    }
+
+    public void setValues(List<Double> values) {
+        this.values = values;
+    }
+
+    public SortedMap<String, HierarchicalAggregateEntity> getChildren() {
+        return children;
+    }
+
+    public void setChildren(SortedMap<String, HierarchicalAggregateEntity> children) {
+        this.children = children;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregator.java
index ecb80ac..8751a74 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/HierarchicalAggregator.java
@@ -22,61 +22,61 @@ import java.util.SortedMap;
 import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
 import org.apache.eagle.query.aggregate.AggregateFunctionType;
 
-public class HierarchicalAggregator extends AbstractAggregator{
-	private HierarchicalAggregateEntity root = new HierarchicalAggregateEntity();
+public class HierarchicalAggregator extends AbstractAggregator {
+    private HierarchicalAggregateEntity root = new HierarchicalAggregateEntity();
 
-	public HierarchicalAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields){
-		super(groupbyFields, aggregateFuntionTypes, aggregatedFields);
-	}
+    public HierarchicalAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields) {
+        super(groupbyFields, aggregateFuntionTypes, aggregatedFields);
+    }
 
-	public void accumulate(TaggedLogAPIEntity entity) throws Exception{
-		List<Double> preAggregatedValues = createPreAggregatedValues(entity);
-		// aggregate to root first
-		addDatapoint(root, preAggregatedValues);
-		// go through hierarchical tree
-		HierarchicalAggregateEntity current = root;
-		int i = 0;
-		for(String groupbyField : groupbyFields){
-			// determine groupbyFieldValue from tag or fields
-			String groupbyFieldValue = determineGroupbyFieldValue(entity, groupbyField, i);
-			SortedMap<String, HierarchicalAggregateEntity> children = current.getChildren();
-			if(children.get(groupbyFieldValue) == null){
-				HierarchicalAggregateEntity tmp = new HierarchicalAggregateEntity();
-				children.put(groupbyFieldValue, tmp);
-			}
-			children.get(groupbyFieldValue).setKey(groupbyFieldValue);
-			addDatapoint(children.get(groupbyFieldValue), preAggregatedValues);
-			current = children.get(groupbyFieldValue);
-		}
-	}
+    public void accumulate(TaggedLogAPIEntity entity) throws Exception {
+        List<Double> preAggregatedValues = createPreAggregatedValues(entity);
+        // aggregate to root first
+        addDatapoint(root, preAggregatedValues);
+        // go through hierarchical tree
+        HierarchicalAggregateEntity current = root;
+        int i = 0;
+        for (String groupbyField : groupbyFields) {
+            // determine groupbyFieldValue from tag or fields
+            String groupbyFieldValue = determineGroupbyFieldValue(entity, groupbyField, i);
+            SortedMap<String, HierarchicalAggregateEntity> children = current.getChildren();
+            if (children.get(groupbyFieldValue) == null) {
+                HierarchicalAggregateEntity tmp = new HierarchicalAggregateEntity();
+                children.put(groupbyFieldValue, tmp);
+            }
+            children.get(groupbyFieldValue).setKey(groupbyFieldValue);
+            addDatapoint(children.get(groupbyFieldValue), preAggregatedValues);
+            current = children.get(groupbyFieldValue);
+        }
+    }
 
-	private void addDatapoint(HierarchicalAggregateEntity entity, List<Double> values){
-		List<GroupbyBucket.Function> functions = entity.getTmpValues();
-		// initialize list of function
-		if(functions.isEmpty()){
-			for(AggregateFunctionType type : aggregateFunctionTypes){
-				functions.add(GroupbyBucket._functionFactories.get(type.name()).createFunction());
-			}
-		}
-		int functionIndex = 0;
-		for(Double v : values){
-			functions.get(functionIndex).run(v);
-			functionIndex++;
-		}
-	}
+    private void addDatapoint(HierarchicalAggregateEntity entity, List<Double> values) {
+        List<GroupbyBucket.Function> functions = entity.getTmpValues();
+        // initialize list of function
+        if (functions.isEmpty()) {
+            for (AggregateFunctionType type : aggregateFunctionTypes) {
+                functions.add(GroupbyBucket.functionFactories.get(type.name()).createFunction());
+            }
+        }
+        int functionIndex = 0;
+        for (Double v : values) {
+            functions.get(functionIndex).run(v);
+            functionIndex++;
+        }
+    }
 
-	private void finalizeHierarchicalAggregateEntity(HierarchicalAggregateEntity entity){
-		for(GroupbyBucket.Function f : entity.getTmpValues()){
-			entity.getValues().add(f.result());
-		}
-		for(HierarchicalAggregateEntity child : entity.getChildren().values()){
-			finalizeHierarchicalAggregateEntity(child);
-		}
-		entity.setTmpValues(null);
-	}
+    private void finalizeHierarchicalAggregateEntity(HierarchicalAggregateEntity entity) {
+        for (GroupbyBucket.Function f : entity.getTmpValues()) {
+            entity.getValues().add(f.result());
+        }
+        for (HierarchicalAggregateEntity child : entity.getChildren().values()) {
+            finalizeHierarchicalAggregateEntity(child);
+        }
+        entity.setTmpValues(null);
+    }
 
-	public HierarchicalAggregateEntity result(){
-		finalizeHierarchicalAggregateEntity(root);
-		return this.root;
-	}
+    public HierarchicalAggregateEntity result() {
+        finalizeHierarchicalAggregateEntity(root);
+        return this.root;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostFlatAggregateSort.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostFlatAggregateSort.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostFlatAggregateSort.java
index f62d2c2..8ca24c6 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostFlatAggregateSort.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostFlatAggregateSort.java
@@ -24,70 +24,74 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 
 public class PostFlatAggregateSort {
-	private static SortedSet<Map.Entry<List<String>, List<Double>>> sortByValue(Map<List<String>, List<Double>> map, List<SortOption> sortOptions) {
-	    SortedSet<Map.Entry<List<String>, List<Double>>> sortedEntries = new TreeSet<Map.Entry<List<String>, List<Double>>>(new MapEntryComparator(sortOptions));
-	    sortedEntries.addAll(map.entrySet());
-	    return sortedEntries;
-	}
+    private static SortedSet<Map.Entry<List<String>, List<Double>>> sortByValue(Map<List<String>, List<Double>> map, List<SortOption> sortOptions) {
+        SortedSet<Map.Entry<List<String>, List<Double>>> sortedEntries = new TreeSet<Map.Entry<List<String>, List<Double>>>(new MapEntryComparator(sortOptions));
+        sortedEntries.addAll(map.entrySet());
+        return sortedEntries;
+    }
 
-	/**
-	 * sort aggregated results with sort options
-	 * @param aggregatedResult aggregated result set, but it is not sorted
-	 * @sortOptions sorting options
-	 * @topN top N results will be returned if topN is specified. If it's not specified (as default value 0), all results will be returned
-	 */
-	public static List<Map.Entry<List<String>, List<Double>>> sort(Map<List<String>, List<Double>> aggregatedResult, List<SortOption> sortOptions, int topN){
-		SortedSet<Map.Entry<List<String>, List<Double>>> allList = sortByValue(aggregatedResult, sortOptions);
-		List<Map.Entry<List<String>, List<Double>>> result = new ArrayList<Map.Entry<List<String>, List<Double>>>();
-		for (Map.Entry<List<String>, List<Double>> entry : allList) {
-			result.add(entry);
-			if (topN > 0 && result.size() >= topN) {
-				break;
-			}
-		}
-		return result;
-	}
+    /**
+     * sort aggregated results with sort options
+     * @param aggregatedResult aggregated result set, but it is not sorted
+     * @sortOptions sorting options
+     * @topN top N results will be returned if topN is specified. If it's not specified (as default value 0), all results will be returned
+     */
+    public static List<Map.Entry<List<String>, List<Double>>> sort(Map<List<String>, List<Double>> aggregatedResult, List<SortOption> sortOptions, int topN) {
+        SortedSet<Map.Entry<List<String>, List<Double>>> allList = sortByValue(aggregatedResult, sortOptions);
+        List<Map.Entry<List<String>, List<Double>>> result = new ArrayList<Map.Entry<List<String>, List<Double>>>();
+        for (Map.Entry<List<String>, List<Double>> entry : allList) {
+            result.add(entry);
+            if (topN > 0 && result.size() >= topN) {
+                break;
+            }
+        }
+        return result;
+    }
+
+    private static class MapEntryComparator implements Comparator<Map.Entry<List<String>, List<Double>>> {
+        private List<SortOption> sortOptions;
+
+        public MapEntryComparator(List<SortOption> sortOptions) {
+            this.sortOptions = sortOptions;
+        }
 
-	private static class MapEntryComparator implements Comparator<Map.Entry<List<String>, List<Double>>>{
-		private List<SortOption> sortOptions;
-		public MapEntryComparator(List<SortOption> sortOptions){
-			this.sortOptions = sortOptions;
-		}
-		/**
-		 * default to sort by all groupby fields
-		 */
-		@Override
-        public int compare(Map.Entry<List<String>, List<Double>> e1, Map.Entry<List<String>, List<Double>> e2){
-			int r = 0;
-			List<String> keyList1 = e1.getKey();
-			List<Double> valueList1 = e1.getValue();
-			List<String> keyList2 = e2.getKey();
-			List<Double> valueList2 = e2.getValue();
-			for(SortOption so : sortOptions){
-				int index = so.getIndex();
-				if (index == -1) {
-					continue;
-				}
-				if(!so.isInGroupby()){  // sort fields come from functions
-					Double value1 = valueList1.get(index);
-					Double value2 = valueList2.get(index);
-					r = value1.compareTo(value2);
-				}else{  // sort fields come from groupby fields
-					String key1 = keyList1.get(index);
-					String key2 = keyList2.get(index);
-					r = key1.compareTo(key2);
-				}
-				if(r == 0) continue;
-				if(!so.isAscendant()){
-					r = -r;
-				}
-				return r;
-			}
-			// default to sort by groupby fields ascendently
-			if(r ==0){ // TODO is this check necessary
-				return new GroupbyFieldsComparator().compare(keyList1, keyList2);
-			}
-			return r;
+        /**
+         * default to sort by all groupby fields
+         */
+        @Override
+        public int compare(Map.Entry<List<String>, List<Double>> e1, Map.Entry<List<String>, List<Double>> e2) {
+            int r = 0;
+            List<String> keyList1 = e1.getKey();
+            List<Double> valueList1 = e1.getValue();
+            List<String> keyList2 = e2.getKey();
+            List<Double> valueList2 = e2.getValue();
+            for (SortOption so : sortOptions) {
+                int index = so.getIndex();
+                if (index == -1) {
+                    continue;
+                }
+                if (!so.isInGroupby()) {  // sort fields come from functions
+                    Double value1 = valueList1.get(index);
+                    Double value2 = valueList2.get(index);
+                    r = value1.compareTo(value2);
+                } else {  // sort fields come from groupby fields
+                    String key1 = keyList1.get(index);
+                    String key2 = keyList2.get(index);
+                    r = key1.compareTo(key2);
+                }
+                if (r == 0) {
+                    continue;
+                }
+                if (!so.isAscendant()) {
+                    r = -r;
+                }
+                return r;
+            }
+            // default to sort by groupby fields ascendently
+            if (r == 0) { // TODO is this check necessary
+                return new GroupbyFieldsComparator().compare(keyList1, keyList2);
+            }
+            return r;
         }
-	}
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostHierarchicalAggregateSort.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostHierarchicalAggregateSort.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostHierarchicalAggregateSort.java
index 7b0997b..bd475f9 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostHierarchicalAggregateSort.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/PostHierarchicalAggregateSort.java
@@ -24,69 +24,71 @@ import java.util.TreeSet;
 
 public class PostHierarchicalAggregateSort {
 
-	private static SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortByValue(HierarchicalAggregateEntity entity, List<SortOption> sortOptions) {
-	    SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortedEntries = new TreeSet<Map.Entry<String, HierarchicalAggregateEntity>>(new MapEntryComparator(sortOptions));
-	    sortedEntries.addAll(entity.getChildren().entrySet());
-	    return sortedEntries;
-	}
+    private static SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortByValue(HierarchicalAggregateEntity entity, List<SortOption> sortOptions) {
+        SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortedEntries = new TreeSet<Map.Entry<String, HierarchicalAggregateEntity>>(new MapEntryComparator(sortOptions));
+        sortedEntries.addAll(entity.getChildren().entrySet());
+        return sortedEntries;
+    }
 
-	/**
-	 * sort aggregated results with sort options
+    /**
+     * sort aggregated results with sort options
      *
      * @param result
      * @param sortOptions
      * @return
      */
-	public static HierarchicalAggregateEntity sort(HierarchicalAggregateEntity result, List<SortOption> sortOptions){
-		SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> tmp = sortByValue(result, sortOptions);
-		result.setSortedList(tmp);
-		result.setChildren(null);
-		for(Map.Entry<String, HierarchicalAggregateEntity> entry : tmp){
-			sort(entry.getValue(), sortOptions);
-		}
-		return result;
-	}
+    public static HierarchicalAggregateEntity sort(HierarchicalAggregateEntity result, List<SortOption> sortOptions) {
+        SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> tmp = sortByValue(result, sortOptions);
+        result.setSortedList(tmp);
+        result.setChildren(null);
+        for (Map.Entry<String, HierarchicalAggregateEntity> entry : tmp) {
+            sort(entry.getValue(), sortOptions);
+        }
+        return result;
+    }
+
+    private static class MapEntryComparator implements Comparator<Map.Entry<String, HierarchicalAggregateEntity>> {
+        private List<SortOption> sortOptions;
 
-	private static class MapEntryComparator implements Comparator<Map.Entry<String, HierarchicalAggregateEntity>>{
-		private List<SortOption> sortOptions;
+        public MapEntryComparator(List<SortOption> sortOptions) {
+            this.sortOptions = sortOptions;
+        }
 
-		public MapEntryComparator(List<SortOption> sortOptions){
-			this.sortOptions = sortOptions;
-		}
+        /**
+         * default to sort by all groupby fields
+         */
+        @Override
+        public int compare(Map.Entry<String, HierarchicalAggregateEntity> e1, Map.Entry<String, HierarchicalAggregateEntity> e2) {
+            int r = 0;
+            String key1 = e1.getKey();
+            List<Double> valueList1 = e1.getValue().getValues();
+            String key2 = e2.getKey();
+            List<Double> valueList2 = e2.getValue().getValues();
+            for (SortOption so : sortOptions) {
+                int index = so.getIndex();
+                if (index == -1) {
+                    continue;
+                }
+                if (!so.isInGroupby()) {  // sort fields come from functions
+                    Double value1 = valueList1.get(index);
+                    Double value2 = valueList2.get(index);
+                    r = value1.compareTo(value2);
+                }
+                // sort fields come from groupby fields, then silently ignored
 
-		/**
-		 * default to sort by all groupby fields
-		 */
-		@Override
-        public int compare(Map.Entry<String, HierarchicalAggregateEntity> e1, Map.Entry<String, HierarchicalAggregateEntity> e2){
-			int r = 0;
-			String key1 = e1.getKey();
-			List<Double> valueList1 = e1.getValue().getValues();
-			String key2 = e2.getKey();
-			List<Double> valueList2 = e2.getValue().getValues();
-			for(SortOption so : sortOptions){
-				int index = so.getIndex();
-				if (index == -1) {
-					continue;
-				}
-				if(!so.isInGroupby()){  // sort fields come from functions
-					Double value1 = valueList1.get(index);
-					Double value2 = valueList2.get(index);
-					r = value1.compareTo(value2);
-				}  
-				// sort fields come from groupby fields, then silently ignored
-				
-				if(r == 0) continue;
-				if(!so.isAscendant()){
-					r = -r;
-				}
-				return r;
-			}
-			// default to sort by groupby fields ascendently
-			if(r ==0){
-				return key1.compareTo(key2);
-			}
-			return r;
+                if (r == 0) {
+                    continue;
+                }
+                if (!so.isAscendant()) {
+                    r = -r;
+                }
+                return r;
+            }
+            // default to sort by groupby fields ascendently
+            if (r == 0) {
+                return key1.compareTo(key2);
+            }
+            return r;
         }
-	}
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOption.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOption.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOption.java
index d1578ac..c848122 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOption.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOption.java
@@ -19,31 +19,36 @@ package org.apache.eagle.query.aggregate.timeseries;
 /**
  * sum(field1), max(field2) groupby(field3, field4) sort by field1 asc, field3 desc
  * There are 2 SortOption object, then
- * the 1st one is inGroupby=false, index=0, ascendent=true
- * the 2nd one is inGroupby=true, index=1, ascendent=false
+ * the 1st one is inGroupby = false, index=0, ascendent=true
+ * the 2nd one is inGroupby = true, index=1, ascendent=false
  *
  */
 public class SortOption {
-	private boolean inGroupby; // sort field defaultly is not from groupby fields 
-	private int index; // index relative to list of groupby fields or list of functions
-	private boolean ascendant; //asc or desc
+    private boolean inGroupby; // sort field defaultly is not from groupby fields
+    private int index; // index relative to list of groupby fields or list of functions
+    private boolean ascendant; //asc or desc
 
-	public boolean isInGroupby() {
-		return inGroupby;
-	}
-	public void setInGroupby(boolean inGroupby) {
-		this.inGroupby = inGroupby;
-	}
-	public int getIndex() {
-		return index;
-	}
-	public void setIndex(int index) {
-		this.index = index;
-	}
-	public boolean isAscendant() {
-		return ascendant;
-	}
-	public void setAscendant(boolean ascendant) {
-		this.ascendant = ascendant;
-	}
+    public boolean isInGroupby() {
+        return inGroupby;
+    }
+
+    public void setInGroupby(boolean inGroupby) {
+        this.inGroupby = inGroupby;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    public boolean isAscendant() {
+        return ascendant;
+    }
+
+    public void setAscendant(boolean ascendant) {
+        this.ascendant = ascendant;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOptionsParser.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOptionsParser.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOptionsParser.java
index 1360e0c..2457b4e 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOptionsParser.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SortOptionsParser.java
@@ -25,45 +25,45 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class SortOptionsParser {
-	private static final Logger LOG = LoggerFactory.getLogger(SortOptionsParser.class);
-	private static Pattern pattern = Pattern.compile("^(.+)\\s+(asc|desc)$");
-		
-	public static List<SortOption> parse(List<String> groupbyFields, List<String> aggregatedFields, List<String> sortOptions, List<String> sortFields){
-		List<SortOption> list = new ArrayList<SortOption>();
-		for(String sortOption : sortOptions){
-			Matcher m = pattern.matcher(sortOption);
-			if(!m.find()){
-				throw new IllegalArgumentException("sort option must have the format of <groupbyfield|function> asc|desc");
-			}
-			String field = m.group(1);
-			if (sortFields != null) {
-				sortFields.add(field);
-			}
-			SortOption so = new SortOption();
-			list.add(so);
-			so.setAscendant(m.group(2).equals("asc") ? true : false);
-			int index = aggregatedFields.indexOf(field); 
-			if(index > -1){
-				so.setInGroupby(false);
-				so.setIndex(index);
-				continue;
-			}
-			if(groupbyFields != null){  // if groupbyFields is not provided, ignore this sort field
-				index = groupbyFields.indexOf(field);
-				if(index > -1){
-					so.setInGroupby(true);
-					so.setIndex(index);
-					continue;
-				}
-			}
-			logNonExistingSortByField(field);
-			so.setInGroupby(false);
-			so.setIndex(-1);
-		}
-		return list;
-	}
-	
-	private static void logNonExistingSortByField(String sortByField){
-		LOG.warn("Sortby field is neither in aggregated fields or groupby fields, ignore " + sortByField);
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(SortOptionsParser.class);
+    private static Pattern pattern = Pattern.compile("^(.+)\\s+(asc|desc)$");
+
+    public static List<SortOption> parse(List<String> groupbyFields, List<String> aggregatedFields, List<String> sortOptions, List<String> sortFields) {
+        List<SortOption> list = new ArrayList<SortOption>();
+        for (String sortOption : sortOptions) {
+            Matcher m = pattern.matcher(sortOption);
+            if (!m.find()) {
+                throw new IllegalArgumentException("sort option must have the format of <groupbyfield|function> asc|desc");
+            }
+            String field = m.group(1);
+            if (sortFields != null) {
+                sortFields.add(field);
+            }
+            SortOption so = new SortOption();
+            list.add(so);
+            so.setAscendant(m.group(2).equals("asc") ? true : false);
+            int index = aggregatedFields.indexOf(field);
+            if (index > -1) {
+                so.setInGroupby(false);
+                so.setIndex(index);
+                continue;
+            }
+            if (groupbyFields != null) {  // if groupbyFields is not provided, ignore this sort field
+                index = groupbyFields.indexOf(field);
+                if (index > -1) {
+                    so.setInGroupby(true);
+                    so.setIndex(index);
+                    continue;
+                }
+            }
+            logNonExistingSortByField(field);
+            so.setInGroupby(false);
+            so.setIndex(-1);
+        }
+        return list;
+    }
+
+    private static void logNonExistingSortByField(String sortByField) {
+        LOG.warn("Sortby field is neither in aggregated fields or groupby fields, ignore " + sortByField);
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedAggregator.java
index d8b781e..f4eabcd 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedAggregator.java
@@ -18,18 +18,18 @@ package org.apache.eagle.query.aggregate.timeseries;
 
 import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
 
-public class SynchronizedAggregator implements Aggregator{
-	private Object mutex = new Object();
-	private Aggregator agg;
-	
-	public SynchronizedAggregator(Aggregator agg){
-		this.agg = agg;
-	}
-	
-	@Override
-	public void accumulate(TaggedLogAPIEntity entity) throws Exception{
-		synchronized(mutex){
-			agg.accumulate(entity);
-		}
-	}
-}	
+public class SynchronizedAggregator implements Aggregator {
+    private Object mutex = new Object();
+    private Aggregator agg;
+
+    public SynchronizedAggregator(Aggregator agg) {
+        this.agg = agg;
+    }
+
+    @Override
+    public void accumulate(TaggedLogAPIEntity entity) throws Exception {
+        synchronized (mutex) {
+            agg.accumulate(entity);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedEntityCreationListener.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedEntityCreationListener.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedEntityCreationListener.java
index 7c1412e..baa89be 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedEntityCreationListener.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/SynchronizedEntityCreationListener.java
@@ -19,18 +19,18 @@ package org.apache.eagle.query.aggregate.timeseries;
 import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
 import org.apache.eagle.log.entity.EntityCreationListener;
 
-public class SynchronizedEntityCreationListener implements EntityCreationListener{
-	private Object mutex = new Object();
-	private EntityCreationListener listener;
-	
-	public SynchronizedEntityCreationListener(EntityCreationListener listener){
-		this.listener = listener;
-	}
-	
-	@Override
-	public void entityCreated(TaggedLogAPIEntity entity) throws Exception{
-		synchronized(mutex){
-			listener.entityCreated(entity);
-		}
-	}
+public class SynchronizedEntityCreationListener implements EntityCreationListener {
+    private Object mutex = new Object();
+    private EntityCreationListener listener;
+
+    public SynchronizedEntityCreationListener(EntityCreationListener listener) {
+        this.listener = listener;
+    }
+
+    @Override
+    public void entityCreated(TaggedLogAPIEntity entity) throws Exception {
+        synchronized (mutex) {
+            listener.entityCreated(entity);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesAggregator.java
index 5bebe13..e142657 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesAggregator.java
@@ -29,7 +29,7 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * TODO Assuming that data point comes in the sequence of occurrence time desc or asc would 
+ * TODO Assuming that data point comes in the sequence of occurrence time desc or asc would
  * save memory for holding all the data in the memory
  *
  * <h3>Aggregate Bucket Structure</h3>
@@ -41,129 +41,135 @@ import java.util.Map;
  *
  */
 public class TimeSeriesAggregator extends FlatAggregator implements GroupbyKeyAggregatable {
-	private final static Logger LOG = LoggerFactory.getLogger(TimeSeriesAggregator.class);
-	private static final int DEFAULT_DATAPOINT_MAX_COUNT = 1000;
-	private long startTime;
-	private long endTime;
-	private long intervalms;
-	private int numFunctions;
-	private int ignoredEntityCounter = 0;
-	
-	public TimeSeriesAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields,
-			long startTime, long endTime, long intervalms){
-		super(groupbyFields, aggregateFuntionTypes, aggregatedFields);
-		// guard to avoid too many data points returned
-//		validateTimeRange(startTime, endTime, intervalms);
-		this.startTime = startTime;
-		this.endTime = endTime;
-		this.intervalms = intervalms;
-		this.numFunctions = aggregateFuntionTypes.size();
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(TimeSeriesAggregator.class);
+    private static final int DEFAULT_DATAPOINT_MAX_COUNT = 1000;
+    private long startTime;
+    private long endTime;
+    private long intervalms;
+    private int numFunctions;
+    private int ignoredEntityCounter = 0;
 
-//	@Deprecated
-//	public static void validateTimeRange(long startTime, long endTime, long intervalms){
-//		if(startTime >= endTime || intervalms <= 0){
-//			throw new IllegalArgumentException("invalid argument, startTime should be less than endTime and interval must be greater than 0, starTime is " + startTime + " and endTime is " + endTime + ", interval is " + intervalms);
-//		}
-//		if((endTime-startTime)/intervalms > DEFAULT_DATAPOINT_MAX_COUNT){
-//			throw new IllegalArgumentException("invalid argument, # of datapoints should be less than " + DEFAULT_DATAPOINT_MAX_COUNT + ", current # of datapoints is " + (endTime-startTime)/intervalms);
-//		}
-//	}
-	
-	public void accumulate(TaggedLogAPIEntity entity) throws Exception{
-		List<String> groupbyFieldValues = createGroup(entity);
-		// TODO: make sure timestamp be in range of this.startTime to this.endTime in outer side
-		// guard the time range to avoid to accumulate entities whose timestamp is bigger than endTime
-		if(entity.getTimestamp() >= this.endTime || entity.getTimestamp() < this.startTime){
-			if(LOG.isDebugEnabled()) LOG.debug("Ignore in-coming entity whose timestamp > endTime or < startTime, timestamp: " + entity.getTimestamp() + ", startTime:" + startTime + ", endTime:" + endTime);
-			this.ignoredEntityCounter ++;
-			return;
-		}
-		// time series bucket index
-		long located =(entity.getTimestamp() - startTime)/intervalms; 
-		groupbyFieldValues.add(String.valueOf(located));
-		List<Double> preAggregatedValues = createPreAggregatedValues(entity);
-		bucket.addDatapoint(groupbyFieldValues, preAggregatedValues);
-	}
-	
-	public Map<List<String>, List<Double>> result(){
-		if(this.ignoredEntityCounter > 0)
-			LOG.warn("Ignored "+this.ignoredEntityCounter+" entities for reason: timestamp > "+this.endTime+" or < "+this.startTime);
-		return bucket.result();
-	}
+    public TimeSeriesAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields,
+                                long startTime, long endTime, long intervalms) {
+        super(groupbyFields, aggregateFuntionTypes, aggregatedFields);
+        // guard to avoid too many data points returned
+        //      validateTimeRange(startTime, endTime, intervalms);
+        this.startTime = startTime;
+        this.endTime = endTime;
+        this.intervalms = intervalms;
+        this.numFunctions = aggregateFuntionTypes.size();
+    }
 
-	/**
-	 * Support new aggregate result
-	 *
-	 * @return
-	 */
-	@Override
-	public List<GroupbyKeyValue> getGroupbyKeyValues(){
-		if(this.ignoredEntityCounter > 0)
-			LOG.warn("Ignored "+this.ignoredEntityCounter+" entities for reason: timestamp > "+this.endTime+" or < "+this.startTime);
-		return bucket.getGroupbyKeyValue();
-	}
-	
-	public Map<List<String>, List<double[]>> getMetric(){
-		// groupbyfields+timeseriesbucket --> aggregatedvalues for different function
-		Map<List<String>, List<Double>> result = bucket.result();
-//		Map<List<String>, List<double[]>> timeseriesDatapoints = new HashMap<List<String>, List<double[]>>();
-//		/**
-//		 * bug fix: startTime is inclusive and endTime is exclusive
-//		 */
-////		int numDatapoints =(int)((endTime-startTime)/intervalms + 1);
-//		int numDatapoints =(int)((endTime-1-startTime)/intervalms + 1);
-//		for(Map.Entry<List<String>, List<Double>> entry : result.entrySet()){
-//			// get groups
-//			List<String> groupbyFields = entry.getKey();
-//			List<String> copy = new ArrayList<String>(groupbyFields);
-//			String strTimeseriesIndex = copy.remove(copy.size()-1);
-//			List<double[]> functionValues = timeseriesDatapoints.get(copy);
-//			if(functionValues == null){
-//				functionValues = new ArrayList<double[]>();
-//				timeseriesDatapoints.put(copy, functionValues);
-//				for(int i=0; i<numFunctions; i++){
-//					functionValues.add(new double[numDatapoints]);
-//				}
-//			}
-//			int timeseriesIndex = Integer.valueOf(strTimeseriesIndex);
-//			int functionIndex = 0;
-//			for(double[] values : functionValues){
-//				values[timeseriesIndex] = entry.getValue().get(functionIndex);
-//				functionIndex++;
-//			}
-//		}
-//		return timeseriesDatapoints;
-		return toMetric(result,(int)((endTime-1-startTime)/intervalms + 1),this.numFunctions);
-	}
+    //  @Deprecated
+    //  public static void validateTimeRange(long startTime, long endTime, long intervalms) {
+    //      if (startTime >= endTime || intervalms <= 0) {
+    //          throw new IllegalArgumentException("invalid argument, startTime should be less than endTime and "
+    //                + "interval must be greater than 0, starTime is " + startTime + " and endTime is " + endTime + ", interval is " + intervalms);
+    //      }
+    //      if ((endTime-startTime)/intervalms > DEFAULT_DATAPOINT_MAX_COUNT) {
+    //          throw new IllegalArgumentException("invalid argument, # of datapoints should be less than " + DEFAULT_DATAPOINT_MAX_COUNT
+    //                  + ", current # of datapoints is " + (endTime-startTime)/intervalms);
+    //      }
+    //  }
 
-	public static Map<List<String>, List<double[]>> toMetric(Map<List<String>, List<Double>> result,int numDatapoints,int numFunctions){
-		Map<List<String>, List<double[]>> timeseriesDatapoints = new HashMap<List<String>, List<double[]>>();
-		/**
-		 * bug fix: startTime is inclusive and endTime is exclusive
-		 */
-//		int numDatapoints =(int)((endTime-startTime)/intervalms + 1);
-//		int numDatapoints =(int)((endTime-1-startTime)/intervalms + 1);
-		for(Map.Entry<List<String>, List<Double>> entry : result.entrySet()){
-			// get groups
-			List<String> groupbyFields = entry.getKey();
-			List<String> copy = new ArrayList<String>(groupbyFields);
-			String strTimeseriesIndex = copy.remove(copy.size()-1);
-			List<double[]> functionValues = timeseriesDatapoints.get(copy);
-			if(functionValues == null){
-				functionValues = new ArrayList<double[]>();
-				timeseriesDatapoints.put(copy, functionValues);
-				for(int i=0; i<numFunctions; i++){
-					functionValues.add(new double[numDatapoints]);
-				}
-			}
-			int timeseriesIndex = Integer.valueOf(strTimeseriesIndex);
-			int functionIndex = 0;
-			for(double[] values : functionValues){
-				values[timeseriesIndex] = entry.getValue().get(functionIndex);
-				functionIndex++;
-			}
-		}
-		return timeseriesDatapoints;
-	}
+    public void accumulate(TaggedLogAPIEntity entity) throws Exception {
+        List<String> groupbyFieldValues = createGroup(entity);
+        // TODO: make sure timestamp be in range of this.startTime to this.endTime in outer side
+        // guard the time range to avoid to accumulate entities whose timestamp is bigger than endTime
+        if (entity.getTimestamp() >= this.endTime || entity.getTimestamp() < this.startTime) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Ignore in-coming entity whose timestamp > endTime or < startTime, timestamp: " + entity.getTimestamp() + ", startTime:" + startTime + ", endTime:" + endTime);
+            }
+            this.ignoredEntityCounter ++;
+            return;
+        }
+        // time series bucket index
+        long located = (entity.getTimestamp() - startTime) / intervalms;
+        groupbyFieldValues.add(String.valueOf(located));
+        List<Double> preAggregatedValues = createPreAggregatedValues(entity);
+        bucket.addDatapoint(groupbyFieldValues, preAggregatedValues);
+    }
+
+    public Map<List<String>, List<Double>> result() {
+        if (this.ignoredEntityCounter > 0) {
+            LOG.warn("Ignored " + this.ignoredEntityCounter + " entities for reason: timestamp > " + this.endTime + " or < " + this.startTime);
+        }
+        return bucket.result();
+    }
+
+    /**
+     * Support new aggregate result
+     *
+     * @return
+     */
+    @Override
+    public List<GroupbyKeyValue> getGroupbyKeyValues() {
+        if (this.ignoredEntityCounter > 0) {
+            LOG.warn("Ignored " + this.ignoredEntityCounter + " entities for reason: timestamp > " + this.endTime + " or < " + this.startTime);
+        }
+        return bucket.getGroupbyKeyValue();
+    }
+
+    public Map<List<String>, List<double[]>> getMetric() {
+        // groupbyfields+timeseriesbucket --> aggregatedvalues for different function
+        Map<List<String>, List<Double>> result = bucket.result();
+        //      Map<List<String>, List<double[]>> timeseriesDatapoints = new HashMap<List<String>, List<double[]>>();
+        //      /**
+        //       * bug fix: startTime is inclusive and endTime is exclusive
+        //       */
+        ////        int numDatapoints =(int)((endTime-startTime)/intervalms + 1);
+        //      int numDatapoints =(int)((endTime-1-startTime)/intervalms + 1);
+        //      for (Map.Entry<List<String>, List<Double>> entry : result.entrySet()) {
+        //          // get groups
+        //          List<String> groupbyFields = entry.getKey();
+        //          List<String> copy = new ArrayList<String>(groupbyFields);
+        //          String strTimeseriesIndex = copy.remove(copy.size()-1);
+        //          List<double[]> functionValues = timeseriesDatapoints.get(copy);
+        //          if (functionValues == null) {
+        //              functionValues = new ArrayList<double[]>();
+        //              timeseriesDatapoints.put(copy, functionValues);
+        //              for (int i = 0; i<numFunctions; i++) {
+        //                  functionValues.add(new double[numDatapoints]);
+        //              }
+        //          }
+        //          int timeseriesIndex = Integer.valueOf(strTimeseriesIndex);
+        //          int functionIndex = 0;
+        //          for (double[] values : functionValues) {
+        //              values[timeseriesIndex] = entry.getValue().get(functionIndex);
+        //              functionIndex++;
+        //          }
+        //      }
+        //      return timeseriesDatapoints;
+        return toMetric(result,(int)((endTime - 1 - startTime) / intervalms + 1), this.numFunctions);
+    }
+
+    public static Map<List<String>, List<double[]>> toMetric(Map<List<String>, List<Double>> result,int numDatapoints,int numFunctions) {
+        Map<List<String>, List<double[]>> timeseriesDatapoints = new HashMap<List<String>, List<double[]>>();
+        /**
+         * bug fix: startTime is inclusive and endTime is exclusive
+         */
+        //      int numDatapoints = (int)((endTime-startTime)/intervalms + 1);
+        //      int numDatapoints = (int)((endTime-1-startTime)/intervalms + 1);
+        for (Map.Entry<List<String>, List<Double>> entry : result.entrySet()) {
+            // get groups
+            List<String> groupbyFields = entry.getKey();
+            List<String> copy = new ArrayList<String>(groupbyFields);
+            String strTimeseriesIndex = copy.remove(copy.size() - 1);
+            List<double[]> functionValues = timeseriesDatapoints.get(copy);
+            if (functionValues == null) {
+                functionValues = new ArrayList<double[]>();
+                timeseriesDatapoints.put(copy, functionValues);
+                for (int i = 0; i < numFunctions; i++) {
+                    functionValues.add(new double[numDatapoints]);
+                }
+            }
+            int timeseriesIndex = Integer.valueOf(strTimeseriesIndex);
+            int functionIndex = 0;
+            for (double[] values : functionValues) {
+                values[timeseriesIndex] = entry.getValue().get(functionIndex);
+                functionIndex++;
+            }
+        }
+        return timeseriesDatapoints;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesBucket.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesBucket.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesBucket.java
index d662658..78fa010 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesBucket.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesBucket.java
@@ -26,51 +26,51 @@ import org.slf4j.LoggerFactory;
  * only numeric aggregation is supported and number type supported is double
  */
 public class TimeSeriesBucket {
-	private final static Logger LOG = LoggerFactory.getLogger(TimeSeriesBucket.class);
-	private long startTime;
-	private long endTime;
-	private long interval;
-	
-	// map of aggregation function to aggregated values 
-	List<double[]> aggregatedValues = new ArrayList<double[]>();
-	
-	// align from the startTime
-	/**
-	 * 
-	 * @param startTime milliseconds
-	 * @param endTime milliseconds
-	 * @param intervalMillseconds
-	 * @param aggFunctions
-	 */
-	public TimeSeriesBucket(long startTime, long endTime, long intervalms, int numAggFunctions){
-		int count =(int)((endTime-startTime)/intervalms);
-		for(int i=0; i<numAggFunctions; i++){
-			aggregatedValues.add(new double[count]);
-		}
-	}
-	
-	/**
-	 * add datapoint which has a list of values for different aggregate functions
-	 * for example, sum(numHosts), count(*), avg(timespan) etc
-	 * @param timestamp
-	 * @param values
-	 */
-	public void addDataPoint(long timestamp, List<Double> values){
-		// locate timeseries bucket
-		if(timestamp < startTime || timestamp > endTime){
-			LOG.warn("timestamp<startTime or timestamp>endTime, ignore this datapoint." + timestamp + "," + startTime + ":" + endTime);
-			return;
-		}
-		int located =(int)((timestamp - startTime)/interval);
-		int index = 0;
-		for(Double src : values){
-			double[] timeSeriesValues = aggregatedValues.get(index);
-			timeSeriesValues[located] += src;
-			index++;
-		}
-	}
-	
-	public List<double[]> aggregatedValues(){
-		return this.aggregatedValues;
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(TimeSeriesBucket.class);
+    private long startTime;
+    private long endTime;
+    private long interval;
+
+    // map of aggregation function to aggregated values
+    List<double[]> aggregatedValues = new ArrayList<double[]>();
+
+    // align from the startTime
+    /**
+     *
+     * @param startTime milliseconds
+     * @param endTime milliseconds
+     * @param intervalMillseconds
+     * @param aggFunctions
+     */
+    public TimeSeriesBucket(long startTime, long endTime, long intervalms, int numAggFunctions) {
+        int count = (int)((endTime - startTime) / intervalms);
+        for (int i = 0; i < numAggFunctions; i++) {
+            aggregatedValues.add(new double[count]);
+        }
+    }
+
+    /**
+     * add datapoint which has a list of values for different aggregate functions
+     * for example, sum(numHosts), count(*), avg(timespan) etc
+     * @param timestamp
+     * @param values
+     */
+    public void addDataPoint(long timestamp, List<Double> values) {
+        // locate timeseries bucket
+        if (timestamp < startTime || timestamp > endTime) {
+            LOG.warn("timestamp<startTime or timestamp>endTime, ignore this datapoint." + timestamp + "," + startTime + ":" + endTime);
+            return;
+        }
+        int located = (int)((timestamp - startTime) / interval);
+        int index = 0;
+        for (Double src : values) {
+            double[] timeSeriesValues = aggregatedValues.get(index);
+            timeSeriesValues[located] += src;
+            index++;
+        }
+    }
+
+    public List<double[]> aggregatedValues() {
+        return this.aggregatedValues;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesPostFlatAggregateSort.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesPostFlatAggregateSort.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesPostFlatAggregateSort.java
index c0a6e06..ae00fdf 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesPostFlatAggregateSort.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/TimeSeriesPostFlatAggregateSort.java
@@ -25,127 +25,127 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 
 public class TimeSeriesPostFlatAggregateSort {
-	// private static final Logger logger =
-	// LoggerFactory.getLogger(PostFlatAggregateSort.class);
-
-	private static SortedSet<Map.Entry<List<String>, List<Double>>> sortByValue(
-			Map<List<String>, List<Double>> mapForSort,
-			List<SortOption> sortOptions) {
-		SortedSet<Map.Entry<List<String>, List<Double>>> sortedEntries = new TreeSet<Map.Entry<List<String>, List<Double>>>(
-				new MapEntryComparator(sortOptions));
-		sortedEntries.addAll(mapForSort.entrySet());
-		return sortedEntries;
-	}
-
-	/**
-	 * sort aggregated results with sort options
-	 * 
-	 * @param entity
-	 */
-	public static List<Map.Entry<List<String>, List<double[]>>> sort(
-			Map<List<String>, List<Double>> mapForSort,
-			Map<List<String>, List<double[]>> valueMap,
-			List<SortOption> sortOptions, int topN) {
-
-		processIndex(sortOptions);
-		List<Map.Entry<List<String>, List<double[]>>> result = new ArrayList<Map.Entry<List<String>, List<double[]>>>();
-		SortedSet<Map.Entry<List<String>, List<Double>>> sortedSet = sortByValue(
-				mapForSort, sortOptions);
-		for (Map.Entry<List<String>, List<Double>> entry : sortedSet) {
-			List<String> key = entry.getKey();
-			List<double[]> value = valueMap.get(key);
-			if (value != null) {
-				Map.Entry<List<String>, List<double[]>> newEntry = new ImmutableEntry<List<String>, List<double[]>>(key, value);
-				result.add(newEntry);
-				if (topN > 0 && result.size() >= topN) {
-					break;
-				}
-			}
-		}
-		return result;
-	}
-
-	private static void processIndex(List<SortOption> sortOptions) {
-		for (int i = 0; i < sortOptions.size(); ++i) {
-			SortOption so = sortOptions.get(i);
-			so.setIndex(i);
-		}
-	}
-
-	private static class MapEntryComparator implements
-			Comparator<Map.Entry<List<String>, List<Double>>> {
-		private List<SortOption> sortOptions;
-
-		public MapEntryComparator(List<SortOption> sortOptions) {
-			this.sortOptions = sortOptions;
-		}
-
-		/**
-		 * default to sort by all groupby fields
-		 */
-		@Override
-		public int compare(Map.Entry<List<String>, List<Double>> e1,
-				Map.Entry<List<String>, List<Double>> e2) {
-			int r = 0;
-			List<String> keyList1 = e1.getKey();
-			List<Double> valueList1 = e1.getValue();
-			List<String> keyList2 = e2.getKey();
-			List<Double> valueList2 = e2.getValue();
-			for (SortOption so : sortOptions) {
-				int index = so.getIndex();
-				if (index == -1) {
-					continue;
-				}
-				if (!so.isInGroupby()) { // sort fields come from functions
-					Double value1 = valueList1.get(index);
-					Double value2 = valueList2.get(index);
-					r = value1.compareTo(value2);
-				} else { // sort fields come from groupby fields
-					String key1 = keyList1.get(index);
-					String key2 = keyList2.get(index);
-					r = key1.compareTo(key2);
-				}
-				if (r == 0)
-					continue;
-				if (!so.isAscendant()) {
-					r = -r;
-				}
-				return r;
-			}
-			// default to sort by groupby fields ascendently
-			if (r == 0) { // TODO is this check necessary
-				return new GroupbyFieldsComparator()
-						.compare(keyList1, keyList2);
-			}
-			return r;
-		}
-	}
-
-	static class ImmutableEntry<K, V> implements Map.Entry<K, V>, Serializable {
-		private final K key;
-		private final V value;
-
-		ImmutableEntry(K key, V value) {
-			this.key = key;
-			this.value = value;
-		}
-
-		@Override
-		public K getKey() {
-			return key;
-		}
-
-		@Override
-		public V getValue() {
-			return value;
-		}
-
-		@Override
-		public final V setValue(V value) {
-			throw new UnsupportedOperationException();
-		}
-
-		private static final long serialVersionUID = 0;
-	}
+    // private static final Logger logger =
+    // LoggerFactory.getLogger(PostFlatAggregateSort.class);
+
+    private static SortedSet<Map.Entry<List<String>, List<Double>>> sortByValue(
+                                                                                Map<List<String>, List<Double>> mapForSort,
+                                                                                List<SortOption> sortOptions) {
+        SortedSet<Map.Entry<List<String>, List<Double>>> sortedEntries = new TreeSet<Map.Entry<List<String>, List<Double>>>(
+            new MapEntryComparator(sortOptions));
+        sortedEntries.addAll(mapForSort.entrySet());
+        return sortedEntries;
+    }
+
+    /**
+     * sort aggregated results with sort options
+     *
+     * @param entity
+     */
+    public static List<Map.Entry<List<String>, List<double[]>>> sort(
+                                                                     Map<List<String>, List<Double>> mapForSort,
+                                                                     Map<List<String>, List<double[]>> valueMap,
+                                                                     List<SortOption> sortOptions, int topN) {
+
+        processIndex(sortOptions);
+        List<Map.Entry<List<String>, List<double[]>>> result = new ArrayList<Map.Entry<List<String>, List<double[]>>>();
+        SortedSet<Map.Entry<List<String>, List<Double>>> sortedSet = sortByValue(
+                                                                                 mapForSort, sortOptions);
+        for (Map.Entry<List<String>, List<Double>> entry : sortedSet) {
+            List<String> key = entry.getKey();
+            List<double[]> value = valueMap.get(key);
+            if (value != null) {
+                Map.Entry<List<String>, List<double[]>> newEntry = new ImmutableEntry<List<String>, List<double[]>>(key, value);
+                result.add(newEntry);
+                if (topN > 0 && result.size() >= topN) {
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+
+    private static void processIndex(List<SortOption> sortOptions) {
+        for (int i = 0; i < sortOptions.size(); ++i) {
+            SortOption so = sortOptions.get(i);
+            so.setIndex(i);
+        }
+    }
+
+    private static class MapEntryComparator implements Comparator<Map.Entry<List<String>, List<Double>>> {
+        private List<SortOption> sortOptions;
+
+        public MapEntryComparator(List<SortOption> sortOptions) {
+            this.sortOptions = sortOptions;
+        }
+
+        /**
+         * default to sort by all groupby fields
+         */
+        @Override
+        public int compare(Map.Entry<List<String>, List<Double>> e1,
+                           Map.Entry<List<String>, List<Double>> e2) {
+            int r = 0;
+            List<String> keyList1 = e1.getKey();
+            List<Double> valueList1 = e1.getValue();
+            List<String> keyList2 = e2.getKey();
+            List<Double> valueList2 = e2.getValue();
+            for (SortOption so : sortOptions) {
+                int index = so.getIndex();
+                if (index == -1) {
+                    continue;
+                }
+                if (!so.isInGroupby()) { // sort fields come from functions
+                    Double value1 = valueList1.get(index);
+                    Double value2 = valueList2.get(index);
+                    r = value1.compareTo(value2);
+                } else { // sort fields come from groupby fields
+                    String key1 = keyList1.get(index);
+                    String key2 = keyList2.get(index);
+                    r = key1.compareTo(key2);
+                }
+                if (r == 0) {
+                    continue;
+                }
+                if (!so.isAscendant()) {
+                    r = -r;
+                }
+                return r;
+            }
+            // default to sort by groupby fields ascendently
+            if (r == 0) { // TODO is this check necessary
+                return new GroupbyFieldsComparator()
+                    .compare(keyList1, keyList2);
+            }
+            return r;
+        }
+    }
+
+    static class ImmutableEntry<K, V> implements Map.Entry<K, V>, Serializable {
+        private final K key;
+        private final V value;
+
+        ImmutableEntry(K key, V value) {
+            this.key = key;
+            this.value = value;
+        }
+
+        @Override
+        public K getKey() {
+            return key;
+        }
+
+        @Override
+        public V getValue() {
+            return value;
+        }
+
+        @Override
+        public final V setValue(V value) {
+            throw new UnsupportedOperationException();
+        }
+
+        private static final long serialVersionUID = 0;
+    }
 
 }


[3/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
index 41bc18a..f329a7a 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
@@ -37,481 +37,482 @@ import org.apache.eagle.log.entity.meta.Qualifier;
 import org.apache.eagle.common.ByteUtil;
 
 public class TestRawAggregator {
-	private static final Logger LOG = LoggerFactory.getLogger(TestRawAggregator.class);
-	
-	private EntityDefinition ed;
-	@SuppressWarnings("unchecked")
-	@Before
-	public void setup(){
-		ed = new EntityDefinition();
-		Qualifier q = new Qualifier();
-		q.setDisplayName("numHosts");
-		q.setQualifierName("a");
-		EntitySerDeser<?> serDeser = new IntSerDeser();
-		q.setSerDeser((EntitySerDeser<Object>)(serDeser));
-		ed.getDisplayNameMap().put("numHosts", q);
-		q = new Qualifier();
-		q.setDisplayName("numClusters");
-		q.setQualifierName("b");
-		serDeser = new LongSerDeser();
-		q.setSerDeser((EntitySerDeser<Object>)(serDeser));
-		ed.getDisplayNameMap().put("numClusters", q);
-	}
-	
-	private Map<String, byte[]> createQualifiers(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters){
-		Map<String, byte[]> qualifiers = new HashMap<String, byte[]>();
-		qualifiers.put("cluster", cluster == null ? null : cluster.getBytes());
-		qualifiers.put("datacenter", datacenter == null ? null : datacenter.getBytes());
-		qualifiers.put("rack", rack == null ? null : rack.getBytes());
-		qualifiers.put("numHosts", ByteUtil.intToBytes(numHosts));
-		qualifiers.put("numClusters", ByteUtil.longToBytes(numClusters));
-		return qualifiers;
-	}
-
-	@Test
-	public void testZeroGroupbyFieldSingleFunctionForSummary(){
-		List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
-		entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
-		entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
-		entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-		
-		RawAggregator agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			
-			double total = 0.0;
-			for(Map<String, byte[]> e : entities){
-				int a = ByteUtil.bytesToInt(e.get("numHosts"));
-				total += a;
-			}
-			
-			Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			double total = 0.0;
-			for(Map<String, byte[]> e : entities){
-				long a = ByteUtil.bytesToLong(e.get("numClusters"));
-				total += a;
-			}
-			Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 1);
-			Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), 5, 0.0000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testSingleGroupbyFieldSingleFunctionForSummary(){
-		List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
-		entities.add(createQualifiers("cluster1", "dc2", "rack128", 10, 0));
-		entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
-		entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-		
-		RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			double total1 = 0.0;
-			total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			
-			double total2 = 0.0;
-			total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0).doubleValue(), total1, 0.0000000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.00000000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			double total1 = 0.0;
-			total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			total1 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			total1 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			
-			double total2 = 0.0;
-			total2 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.000000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			double total1 = 0.0;
-			total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
-			total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
-			total1 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
-			
-			double total2 = 0.0;
-			total2 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
-			total2 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
-			
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			double total1 = 0.0;
-			total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
-			total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
-			total1 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
-			total1 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
-			
-			double total2 = 0.0;
-			total2 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.00000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.00000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	
-	@Test
-	public void testSingleGroupbyFieldSingleFunctionForCount(){
-		List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
-		entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
-		entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
-		entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
-		
-		RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			double total1 = 0.0;
-			total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			
-			double total2 = 0.0;
-			total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(1), 0.00000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("can not aggregate", ex);
-			Assert.fail("can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testMultipleFieldsSingleFunctionForSummary(){
-		List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
-		entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
-		entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
-		entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-		entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
-		
-		RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(3, result.size());
-			double total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), total, 0.00000000000000000000000001);
-			
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
-			
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
-			
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), total, 0.0000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(5, result.size());
-			double total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), total, 0.0000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), total, 0.0000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), total, 0.0000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), total, 0.0000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), total, 0.0000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testMultipleFieldsSingleFunctionForCount(){
-		List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
-		entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
-		entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
-		entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-		entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
-		
-		RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(3, result.size());
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), (double)(3), 0.00000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(2), 0.0000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(1), 0.000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(5, result.size());
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), (double)(2), 0.0000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(1), 0.0000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(1), 0.0000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testSingleGroupbyFieldMultipleFunctions(){
-		List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
-		entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
-		entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
-		entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
-		
-		RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count), 
-				Arrays.asList("numHosts", "*"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			double total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total, 0.0000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(1), (double)(3), 0.00000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total, 0.0000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(1), (double)(2), 0.0000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum), Arrays.asList("*", "numHosts"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			double total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.00000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-		
-		agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum, AggregateFunctionType.sum), 
-				Arrays.asList("*", "numHosts", "numClusters"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 2);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000000000001);
-			double total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.0000000000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
-			total += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
-			total += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
-			total += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(2), total, 0.00000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(1), total, 0.00000000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
-			Assert.assertEquals(result.get(Arrays.asList("dc2")).get(2), total, 0.000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
-	
-	@Test
-	public void testMultipleGroupbyFieldsMultipleFunctions(){
-		List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
-		entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
-		entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
-		entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
-		entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-		
-		RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "rack"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count), 
-				Arrays.asList("numHosts", "*"), ed);
-		try{
-			for(Map<String, byte[]> e : entities){
-				agg.qualifierCreated(e);
-			}
-			Map<List<String>, List<Double>> result = agg.result();
-			Assert.assertEquals(result.size(), 4);
-			double total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
-			total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(0), total, 0.000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(1), (double)(2), 0.00000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(0), total, 0.00000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(1), (double)(1), 0.00000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(0), total, 0.000000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(1), (double)(1), 0.0000000000000000000000001);
-			total = 0.0;
-			total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(0), total, 0.00000000000000000000000001);
-			Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(1), (double)(1), 0.000000000000000000000000001);
-		}catch(Exception ex){
-			LOG.error("Can not aggregate", ex);
-			Assert.fail("Can not aggregate");
-		}
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(TestRawAggregator.class);
+
+    private EntityDefinition ed;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setup() {
+        ed = new EntityDefinition();
+        Qualifier q = new Qualifier();
+        q.setDisplayName("numHosts");
+        q.setQualifierName("a");
+        EntitySerDeser<?> serDeser = new IntSerDeser();
+        q.setSerDeser((EntitySerDeser<Object>)(serDeser));
+        ed.getDisplayNameMap().put("numHosts", q);
+        q = new Qualifier();
+        q.setDisplayName("numClusters");
+        q.setQualifierName("b");
+        serDeser = new LongSerDeser();
+        q.setSerDeser((EntitySerDeser<Object>)(serDeser));
+        ed.getDisplayNameMap().put("numClusters", q);
+    }
+
+    private Map<String, byte[]> createQualifiers(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters) {
+        Map<String, byte[]> qualifiers = new HashMap<String, byte[]>();
+        qualifiers.put("cluster", cluster == null ? null : cluster.getBytes());
+        qualifiers.put("datacenter", datacenter == null ? null : datacenter.getBytes());
+        qualifiers.put("rack", rack == null ? null : rack.getBytes());
+        qualifiers.put("numHosts", ByteUtil.intToBytes(numHosts));
+        qualifiers.put("numClusters", ByteUtil.longToBytes(numClusters));
+        return qualifiers;
+    }
+
+    @Test
+    public void testZeroGroupbyFieldSingleFunctionForSummary() {
+        List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+        entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+        entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+        entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+
+        RawAggregator agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+
+            double total = 0.0;
+            for (Map<String, byte[]> e : entities) {
+                int a = ByteUtil.bytesToInt(e.get("numHosts"));
+                total += a;
+            }
+
+            Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+            double total = 0.0;
+            for (Map<String, byte[]> e : entities) {
+                long a = ByteUtil.bytesToLong(e.get("numClusters"));
+                total += a;
+            }
+            Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 1);
+            Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), 5, 0.0000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testSingleGroupbyFieldSingleFunctionForSummary() {
+        List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+        entities.add(createQualifiers("cluster1", "dc2", "rack128", 10, 0));
+        entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+        entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+
+        RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            double total1 = 0.0;
+            total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+
+            double total2 = 0.0;
+            total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0).doubleValue(), total1, 0.0000000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.00000000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            double total1 = 0.0;
+            total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            total1 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            total1 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+
+            double total2 = 0.0;
+            total2 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.000000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            double total1 = 0.0;
+            total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
+            total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
+            total1 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
+
+            double total2 = 0.0;
+            total2 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
+            total2 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
+
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            double total1 = 0.0;
+            total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
+            total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
+            total1 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
+            total1 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
+
+            double total2 = 0.0;
+            total2 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.00000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.00000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+
+    @Test
+    public void testSingleGroupbyFieldSingleFunctionForCount() {
+        List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+        entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+        entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+        entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
+
+        RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            double total1 = 0.0;
+            total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+
+            double total2 = 0.0;
+            total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(1), 0.00000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("can not aggregate", ex);
+            Assert.fail("can not aggregate");
+        }
+    }
+
+    @Test
+    public void testMultipleFieldsSingleFunctionForSummary() {
+        List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+        entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+        entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+        entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+        entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
+
+        RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(3, result.size());
+            double total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), total, 0.00000000000000000000000001);
+
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
+
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
+
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), total, 0.0000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(5, result.size());
+            double total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), total, 0.0000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), total, 0.0000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), total, 0.0000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), total, 0.0000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), total, 0.0000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testMultipleFieldsSingleFunctionForCount() {
+        List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+        entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+        entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+        entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+        entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
+
+        RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(3, result.size());
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), (double)(3), 0.00000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(2), 0.0000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(1), 0.000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(5, result.size());
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), (double)(2), 0.0000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(1), 0.0000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(1), 0.0000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testSingleGroupbyFieldMultipleFunctions() {
+        List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+        entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+        entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+        entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
+
+        RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
+                                              Arrays.asList("numHosts", "*"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            double total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total, 0.0000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(1), (double)(3), 0.00000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total, 0.0000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(1), (double)(2), 0.0000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum), Arrays.asList("*", "numHosts"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            double total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.00000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+
+        agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum, AggregateFunctionType.sum),
+                                Arrays.asList("*", "numHosts", "numClusters"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 2);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000000000001);
+            double total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.0000000000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
+            total += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
+            total += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
+            total += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(2), total, 0.00000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(1), total, 0.00000000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
+            Assert.assertEquals(result.get(Arrays.asList("dc2")).get(2), total, 0.000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
+
+    @Test
+    public void testMultipleGroupbyFieldsMultipleFunctions() {
+        List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+        entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+        entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+        entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+        entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+
+        RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "rack"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
+                                              Arrays.asList("numHosts", "*"), ed);
+        try {
+            for (Map<String, byte[]> e : entities) {
+                agg.qualifierCreated(e);
+            }
+            Map<List<String>, List<Double>> result = agg.result();
+            Assert.assertEquals(result.size(), 4);
+            double total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+            total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(0), total, 0.000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(1), (double)(2), 0.00000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(0), total, 0.00000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(1), (double)(1), 0.00000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(0), total, 0.000000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(1), (double)(1), 0.0000000000000000000000001);
+            total = 0.0;
+            total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(0), total, 0.00000000000000000000000001);
+            Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(1), (double)(1), 0.000000000000000000000000001);
+        } catch (Exception ex) {
+            LOG.error("Can not aggregate", ex);
+            Assert.fail("Can not aggregate");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
index a304ea9..789ec17 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
@@ -19,8 +19,8 @@ package org.apache.eagle.query.aggregate.raw;
 import org.junit.Test;
 
 public class TestRawHBaseLogReaderAndAgg {
-	@Test
-	public void testRawReaderAndAgg(){
-		
-	}
+    @Test
+    public void testRawReaderAndAgg() {
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
index 4ae4b56..b7e8598 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
@@ -35,217 +35,217 @@ import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
 import org.apache.eagle.query.aggregate.Aggregator;
 
 public class TestAggregator {
-	private final static Logger LOG = LoggerFactory.getLogger(TestAggregator.class);
-	
-	public static class AggregatedSampleAPIEntityFactory implements AggregateAPIEntityFactory {
-		@Override
-		public AggregateAPIEntity create(){
-			return new AggregatedSampleAPIEntity();
-		}
-	}
-	
-	
-	public static class TestAPIEntity extends TaggedLogAPIEntity{
-		private String numTotalAlerts;
-		private String usedCapacity;
-		private String status;
-
-		public String getStatus() {
-			return status;
-		}
-
-		public void setStatus(String status) {
-			this.status = status;
-		}
-
-		public String getNumTotalAlerts() {
-			return numTotalAlerts;
-		}
-
-		public void setNumTotalAlerts(String numTotalAlerts) {
-			this.numTotalAlerts = numTotalAlerts;
-		}
-
-		public String getUsedCapacity() {
-			return usedCapacity;
-		}
-
-		public void setUsedCapacity(String usedCapacity) {
-			this.usedCapacity = usedCapacity;
-		}
-	}
-	
-
-
-	public static class AggregatedSampleAPIEntity extends AggregateAPIEntity{
-		private long numTotalAlerts;
-	
-		@JsonProperty("nTA")
-		public long getNumTotalAlerts() {
-			return numTotalAlerts;
-		}
-	
-		public void setNumTotalAlerts(long numTotalAlerts) {
-			this.numTotalAlerts = numTotalAlerts;
-		}
-	}
-	
-	@Test
-	public void testAggregate(){ 
-		try{
-			final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
-			List<String> sumFunctionFields = Arrays.asList("numTotalAlerts");
-			boolean counting = true;
-			List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "cluster");
-			List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
-			sortFieldOrders.add(new AggregateParams.SortFieldOrder("numTotalAlerts", false));
-			Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, sumFunctionFields);
-			List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
-			TestAPIEntity entity = new TestAPIEntity();
-			entity.setTags(new HashMap<String, String>());
-			entity.getTags().put("category", "checkHadoopFS");
-			entity.getTags().put("rack", "rack123");
-			entity.getTags().put("cluster", "cluster1");
-			entity.setNumTotalAlerts("123");
-			entity.setUsedCapacity("12.5");
-			entity.setStatus("live");
-			list.add(entity);
-	
-			TestAPIEntity entity2 = new TestAPIEntity();
-			entity2.setTags(new HashMap<String, String>());
-			entity2.getTags().put("category", "checkHadoopFS");
-			entity2.getTags().put("rack", "rack124");
-			entity2.getTags().put("cluster", "cluster2");
-			entity2.setNumTotalAlerts("35");
-			entity2.setUsedCapacity("32.1");
-			entity2.setStatus("dead");
-			list.add(entity2);
-			
-			TestAPIEntity entity3 = new TestAPIEntity();
-			entity3.setTags(new HashMap<String, String>());
-			entity3.getTags().put("category", "checkHadoopFS");
-	//		entity3.getTags().put("rack", "rack124");
-			entity3.getTags().put("cluster", "cluster2");
-			entity3.setNumTotalAlerts("11");
-			entity3.setUsedCapacity("82.11");
-			entity3.setStatus("live");
-			list.add(entity3);
-						
-			TestAPIEntity entity4 = new TestAPIEntity();
-			entity4.setTags(new HashMap<String, String>());
-			entity4.getTags().put("category", "diskfailure");
-			entity4.getTags().put("rack", "rack124");
-			entity4.getTags().put("cluster", "cluster2");
-			entity4.setNumTotalAlerts("61");
-			entity4.setUsedCapacity("253.2");
-			entity4.setStatus("dead");
-			list.add(entity4);
-			
-			long numTotalAlerts = 0;
-			for(TestAPIEntity e : list){
-				agg.accumulate(e);
-				numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
-			}
-
-			JsonFactory factory = new JsonFactory(); 
-			ObjectMapper mapper = new ObjectMapper(factory);
-			String result = null;
-			AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
-			result = mapper.writeValueAsString(toBeVerified);
-			
-			Assert.assertEquals(2, toBeVerified.getNumDirectDescendants());
-			Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
-			Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
-			
-	    	LOG.info(result);
-	    	
-	    	PostAggregateSorting.sort(root, sortFieldOrders);
-	    	toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
-			result = mapper.writeValueAsString(toBeVerified);
-	    	LOG.info(result);
-	    }catch(Exception ex){
-	    	LOG.error("Test aggregator fails", ex);
-	    	Assert.fail("Test aggregator fails");
-	    }
-	}
-	
-	@Test
-	public void testUnassigned(){ 
-		// rack is unassigned
-		try{
-			final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
-			boolean counting = true;
-			List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "rack");
-			List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
-			sortFieldOrders.add(new AggregateParams.SortFieldOrder("count", false));
-			sortFieldOrders.add(new AggregateParams.SortFieldOrder("key", false));
-			Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, new ArrayList<String>());
-			List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
-			TestAPIEntity entity = new TestAPIEntity();
-			entity.setTags(new HashMap<String, String>());
-			entity.getTags().put("category", "checkHadoopFS");
-			entity.getTags().put("rack", "rack123");
-			entity.getTags().put("cluster", "cluster1");
-			entity.setNumTotalAlerts("123");
-			entity.setUsedCapacity("12.5");
-			entity.setStatus("live");
-			list.add(entity);
-	
-			TestAPIEntity entity2 = new TestAPIEntity();
-			entity2.setTags(new HashMap<String, String>());
-			entity2.getTags().put("category", "checkHadoopFS");
-			entity2.getTags().put("rack", "rack124");
-			entity2.getTags().put("cluster", "cluster2");
-			entity2.setNumTotalAlerts("35");
-			entity2.setUsedCapacity("32.1");
-			entity2.setStatus("dead");
-			list.add(entity2);
-			
-			TestAPIEntity entity3 = new TestAPIEntity();
-			entity3.setTags(new HashMap<String, String>());
-			entity3.getTags().put("category", "checkHadoopFS");
-	//		entity3.getTags().put("rack", "rack124");
-			entity3.getTags().put("cluster", "cluster2");
-			entity3.setNumTotalAlerts("11");
-			entity3.setUsedCapacity("82.11");
-			entity3.setStatus("live");
-			list.add(entity3);
-						
-			TestAPIEntity entity4 = new TestAPIEntity();
-			entity4.setTags(new HashMap<String, String>());
-			entity4.getTags().put("category", "diskfailure");
-			entity4.getTags().put("rack", "rack124");
-			entity4.getTags().put("cluster", "cluster2");
-			entity4.setNumTotalAlerts("61");
-			entity4.setUsedCapacity("253.2");
-			entity4.setStatus("dead");
-			list.add(entity4);
-			
-//			long numTotalAlerts = 0;
-			for(TestAPIEntity e : list){
-				agg.accumulate(e);
-//				numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
-			}
-
-			JsonFactory factory = new JsonFactory(); 
-			ObjectMapper mapper = new ObjectMapper(factory);
-			String result = null;
-			AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
-			result = mapper.writeValueAsString(toBeVerified);
-			
-			Assert.assertEquals(3, toBeVerified.getNumDirectDescendants());
-			Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
-//			Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
-			
-	    	LOG.info(result);
-	    	
-	    	PostAggregateSorting.sort(root, sortFieldOrders);			
-	    	toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
-			result = mapper.writeValueAsString(toBeVerified);
-	    	LOG.info(result);
-	    }catch(Exception ex){
-	    	LOG.error("Test aggregator fails", ex);
-	    	Assert.fail("Test aggregator fails");
-	    }
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(TestAggregator.class);
+
+    public static class AggregatedSampleAPIEntityFactory implements AggregateAPIEntityFactory {
+        @Override
+        public AggregateAPIEntity create() {
+            return new AggregatedSampleAPIEntity();
+        }
+    }
+
+
+    public static class TestAPIEntity extends TaggedLogAPIEntity {
+        private String numTotalAlerts;
+        private String usedCapacity;
+        private String status;
+
+        public String getStatus() {
+            return status;
+        }
+
+        public void setStatus(String status) {
+            this.status = status;
+        }
+
+        public String getNumTotalAlerts() {
+            return numTotalAlerts;
+        }
+
+        public void setNumTotalAlerts(String numTotalAlerts) {
+            this.numTotalAlerts = numTotalAlerts;
+        }
+
+        public String getUsedCapacity() {
+            return usedCapacity;
+        }
+
+        public void setUsedCapacity(String usedCapacity) {
+            this.usedCapacity = usedCapacity;
+        }
+    }
+
+
+
+    public static class AggregatedSampleAPIEntity extends AggregateAPIEntity {
+        private long numTotalAlerts;
+
+        @JsonProperty("nTA")
+        public long getNumTotalAlerts() {
+            return numTotalAlerts;
+        }
+
+        public void setNumTotalAlerts(long numTotalAlerts) {
+            this.numTotalAlerts = numTotalAlerts;
+        }
+    }
+
+    @Test
+    public void testAggregate() {
+        try {
+            final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
+            List<String> sumFunctionFields = Arrays.asList("numTotalAlerts");
+            boolean counting = true;
+            List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "cluster");
+            List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
+            sortFieldOrders.add(new AggregateParams.SortFieldOrder("numTotalAlerts", false));
+            Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, sumFunctionFields);
+            List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
+            TestAPIEntity entity = new TestAPIEntity();
+            entity.setTags(new HashMap<String, String>());
+            entity.getTags().put("category", "checkHadoopFS");
+            entity.getTags().put("rack", "rack123");
+            entity.getTags().put("cluster", "cluster1");
+            entity.setNumTotalAlerts("123");
+            entity.setUsedCapacity("12.5");
+            entity.setStatus("live");
+            list.add(entity);
+
+            TestAPIEntity entity2 = new TestAPIEntity();
+            entity2.setTags(new HashMap<String, String>());
+            entity2.getTags().put("category", "checkHadoopFS");
+            entity2.getTags().put("rack", "rack124");
+            entity2.getTags().put("cluster", "cluster2");
+            entity2.setNumTotalAlerts("35");
+            entity2.setUsedCapacity("32.1");
+            entity2.setStatus("dead");
+            list.add(entity2);
+
+            TestAPIEntity entity3 = new TestAPIEntity();
+            entity3.setTags(new HashMap<String, String>());
+            entity3.getTags().put("category", "checkHadoopFS");
+            //		entity3.getTags().put("rack", "rack124");
+            entity3.getTags().put("cluster", "cluster2");
+            entity3.setNumTotalAlerts("11");
+            entity3.setUsedCapacity("82.11");
+            entity3.setStatus("live");
+            list.add(entity3);
+
+            TestAPIEntity entity4 = new TestAPIEntity();
+            entity4.setTags(new HashMap<String, String>());
+            entity4.getTags().put("category", "diskfailure");
+            entity4.getTags().put("rack", "rack124");
+            entity4.getTags().put("cluster", "cluster2");
+            entity4.setNumTotalAlerts("61");
+            entity4.setUsedCapacity("253.2");
+            entity4.setStatus("dead");
+            list.add(entity4);
+
+            long numTotalAlerts = 0;
+            for (TestAPIEntity e : list) {
+                agg.accumulate(e);
+                numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
+            }
+
+            JsonFactory factory = new JsonFactory();
+            ObjectMapper mapper = new ObjectMapper(factory);
+            String result = null;
+            AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
+            result = mapper.writeValueAsString(toBeVerified);
+
+            Assert.assertEquals(2, toBeVerified.getNumDirectDescendants());
+            Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
+            Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
+
+            LOG.info(result);
+
+            PostAggregateSorting.sort(root, sortFieldOrders);
+            toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
+            result = mapper.writeValueAsString(toBeVerified);
+            LOG.info(result);
+        } catch (Exception ex) {
+            LOG.error("Test aggregator fails", ex);
+            Assert.fail("Test aggregator fails");
+        }
+    }
+
+    @Test
+    public void testUnassigned() {
+        // rack is unassigned
+        try {
+            final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
+            boolean counting = true;
+            List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "rack");
+            List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
+            sortFieldOrders.add(new AggregateParams.SortFieldOrder("count", false));
+            sortFieldOrders.add(new AggregateParams.SortFieldOrder("key", false));
+            Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, new ArrayList<String>());
+            List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
+            TestAPIEntity entity = new TestAPIEntity();
+            entity.setTags(new HashMap<String, String>());
+            entity.getTags().put("category", "checkHadoopFS");
+            entity.getTags().put("rack", "rack123");
+            entity.getTags().put("cluster", "cluster1");
+            entity.setNumTotalAlerts("123");
+            entity.setUsedCapacity("12.5");
+            entity.setStatus("live");
+            list.add(entity);
+
+            TestAPIEntity entity2 = new TestAPIEntity();
+            entity2.setTags(new HashMap<String, String>());
+            entity2.getTags().put("category", "checkHadoopFS");
+            entity2.getTags().put("rack", "rack124");
+            entity2.getTags().put("cluster", "cluster2");
+            entity2.setNumTotalAlerts("35");
+            entity2.setUsedCapacity("32.1");
+            entity2.setStatus("dead");
+            list.add(entity2);
+
+            TestAPIEntity entity3 = new TestAPIEntity();
+            entity3.setTags(new HashMap<String, String>());
+            entity3.getTags().put("category", "checkHadoopFS");
+            //		entity3.getTags().put("rack", "rack124");
+            entity3.getTags().put("cluster", "cluster2");
+            entity3.setNumTotalAlerts("11");
+            entity3.setUsedCapacity("82.11");
+            entity3.setStatus("live");
+            list.add(entity3);
+
+            TestAPIEntity entity4 = new TestAPIEntity();
+            entity4.setTags(new HashMap<String, String>());
+            entity4.getTags().put("category", "diskfailure");
+            entity4.getTags().put("rack", "rack124");
+            entity4.getTags().put("cluster", "cluster2");
+            entity4.setNumTotalAlerts("61");
+            entity4.setUsedCapacity("253.2");
+            entity4.setStatus("dead");
+            list.add(entity4);
+
+            //			long numTotalAlerts = 0;
+            for (TestAPIEntity e : list) {
+                agg.accumulate(e);
+                //				numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
+            }
+
+            JsonFactory factory = new JsonFactory();
+            ObjectMapper mapper = new ObjectMapper(factory);
+            String result = null;
+            AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
+            result = mapper.writeValueAsString(toBeVerified);
+
+            Assert.assertEquals(3, toBeVerified.getNumDirectDescendants());
+            Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
+            //			Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
+
+            LOG.info(result);
+
+            PostAggregateSorting.sort(root, sortFieldOrders);
+            toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
+            result = mapper.writeValueAsString(toBeVerified);
+            LOG.info(result);
+        } catch (Exception ex) {
+            LOG.error("Test aggregator fails", ex);
+            Assert.fail("Test aggregator fails");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
index c2d0a26..630d7c1 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
@@ -23,34 +23,34 @@ import java.util.List;
 import org.junit.Test;
 
 public class TestAlertAggService {
-	@Test
-	public void testCompileAndSplitCondition(){
-		List<String> alertTagNameValues = new ArrayList<String>();
-		String tagNameValue1 = "cluster=cluster1";
-		String tagNameValue2 = "category=checkHadoopFS";
-		String tagNameValue3 = "category=highloadDisk";
-		String tagNameValue4 = "cluster=dc124";
-		String tagNameValue5 = "category=lowloadDisk";
-		alertTagNameValues.add(tagNameValue1);
-		alertTagNameValues.add(tagNameValue2);
-		alertTagNameValues.add(tagNameValue3);
-		alertTagNameValues.add(tagNameValue4);
-		alertTagNameValues.add(tagNameValue5);
-//		AlertAggResource r = new AlertAggResource();
-//		List<List<String>> result = r.compileAndSplitConditions(alertTagNameValues);
-//		Assert.assertEquals(result.size(), 3);
-//		Assert.assertEquals(result.get(0).size(), 3);
-//		Assert.assertTrue(result.get(0).contains(tagNameValue2));
-//		Assert.assertTrue(result.get(0).contains(tagNameValue1));
-//		Assert.assertTrue(result.get(0).contains(tagNameValue4));
-//		Assert.assertEquals(result.get(1).size(), 3);
-//		Assert.assertTrue(result.get(1).contains(tagNameValue3));
-//		Assert.assertTrue(result.get(1).contains(tagNameValue1));
-//		Assert.assertTrue(result.get(1).contains(tagNameValue4));
-//		Assert.assertEquals(result.get(2).size(), 3);
-//		Assert.assertTrue(result.get(2).contains(tagNameValue5));
-//		Assert.assertTrue(result.get(2).contains(tagNameValue1));
-//		Assert.assertTrue(result.get(2).contains(tagNameValue4));
-	}
+    @Test
+    public void testCompileAndSplitCondition() {
+        List<String> alertTagNameValues = new ArrayList<String>();
+        String tagNameValue1 = "cluster = cluster1";
+        String tagNameValue2 = "category = checkHadoopFS";
+        String tagNameValue3 = "category = highloadDisk";
+        String tagNameValue4 = "cluster = dc124";
+        String tagNameValue5 = "category = lowloadDisk";
+        alertTagNameValues.add(tagNameValue1);
+        alertTagNameValues.add(tagNameValue2);
+        alertTagNameValues.add(tagNameValue3);
+        alertTagNameValues.add(tagNameValue4);
+        alertTagNameValues.add(tagNameValue5);
+        //		AlertAggResource r = new AlertAggResource();
+        //		List<List<String>> result = r.compileAndSplitConditions(alertTagNameValues);
+        //		Assert.assertEquals(result.size(), 3);
+        //		Assert.assertEquals(result.get(0).size(), 3);
+        //		Assert.assertTrue(result.get(0).contains(tagNameValue2));
+        //		Assert.assertTrue(result.get(0).contains(tagNameValue1));
+        //		Assert.assertTrue(result.get(0).contains(tagNameValue4));
+        //		Assert.assertEquals(result.get(1).size(), 3);
+        //		Assert.assertTrue(result.get(1).contains(tagNameValue3));
+        //		Assert.assertTrue(result.get(1).contains(tagNameValue1));
+        //		Assert.assertTrue(result.get(1).contains(tagNameValue4));
+        //		Assert.assertEquals(result.get(2).size(), 3);
+        //		Assert.assertTrue(result.get(2).contains(tagNameValue5));
+        //		Assert.assertTrue(result.get(2).contains(tagNameValue1));
+        //		Assert.assertTrue(result.get(2).contains(tagNameValue4));
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
index e44d73b..5e986ac 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
@@ -29,128 +29,128 @@ import java.util.List;
 import java.util.Map;
 
 public class TestBucketQuery {
-	private static class SampleTaggedLogAPIEntity extends TaggedLogAPIEntity{
-		private String description;
-
-		@SuppressWarnings("unused")
-		public String getDescription() {
-			return description;
-		}
-
-		public void setDescription(String description) {
-			this.description = description;
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-	@Test
-	public void testBucketQuery(){
-		SampleTaggedLogAPIEntity e1 = new SampleTaggedLogAPIEntity();
-		e1.setTags(new HashMap<String, String>());
-		e1.getTags().put("cluster", "cluster1");
-		e1.getTags().put("rack", "rack123");
-		e1.setDescription("this is description 1");
-		
-		SampleTaggedLogAPIEntity e2 = new SampleTaggedLogAPIEntity();
-		e2.setTags(new HashMap<String, String>());
-		e2.getTags().put("cluster", "cluster1");
-		e2.getTags().put("rack", "rack123");
-		e2.setDescription("this is description 2");
-		
-		List<String> bucketFields = new ArrayList<String>();
-		bucketFields.add("cluster");
-		int limit = 1;
-		
-		BucketQuery query1 = new BucketQuery(bucketFields, limit);
-		query1.put(e1);
-		query1.put(e2);
-		
-		Map<String, Object> map = query1.get();
-		
-		List<TaggedLogAPIEntity> o = (List<TaggedLogAPIEntity>)map.get("cluster1");
-		Assert.assertEquals(limit, o.size());
-		
-		JsonFactory factory = new JsonFactory();
-		ObjectMapper mapper = new ObjectMapper(factory);
-		mapper.setFilters(TaggedLogAPIEntity.getFilterProvider());
-		try{
-			String result = mapper.writeValueAsString(map);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-		
-		limit = 2;
-		BucketQuery query2 = new BucketQuery(bucketFields, limit);
-		query2.put(e1);
-		query2.put(e2);
-		Map<String, Object> map2 = query2.get();
-		o = (List<TaggedLogAPIEntity>)map2.get("cluster1");
-		try{
-			String result = mapper.writeValueAsString(map2);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-		Assert.assertEquals(limit, o.size());
-		
-		
-		SampleTaggedLogAPIEntity e3 = new SampleTaggedLogAPIEntity();
-		e3.setTags(new HashMap<String, String>());
-		e3.getTags().put("cluster", "cluster1");
-		e3.getTags().put("rack", "rack124");
-		e3.setDescription("this is description 3");
-		bucketFields.add("rack");
-		limit = 2;
-		BucketQuery query3 = new BucketQuery(bucketFields, limit);
-		query3.put(e1);
-		query3.put(e2);
-		query3.put(e3);
-		Map<String, Object> map3 = query3.get();
-		Map<String, Object> o3 = (Map<String, Object>)map3.get("cluster1");
-		List<TaggedLogAPIEntity> o4 = (List<TaggedLogAPIEntity>)o3.get("rack124");
-		Assert.assertEquals(1, o4.size());
-		List<TaggedLogAPIEntity> o5 = (List<TaggedLogAPIEntity>)o3.get("rack123");
-		Assert.assertEquals(o5.size(), 2);
-		
-		try{
-			String result = mapper.writeValueAsString(map3);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-		
-		
-		SampleTaggedLogAPIEntity e4 = new SampleTaggedLogAPIEntity();
-		e4.setTags(new HashMap<String, String>());
-		e4.getTags().put("cluster", "cluster1");
-		// rack is set to null
-//		e4.getTags().put("rack", "rack124");
-		e4.setDescription("this is description 3");
-		limit = 2;
-		BucketQuery query4 = new BucketQuery(bucketFields, limit);
-		query4.put(e1);
-		query4.put(e2);
-		query4.put(e3);
-		query4.put(e4);
-		Map<String, Object> map4 = query4.get();
-		Map<String, Object> o6 = (Map<String, Object>)map4.get("cluster1");
-		List<TaggedLogAPIEntity> o7 = (List<TaggedLogAPIEntity>)o6.get("rack124");
-		Assert.assertEquals(1, o7.size());
-		List<TaggedLogAPIEntity> o8 = (List<TaggedLogAPIEntity>)o6.get("rack123");
-		Assert.assertEquals(o8.size(), 2);
-		List<TaggedLogAPIEntity> o9 = (List<TaggedLogAPIEntity>)o6.get("unassigned");
-		Assert.assertEquals(o9.size(), 1);
-		
-		try{
-			String result = mapper.writeValueAsString(map4);
-			System.out.println(result);
-		}catch(Exception ex){
-			ex.printStackTrace();
-			Assert.fail("can not serialize bucket query result");
-		}
-	}
+    private static class SampleTaggedLogAPIEntity extends TaggedLogAPIEntity {
+        private String description;
+
+        @SuppressWarnings("unused")
+        public String getDescription() {
+            return description;
+        }
+
+        public void setDescription(String description) {
+            this.description = description;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testBucketQuery() {
+        SampleTaggedLogAPIEntity e1 = new SampleTaggedLogAPIEntity();
+        e1.setTags(new HashMap<String, String>());
+        e1.getTags().put("cluster", "cluster1");
+        e1.getTags().put("rack", "rack123");
+        e1.setDescription("this is description 1");
+
+        SampleTaggedLogAPIEntity e2 = new SampleTaggedLogAPIEntity();
+        e2.setTags(new HashMap<String, String>());
+        e2.getTags().put("cluster", "cluster1");
+        e2.getTags().put("rack", "rack123");
+        e2.setDescription("this is description 2");
+
+        List<String> bucketFields = new ArrayList<String>();
+        bucketFields.add("cluster");
+        int limit = 1;
+
+        BucketQuery query1 = new BucketQuery(bucketFields, limit);
+        query1.put(e1);
+        query1.put(e2);
+
+        Map<String, Object> map = query1.get();
+
+        List<TaggedLogAPIEntity> o = (List<TaggedLogAPIEntity>)map.get("cluster1");
+        Assert.assertEquals(limit, o.size());
+
+        JsonFactory factory = new JsonFactory();
+        ObjectMapper mapper = new ObjectMapper(factory);
+        mapper.setFilters(TaggedLogAPIEntity.getFilterProvider());
+        try {
+            String result = mapper.writeValueAsString(map);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+
+        limit = 2;
+        BucketQuery query2 = new BucketQuery(bucketFields, limit);
+        query2.put(e1);
+        query2.put(e2);
+        Map<String, Object> map2 = query2.get();
+        o = (List<TaggedLogAPIEntity>)map2.get("cluster1");
+        try {
+            String result = mapper.writeValueAsString(map2);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+        Assert.assertEquals(limit, o.size());
+
+
+        SampleTaggedLogAPIEntity e3 = new SampleTaggedLogAPIEntity();
+        e3.setTags(new HashMap<String, String>());
+        e3.getTags().put("cluster", "cluster1");
+        e3.getTags().put("rack", "rack124");
+        e3.setDescription("this is description 3");
+        bucketFields.add("rack");
+        limit = 2;
+        BucketQuery query3 = new BucketQuery(bucketFields, limit);
+        query3.put(e1);
+        query3.put(e2);
+        query3.put(e3);
+        Map<String, Object> map3 = query3.get();
+        Map<String, Object> o3 = (Map<String, Object>)map3.get("cluster1");
+        List<TaggedLogAPIEntity> o4 = (List<TaggedLogAPIEntity>)o3.get("rack124");
+        Assert.assertEquals(1, o4.size());
+        List<TaggedLogAPIEntity> o5 = (List<TaggedLogAPIEntity>)o3.get("rack123");
+        Assert.assertEquals(o5.size(), 2);
+
+        try {
+            String result = mapper.writeValueAsString(map3);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+
+
+        SampleTaggedLogAPIEntity e4 = new SampleTaggedLogAPIEntity();
+        e4.setTags(new HashMap<String, String>());
+        e4.getTags().put("cluster", "cluster1");
+        // rack is set to null
+        //		e4.getTags().put("rack", "rack124");
+        e4.setDescription("this is description 3");
+        limit = 2;
+        BucketQuery query4 = new BucketQuery(bucketFields, limit);
+        query4.put(e1);
+        query4.put(e2);
+        query4.put(e3);
+        query4.put(e4);
+        Map<String, Object> map4 = query4.get();
+        Map<String, Object> o6 = (Map<String, Object>)map4.get("cluster1");
+        List<TaggedLogAPIEntity> o7 = (List<TaggedLogAPIEntity>)o6.get("rack124");
+        Assert.assertEquals(1, o7.size());
+        List<TaggedLogAPIEntity> o8 = (List<TaggedLogAPIEntity>)o6.get("rack123");
+        Assert.assertEquals(o8.size(), 2);
+        List<TaggedLogAPIEntity> o9 = (List<TaggedLogAPIEntity>)o6.get("unassigned");
+        Assert.assertEquals(o9.size(), 1);
+
+        try {
+            String result = mapper.writeValueAsString(map4);
+            System.out.println(result);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            Assert.fail("can not serialize bucket query result");
+        }
+    }
 }


[6/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the eagle-query-base module

Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/IllegalAggregateFieldTypeException.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/IllegalAggregateFieldTypeException.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/IllegalAggregateFieldTypeException.java
index 3e3e739..05f7fb8 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/IllegalAggregateFieldTypeException.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/IllegalAggregateFieldTypeException.java
@@ -16,13 +16,14 @@
  */
 package org.apache.eagle.query.aggregate;
 
-public class IllegalAggregateFieldTypeException extends RuntimeException{
-	static final long serialVersionUID = -4548788354899625887L;
-	public IllegalAggregateFieldTypeException(){
-		super();
-	}
-	
-	public IllegalAggregateFieldTypeException(String message){
-		super(message + ", only count and sum are support");
-	}
+public class IllegalAggregateFieldTypeException extends RuntimeException {
+    static final long serialVersionUID = -4548788354899625887L;
+
+    public IllegalAggregateFieldTypeException() {
+        super();
+    }
+
+    public IllegalAggregateFieldTypeException(String message) {
+        super(message + ", only count and sum are support");
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/PostAggregateSorting.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/PostAggregateSorting.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/PostAggregateSorting.java
index b801255..d27e10e 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/PostAggregateSorting.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/PostAggregateSorting.java
@@ -27,75 +27,79 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PostAggregateSorting {
-	private static final Logger LOG = LoggerFactory.getLogger(PostAggregateSorting.class);
-	
-	private static SortedSet<Map.Entry<String, AggregateAPIEntity>> sortByValue(Map<String, AggregateAPIEntity> map, List<AggregateParams.SortFieldOrder> sortedFields) {
-	    SortedSet<Map.Entry<String, AggregateAPIEntity>> sortedEntries = new TreeSet<Map.Entry<String, AggregateAPIEntity>>(new MapKeyValueComparator(sortedFields));
-	    sortedEntries.addAll(map.entrySet());
-	    return sortedEntries;
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(PostAggregateSorting.class);
 
-	/**
-	 * recursively populate sorted list from entity list
-	 * @param entity
-	 */
-	public static void sort(AggregateAPIEntity entity, List<AggregateParams.SortFieldOrder> sortFieldOrders){
-		// sort should internally add key field to AggregateAPIEntity before the sorting starts as "key" could be sorted against
-		Map<String, AggregateAPIEntity> children = entity.getEntityList();
-		for(Map.Entry<String, AggregateAPIEntity> e : children.entrySet()){
-			e.getValue().setKey(e.getKey());
-		}
-		SortedSet<Map.Entry<String, AggregateAPIEntity>> set = sortByValue(children, sortFieldOrders);
-		for(Map.Entry<String, AggregateAPIEntity> entry : set){
-			entity.getSortedList().add(entry.getValue());
-		}
-		for(Map.Entry<String, AggregateAPIEntity> entry : entity.getEntityList().entrySet()){
-			sort(entry.getValue(), sortFieldOrders);
-		}
-		entity.setEntityList(null);
-	}
+    private static SortedSet<Map.Entry<String, AggregateAPIEntity>> sortByValue(Map<String, AggregateAPIEntity> map, List<AggregateParams.SortFieldOrder> sortedFields) {
+        SortedSet<Map.Entry<String, AggregateAPIEntity>> sortedEntries = new TreeSet<Map.Entry<String, AggregateAPIEntity>>(new MapKeyValueComparator(sortedFields));
+        sortedEntries.addAll(map.entrySet());
+        return sortedEntries;
+    }
 
-	private static class MapKeyValueComparator implements Comparator<Map.Entry<String, AggregateAPIEntity>>{
-		private List<AggregateParams.SortFieldOrder> sortedFieldOrders;
-		public MapKeyValueComparator(List<AggregateParams.SortFieldOrder> sortedFields){
-			this.sortedFieldOrders = sortedFields;
-		}
-		@Override
-        public int compare(Map.Entry<String, AggregateAPIEntity> e1, Map.Entry<String, AggregateAPIEntity> e2){
-			int r = 0;
-			AggregateAPIEntity entity1 = e1.getValue();
-			AggregateAPIEntity entity2 = e2.getValue();
-            for(AggregateParams.SortFieldOrder sortFieldOrder : sortedFieldOrders){
-            	// TODO count should not be literal, compare numTotalDescendants
-            	if(sortFieldOrder.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_COUNT)){
-            		long tmp = entity1.getNumTotalDescendants() - entity2.getNumTotalDescendants();
-            		r = (tmp == 0) ? 0 : ((tmp > 0) ? 1 : -1);
-            	}else if(sortFieldOrder.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_AGGREGATE_KEY)){
-            		r = entity1.getKey().compareTo(entity2.getKey());
-            	}else{
-            		try{
-	            		String sortedField = sortFieldOrder.getField();
-	            		String tmp1 = sortedField.substring(0, 1).toUpperCase()+sortedField.substring(1);
-	            		Method getMethod1 = entity1.getClass().getMethod("get"+tmp1);
-	            		Object r1 = getMethod1.invoke(entity1);
-	            		Long comp1 = (Long)r1;
-	            		String tmp2 = sortedField.substring(0, 1).toUpperCase()+sortedField.substring(1);
-	            		Method getMethod2 = entity2.getClass().getMethod("get"+tmp2);
-	            		Object r2 = getMethod2.invoke(entity2);
-	            		Long comp2 = (Long)r2;
-	            		r = comp1.compareTo(comp2);
-            		}catch(Exception ex){
-            			LOG.error("Can not get corresponding field for sorting", ex);
-            			r = 0;
-            		}
-            	}
-            	if(r == 0) continue;
-        		if(!sortFieldOrder.isAscendant()){
-        			r = -r;
-        		}
-    			return r;
-            }	
-			return r;
+    /**
+     * recursively populate sorted list from entity list
+     * @param entity
+     */
+    public static void sort(AggregateAPIEntity entity, List<AggregateParams.SortFieldOrder> sortFieldOrders) {
+        // sort should internally add key field to AggregateAPIEntity before the sorting starts as "key" could be sorted against
+        Map<String, AggregateAPIEntity> children = entity.getEntityList();
+        for (Map.Entry<String, AggregateAPIEntity> e : children.entrySet()) {
+            e.getValue().setKey(e.getKey());
         }
-	}
+        SortedSet<Map.Entry<String, AggregateAPIEntity>> set = sortByValue(children, sortFieldOrders);
+        for (Map.Entry<String, AggregateAPIEntity> entry : set) {
+            entity.getSortedList().add(entry.getValue());
+        }
+        for (Map.Entry<String, AggregateAPIEntity> entry : entity.getEntityList().entrySet()) {
+            sort(entry.getValue(), sortFieldOrders);
+        }
+        entity.setEntityList(null);
+    }
+
+    private static class MapKeyValueComparator implements Comparator<Map.Entry<String, AggregateAPIEntity>> {
+        private List<AggregateParams.SortFieldOrder> sortedFieldOrders;
+
+        public MapKeyValueComparator(List<AggregateParams.SortFieldOrder> sortedFields) {
+            this.sortedFieldOrders = sortedFields;
+        }
+
+        @Override
+        public int compare(Map.Entry<String, AggregateAPIEntity> e1, Map.Entry<String, AggregateAPIEntity> e2) {
+            int r = 0;
+            AggregateAPIEntity entity1 = e1.getValue();
+            AggregateAPIEntity entity2 = e2.getValue();
+            for (AggregateParams.SortFieldOrder sortFieldOrder : sortedFieldOrders) {
+                // TODO count should not be literal, compare numTotalDescendants
+                if (sortFieldOrder.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_COUNT)) {
+                    long tmp = entity1.getNumTotalDescendants() - entity2.getNumTotalDescendants();
+                    r = (tmp == 0) ? 0 : ((tmp > 0) ? 1 : -1);
+                } else if (sortFieldOrder.getField().equals(AggregateParams.SortFieldOrder.SORT_BY_AGGREGATE_KEY)) {
+                    r = entity1.getKey().compareTo(entity2.getKey());
+                } else {
+                    try {
+                        String sortedField = sortFieldOrder.getField();
+                        String tmp1 = sortedField.substring(0, 1).toUpperCase() + sortedField.substring(1);
+                        Method getMethod1 = entity1.getClass().getMethod("get" + tmp1);
+                        Object r1 = getMethod1.invoke(entity1);
+                        Long comp1 = (Long)r1;
+                        String tmp2 = sortedField.substring(0, 1).toUpperCase() + sortedField.substring(1);
+                        Method getMethod2 = entity2.getClass().getMethod("get" + tmp2);
+                        Object r2 = getMethod2.invoke(entity2);
+                        Long comp2 = (Long)r2;
+                        r = comp1.compareTo(comp2);
+                    } catch (Exception ex) {
+                        LOG.error("Can not get corresponding field for sorting", ex);
+                        r = 0;
+                    }
+                }
+                if (r == 0) {
+                    continue;
+                }
+                if (!sortFieldOrder.isAscendant()) {
+                    r = -r;
+                }
+                return r;
+            }
+            return r;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderType.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderType.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderType.java
index 6d47c7f..30a51d6 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderType.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderType.java
@@ -20,40 +20,41 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public enum SortFieldOrderType {
-	key("^(key)=(asc|desc)$"),
-	count("^(count)=(asc|desc)$"),
-	sum("^sum\\((.*)\\)=(asc|desc)$"),
-	avg("^avg\\((.*)\\)(asc|desc)$"),
-	max("^max\\((.*)\\)(asc|desc)$"),
-	min("^min\\((.*)\\)(asc|desc)$");
-	
-	private Pattern pattern;
-	private SortFieldOrderType(String patternString){
-		this.pattern = Pattern.compile(patternString);
-	}
+    key("^(key)=(asc|desc)$"),
+    count("^(count)=(asc|desc)$"),
+    sum("^sum\\((.*)\\)=(asc|desc)$"),
+    avg("^avg\\((.*)\\)(asc|desc)$"),
+    max("^max\\((.*)\\)(asc|desc)$"),
+    min("^min\\((.*)\\)(asc|desc)$");
 
-	/**
-	 * This method is thread safe
-	 * match and retrieve back the aggregated fields, for count, aggregateFields can be null
-	 * @param sortFieldOrder
-	 * @return
-	 */
-	public SortFieldOrderTypeMatcher matcher(String sortFieldOrder){
-		Matcher m = pattern.matcher(sortFieldOrder);
-		
-		if(m.find()){
-			return new SortFieldOrderTypeMatcher(true, m.group(1), m.group(2));
-		}else{
-			return new SortFieldOrderTypeMatcher(false, null, null);
-		}
-	}
-	
-	public static AggregateParams.SortFieldOrder matchAll(String sortFieldOrder){
-		for(SortFieldOrderType type : SortFieldOrderType.values()){
-			SortFieldOrderTypeMatcher m = type.matcher(sortFieldOrder);
-			if(m.find())
-				return m.sortFieldOrder();
-		}
-		return null;
-	}
+    private Pattern pattern;
+    private SortFieldOrderType(String patternString) {
+        this.pattern = Pattern.compile(patternString);
+    }
+
+    /**
+     * This method is thread safe
+     * match and retrieve back the aggregated fields, for count, aggregateFields can be null
+     * @param sortFieldOrder
+     * @return
+     */
+    public SortFieldOrderTypeMatcher matcher(String sortFieldOrder) {
+        Matcher m = pattern.matcher(sortFieldOrder);
+
+        if (m.find()) {
+            return new SortFieldOrderTypeMatcher(true, m.group(1), m.group(2));
+        } else {
+            return new SortFieldOrderTypeMatcher(false, null, null);
+        }
+    }
+
+    public static AggregateParams.SortFieldOrder matchAll(String sortFieldOrder) {
+        for (SortFieldOrderType type : SortFieldOrderType.values()) {
+            SortFieldOrderTypeMatcher m = type.matcher(sortFieldOrder);
+            if (m.find()) {
+                return m.sortFieldOrder();
+            }
+        }
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderTypeMatcher.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderTypeMatcher.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderTypeMatcher.java
index 0b4d408..8ef5c28 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderTypeMatcher.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/SortFieldOrderTypeMatcher.java
@@ -18,21 +18,21 @@ package org.apache.eagle.query.aggregate;
 
 
 public class SortFieldOrderTypeMatcher {
-	private boolean matched;
-	private AggregateParams.SortFieldOrder sortFieldOrder;
+    private boolean matched;
+    private AggregateParams.SortFieldOrder sortFieldOrder;
 
-	public SortFieldOrderTypeMatcher(boolean matched, String field, String order){
-		this.matched = matched;
-		if(matched){
-			this.sortFieldOrder = new AggregateParams.SortFieldOrder(field, order.equals("asc"));
-		}
-	}
-	
-	public boolean find(){
-		return this.matched;
-	}
-	
-	public AggregateParams.SortFieldOrder sortFieldOrder(){
-		return this.sortFieldOrder;
-	}
+    public SortFieldOrderTypeMatcher(boolean matched, String field, String order) {
+        this.matched = matched;
+        if (matched) {
+            this.sortFieldOrder = new AggregateParams.SortFieldOrder(field, order.equals("asc"));
+        }
+    }
+
+    public boolean find() {
+        return this.matched;
+    }
+
+    public AggregateParams.SortFieldOrder sortFieldOrder() {
+        return this.sortFieldOrder;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/Function.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/Function.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/Function.java
index 83c683c..90abf2c 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/Function.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/Function.java
@@ -16,91 +16,112 @@
  */
 package org.apache.eagle.query.aggregate.raw;
 
-public abstract class Function{
-	private int count = 0;
-	protected void incrCount(int num){ count += num; }
-	public int count(){ return count; }
-	public abstract void run(double v,int count);
-	public void run(double v){ run(v,1); }
-	public abstract double result();
-
-	public static class Avg extends Function {
-		private double total;
-		public Avg(){
-			this.total = 0.0;
-		}
-		@Override
-		public void run(double v,int count){
-			this.incrCount(count);
-			total += v;
-		}
-		@Override
-		public double result(){
-			return this.total/this.count();
-		}
-	}
-
-	public static class Max extends Function {
-		private double maximum;
-		public Max(){
-			// TODO is this a bug, or only positive numeric calculation is supported
-			this.maximum = 0.0;
-		}
-
-		@Override
-		public void run(double v,int count){
-			this.incrCount(count);
-			if(v > maximum){
-				maximum = v;
-			}
-		}
-
-		@Override
-		public double result(){
-			return maximum;
-		}
-	}
-
-	public static class Min extends Function {
-		private double minimum;
-		public Min(){
-			// TODO is this a bug, or only positive numeric calculation is supported
-			this.minimum = Double.MAX_VALUE;
-		}
-		@Override
-		public void run(double v,int count){
-			this.incrCount(count);
-			if(v < minimum){
-				minimum = v;
-			}
-		}
-
-		@Override
-		public double result(){
-			return minimum;
-		}
-	}
-
-	public static class Sum extends Function {
-		private double summary;
-		public Sum(){
-			this.summary = 0.0;
-		}
-		@Override
-		public void run(double v,int count){
-			this.incrCount(count);
-			this.summary += v;
-		}
-
-		@Override
-		public double result(){
-			return this.summary;
-		}
-	}
-
-	public static class Count extends Sum{
-		public Count(){
-			super();
-		}
-	}
+public abstract class Function {
+    private int count = 0;
+
+    protected void incrCount(int num) {
+        count += num;
+    }
+
+    public int count() {
+        return count;
+    }
+
+    public abstract void run(double v,int count);
+
+    public void run(double v) {
+        run(v, 1);
+    }
+
+    public abstract double result();
+
+    public static class Avg extends Function {
+        private double total;
+
+        public Avg() {
+            this.total = 0.0;
+        }
+
+        @Override
+        public void run(double v, int count) {
+            this.incrCount(count);
+            total += v;
+        }
+
+        @Override
+        public double result() {
+            return this.total / this.count();
+        }
+    }
+
+    public static class Max extends Function {
+        private double maximum;
+
+        public Max() {
+            // TODO is this a bug, or only positive numeric calculation is supported
+            this.maximum = 0.0;
+        }
+
+        @Override
+        public void run(double v,int count) {
+            this.incrCount(count);
+            if (v > maximum) {
+                maximum = v;
+            }
+        }
+
+        @Override
+        public double result() {
+            return maximum;
+        }
+    }
+
+    public static class Min extends Function {
+        private double minimum;
+
+        public Min() {
+            // TODO is this a bug, or only positive numeric calculation is supported
+            this.minimum = Double.MAX_VALUE;
+        }
+
+        @Override
+        public void run(double v,int count) {
+            this.incrCount(count);
+            if (v < minimum) {
+                minimum = v;
+            }
+        }
+
+        @Override
+        public double result() {
+            return minimum;
+        }
+    }
+
+    public static class Sum extends Function {
+        private double summary;
+
+        public Sum() {
+            this.summary = 0.0;
+        }
+
+        @Override
+        public void run(double v,int count) {
+            this.incrCount(count);
+            this.summary += v;
+        }
+
+        @Override
+        public double result() {
+            return this.summary;
+        }
+    }
+
+    public static class Count extends Sum {
+
+        public Count() {
+            super();
+        }
+
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/FunctionFactory.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/FunctionFactory.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/FunctionFactory.java
index c6d1861..4f9330d 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/FunctionFactory.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/FunctionFactory.java
@@ -21,55 +21,55 @@ import org.apache.eagle.query.aggregate.AggregateFunctionType;
 import java.util.HashMap;
 import java.util.Map;
 
-public abstract class FunctionFactory{
-	public abstract Function createFunction();
+public abstract class FunctionFactory {
+    public abstract Function createFunction();
 
-	public static class AvgFactory extends FunctionFactory {
-		@Override
-		public Function createFunction(){
-			return new Function.Avg();
-		}
-	}
+    public static class AvgFactory extends FunctionFactory {
+        @Override
+        public Function createFunction() {
+            return new Function.Avg();
+        }
+    }
 
-	public static class MaxFactory extends FunctionFactory {
-		@Override
-		public Function createFunction(){
-			return new Function.Max();
-		}
-	}
+    public static class MaxFactory extends FunctionFactory {
+        @Override
+        public Function createFunction() {
+            return new Function.Max();
+        }
+    }
 
-	public static class MinFactory extends FunctionFactory {
-		@Override
-		public Function createFunction(){
-			return new Function.Min();
-		}
-	}
+    public static class MinFactory extends FunctionFactory {
+        @Override
+        public Function createFunction() {
+            return new Function.Min();
+        }
+    }
 
-	public static class CountFactory extends FunctionFactory {
-		@Override
-		public Function createFunction(){
-			return new Function.Count();
-		}
-	}
+    public static class CountFactory extends FunctionFactory {
+        @Override
+        public Function createFunction() {
+            return new Function.Count();
+        }
+    }
 
-	public static class SumFactory extends FunctionFactory {
-		@Override
-		public Function createFunction(){
-			return new Function.Sum();
-		}
-	}
+    public static class SumFactory extends FunctionFactory {
+        @Override
+        public Function createFunction() {
+            return new Function.Sum();
+        }
+    }
 
-	public static FunctionFactory locateFunctionFactory(AggregateFunctionType funcType){
-		return _functionFactories.get(funcType.name());
-	}
+    public static FunctionFactory locateFunctionFactory(AggregateFunctionType funcType) {
+        return functionFactories.get(funcType.name());
+    }
 
-	private static Map<String, FunctionFactory> _functionFactories = new HashMap<String, FunctionFactory>();
-	static{
-		_functionFactories.put(AggregateFunctionType.count.name(), new CountFactory());
-		_functionFactories.put(AggregateFunctionType.sum.name(), new SumFactory());
-		_functionFactories.put(AggregateFunctionType.min.name(), new MinFactory());
-		_functionFactories.put(AggregateFunctionType.max.name(), new MaxFactory());
-		_functionFactories.put(AggregateFunctionType.avg.name(), new AvgFactory());
-	}
+    private static Map<String, FunctionFactory> functionFactories = new HashMap<String, FunctionFactory>();
+
+    static {
+        functionFactories.put(AggregateFunctionType.count.name(), new CountFactory());
+        functionFactories.put(AggregateFunctionType.sum.name(), new SumFactory());
+        functionFactories.put(AggregateFunctionType.min.name(), new MinFactory());
+        functionFactories.put(AggregateFunctionType.max.name(), new MaxFactory());
+        functionFactories.put(AggregateFunctionType.avg.name(), new AvgFactory());
+    }
 }
-	
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKey.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKey.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKey.java
index c8ed260..b6970d0 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKey.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKey.java
@@ -38,112 +38,115 @@ import java.util.ListIterator;
  * </pre>
  */
 public class GroupbyKey implements Writable {
-	private final WritableList<BytesWritable> value;
+    private final WritableList<BytesWritable> value;
 
-	public void addValue(byte[] value){
-		this.value.add(new BytesWritable(value));
-	}
-	public void addAll(List<BytesWritable> list){
-		this.value.addAll(list);
-	}
+    public void addValue(byte[] value) {
+        this.value.add(new BytesWritable(value));
+    }
 
-	public List<BytesWritable> getValue(){
-		return value;
-	}
+    public void addAll(List<BytesWritable> list) {
+        this.value.addAll(list);
+    }
 
-	/**
-	 * empty constructor
-	 */
-	public GroupbyKey(){
-		this.value = new WritableList<BytesWritable>(BytesWritable.class);
-	}
+    public List<BytesWritable> getValue() {
+        return value;
+    }
 
-	/**
-	 * clear for reuse
-	 */
-	public void clear(){
-		value.clear();
-	}
+    /**
+     * empty constructor
+     */
+    public GroupbyKey() {
+        this.value = new WritableList<BytesWritable>(BytesWritable.class);
+    }
 
-	/**
-	 * copy constructor
-	 * @param key
-	 */
-	public GroupbyKey(GroupbyKey key){
-		this();
-		ListIterator<BytesWritable> it = key.value.listIterator();
-//		ListIterator<byte[]> it = key.value.listIterator();
-		while(it.hasNext()){
-			this.value.add(it.next());
-		}
-	}
+    /**
+     * clear for reuse
+     */
+    public void clear() {
+        value.clear();
+    }
 
-	public GroupbyKey(List<byte[]> bytes){
-		this();
-		for(byte[] bt:bytes){
-			this.addValue(bt);
-		}
-	}
+    /**
+     * copy constructor
+     * @param key
+     */
+    public GroupbyKey(GroupbyKey key) {
+        this();
+        ListIterator<BytesWritable> it = key.value.listIterator();
+        // ListIterator<byte[]> it = key.value.listIterator();
+        while (it.hasNext()) {
+            this.value.add(it.next());
+        }
+    }
 
-	@Override
-	public boolean equals(Object obj){
-		if(obj == this)
-			return true;
-		if(!(obj instanceof GroupbyKey)){
-			return false;
-		}
-		GroupbyKey that = (GroupbyKey)obj;
-		ListIterator<BytesWritable> e1 = this.value.listIterator();
-		ListIterator<BytesWritable> e2 = that.value.listIterator();
-		while(e1.hasNext() && e2.hasNext()){
-			if(!Arrays.equals(e1.next().getBytes(), e2.next().getBytes()))
-				return false;
-		}
-		return !(e1.hasNext() || e2.hasNext());
-	}
+    public GroupbyKey(List<byte[]> bytes) {
+        this();
+        for (byte[] bt:bytes) {
+            this.addValue(bt);
+        }
+    }
 
-	@Override
-	public String toString() {
-		List<String> items = new ArrayList<>(this.value.size());
-		ListIterator<BytesWritable> iterator = this.value.listIterator();
-		while(iterator.hasNext()){
-			items.add(iterator.next().toString());
-		}
-		return String.format("%s(%s)",this.getClass().getSimpleName(),StringUtils.join(items,","));
-	}
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof GroupbyKey)) {
+            return false;
+        }
+        GroupbyKey that = (GroupbyKey)obj;
+        ListIterator<BytesWritable> e1 = this.value.listIterator();
+        ListIterator<BytesWritable> e2 = that.value.listIterator();
+        while (e1.hasNext() && e2.hasNext()) {
+            if (!Arrays.equals(e1.next().getBytes(), e2.next().getBytes())) {
+                return false;
+            }
+        }
+        return !(e1.hasNext() || e2.hasNext());
+    }
 
-	@Override
-	public int hashCode(){
-		ListIterator<BytesWritable> e1 = this.value.listIterator();
-		int hash = 0xFFFFFFFF;
-		while(e1.hasNext()){
-			hash ^= Arrays.hashCode(e1.next().getBytes());
-		}
-		return hash;
-	}
+    @Override
+    public String toString() {
+        List<String> items = new ArrayList<>(this.value.size());
+        ListIterator<BytesWritable> iterator = this.value.listIterator();
+        while (iterator.hasNext()) {
+            items.add(iterator.next().toString());
+        }
+        return String.format("%s(%s)",this.getClass().getSimpleName(),StringUtils.join(items,","));
+    }
 
-	/**
-	 * Serialize the fields of this object to <code>out</code>.
-	 *
-	 * @param out <code>DataOuput</code> to serialize this object into.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void write(DataOutput out) throws IOException {
-		this.value.write(out);
-	}
+    @Override
+    public int hashCode() {
+        ListIterator<BytesWritable> e1 = this.value.listIterator();
+        int hash = 0xFFFFFFFF;
+        while (e1.hasNext()) {
+            hash ^= Arrays.hashCode(e1.next().getBytes());
+        }
+        return hash;
+    }
 
-	/**
-	 * Deserialize the fields of this object from <code>in</code>.
-	 * <p/>
-	 * <p>For efficiency, implementations should attempt to re-use storage in the
-	 * existing object where possible.</p>
-	 *
-	 * @param in <code>DataInput</code> to deseriablize this object from.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void readFields(DataInput in) throws IOException {
-		this.value.readFields(in);
-	}
+    /**
+     * Serialize the fields of this object to <code>out</code>.
+     *
+     * @param out <code>DataOuput</code> to serialize this object into.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void write(DataOutput out) throws IOException {
+        this.value.write(out);
+    }
+
+    /**
+     * Deserialize the fields of this object from <code>in</code>.
+     * <p/>
+     * <p>For efficiency, implementations should attempt to re-use storage in the
+     * existing object where possible.</p>
+     *
+     * @param in <code>DataInput</code> to deseriablize this object from.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void readFields(DataInput in) throws IOException {
+        this.value.readFields(in);
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyAggregatable.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyAggregatable.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyAggregatable.java
index 7e20029..723df2c 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyAggregatable.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyAggregatable.java
@@ -19,7 +19,7 @@ package org.apache.eagle.query.aggregate.raw;
 import java.util.List;
 
 /**
- * The generic interface to unify the GroupbyKeyValue-based results of different 
+ * The generic interface to unify the GroupbyKeyValue-based results of different
  * business logic aggregates like RawAggregator or TimeSeriesAggregator
  *
  * @see org.apache.eagle.query.aggregate.timeseries.TimeSeriesAggregator
@@ -29,11 +29,11 @@ import java.util.List;
  *
  */
 public interface GroupbyKeyAggregatable {
-	/**
-	 * @see RawAggregator#getGroupbyKeyValues()
-	 * @see org.apache.eagle.query.aggregate.timeseries.TimeSeriesAggregator#getGroupbyKeyValues()
-	 * 
-	 * @return
-	 */
-	public List<GroupbyKeyValue> getGroupbyKeyValues();
+    /**
+     * @see RawAggregator#getGroupbyKeyValues()
+     * @see org.apache.eagle.query.aggregate.timeseries.TimeSeriesAggregator#getGroupbyKeyValues()
+     *
+     * @return
+     */
+    List<GroupbyKeyValue> getGroupbyKeyValues();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyComparator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyComparator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyComparator.java
index f976c8c..ad1f755 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyComparator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyComparator.java
@@ -23,21 +23,25 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.ListIterator;
 
-public class GroupbyKeyComparator implements Comparator<GroupbyKey>{
-	@Override 
-    public int compare(GroupbyKey key1, GroupbyKey key2){
-		List<BytesWritable> list1 = key1.getValue();
-		List<BytesWritable> list2 = key2.getValue();
-		
-		if(list1 == null || list2 == null || list1.size() != list2.size())
-			throw new IllegalArgumentException("2 list of groupby fields must be non-null and have the same size");
-		ListIterator<BytesWritable> e1 = list1.listIterator();
-		ListIterator<BytesWritable> e2 = list2.listIterator();
-		while(e1.hasNext() && e2.hasNext()){
-			int r = Bytes.compareTo(e1.next().copyBytes(), e2.next().copyBytes());
-			if(r != 0)
-				return r;
-		}
-		return 0;
-	}
+public class GroupbyKeyComparator implements Comparator<GroupbyKey> {
+
+    @Override
+    public int compare(GroupbyKey key1, GroupbyKey key2) {
+        List<BytesWritable> list1 = key1.getValue();
+        List<BytesWritable> list2 = key2.getValue();
+
+        if (list1 == null || list2 == null || list1.size() != list2.size()) {
+            throw new IllegalArgumentException("2 list of groupby fields must be non-null and have the same size");
+        }
+        ListIterator<BytesWritable> e1 = list1.listIterator();
+        ListIterator<BytesWritable> e2 = list2.listIterator();
+        while (e1.hasNext() && e2.hasNext()) {
+            int r = Bytes.compareTo(e1.next().copyBytes(), e2.next().copyBytes());
+            if (r != 0) {
+                return r;
+            }
+        }
+        return 0;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValue.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValue.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValue.java
index 2256761..8420b11 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValue.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValue.java
@@ -36,56 +36,59 @@ import java.io.IOException;
  * @since : 11/4/14,2014
  */
 public class GroupbyKeyValue implements Writable {
-	private GroupbyKey key;
-	private GroupbyValue value;
-	public GroupbyKeyValue(){
-		this.key = new GroupbyKey();
-		this.value = new GroupbyValue();
-	}
-	public GroupbyKeyValue(GroupbyKey key,GroupbyValue value){
-		this.key = key;
-		this.value = value;
-	}
-	public GroupbyKey getKey() {
-		return key;
-	}
+    private GroupbyKey key;
+    private GroupbyValue value;
 
-	public void setKey(GroupbyKey key) {
-		this.key = key;
-	}
+    public GroupbyKeyValue() {
+        this.key = new GroupbyKey();
+        this.value = new GroupbyValue();
+    }
 
-	public GroupbyValue getValue() {
-		return value;
-	}
+    public GroupbyKeyValue(GroupbyKey key,GroupbyValue value) {
+        this.key = key;
+        this.value = value;
+    }
 
-	public void setValue(GroupbyValue value) {
-		this.value = value;
-	}
+    public GroupbyKey getKey() {
+        return key;
+    }
 
-	/**
-	 * Serialize the fields of this object to <code>out</code>.
-	 *
-	 * @param out <code>DataOuput</code> to serialize this object into.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void write(DataOutput out) throws IOException {
-		this.key.write(out);
-		this.value.write(out);
-	}
+    public void setKey(GroupbyKey key) {
+        this.key = key;
+    }
 
-	/**
-	 * Deserialize the fields of this object from <code>in</code>.
-	 * <p/>
-	 * <p>For efficiency, implementations should attempt to re-use storage in the
-	 * existing object where possible.</p>
-	 *
-	 * @param in <code>DataInput</code> to deseriablize this object from.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void readFields(DataInput in) throws IOException {
-		this.key.readFields(in);
-		this.value.readFields(in);
-	}
+    public GroupbyValue getValue() {
+        return value;
+    }
+
+    public void setValue(GroupbyValue value) {
+        this.value = value;
+    }
+
+    /**
+     * Serialize the fields of this object to <code>out</code>.
+     *
+     * @param out <code>DataOuput</code> to serialize this object into.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void write(DataOutput out) throws IOException {
+        this.key.write(out);
+        this.value.write(out);
+    }
+
+    /**
+     * Deserialize the fields of this object from <code>in</code>.
+     * <p/>
+     * <p>For efficiency, implementations should attempt to re-use storage in the
+     * existing object where possible.</p>
+     *
+     * @param in <code>DataInput</code> to deseriablize this object from.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void readFields(DataInput in) throws IOException {
+        this.key.readFields(in);
+        this.value.readFields(in);
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValueCreationListener.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValueCreationListener.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValueCreationListener.java
index 6ca4bec..e443624 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValueCreationListener.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyKeyValueCreationListener.java
@@ -20,5 +20,5 @@ package org.apache.eagle.query.aggregate.raw;
  * @since : 11/11/14,2014
  */
 public interface GroupbyKeyValueCreationListener {
-	void keyValueCreated(GroupbyKeyValue kv);
+    void keyValueCreated(GroupbyKeyValue kv);
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyValue.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyValue.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyValue.java
index b7f2c43..20679b9 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyValue.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/GroupbyValue.java
@@ -41,99 +41,105 @@ import java.io.IOException;
  *
  * @since : 11/4/14,2014
  */
-public class GroupbyValue implements Writable{
-	private final WritableList<DoubleWritable> value;
-	private WritableList<BytesWritable> meta;
-	private int initialCapacity=1;
-	public GroupbyValue(){
-		this(1);
-	}
-	/**
-	 * Constructs an empty list with the specified initial capacity.
-	 *
-	 * @param   initialCapacity   the initial capacity of the list
-	 * @exception IllegalArgumentException if the specified initial capacity
-	 *            is negative
-	 */
-	public GroupbyValue(int initialCapacity ){
-		this.initialCapacity = initialCapacity;
-		this.value = new WritableList<DoubleWritable>(DoubleWritable.class,this.initialCapacity);
-		this.meta = new WritableList<BytesWritable>(BytesWritable.class,this.initialCapacity);
-	}
-
-	public WritableList<DoubleWritable> getValue(){
-		return this.value;
-	}
-
-	public WritableList<BytesWritable> getMeta(){
-		return this.meta;
-	}
-
-	public DoubleWritable get(int index){
-		return this.value.get(index);
-	}
-
-	public BytesWritable getMeta(int index){
-		if(this.meta==null) return null;
-		return this.meta.get(index);
-	}
-
-	// Values
-	public void add(DoubleWritable value){
-		this.value.add(value);
-	}
-	public void add(Double value){
-		this.value.add(new DoubleWritable(value));
-	}
-
-	public void set(int index,DoubleWritable value){
-		this.value.set(index, value);
-	}
-
-	//////////////
-	// Meta
-	/////////////
-	public void addMeta(BytesWritable meta){
-		this.meta.add(meta);
-	}
-
-	public void addMeta(int meta){
-		this.meta.add(new BytesWritable(ByteUtil.intToBytes(meta)));
-	}
-
-	public void setMeta(int index,BytesWritable meta){
-		this.meta.set(index,meta);
-	}
-	public void setMeta(int index,int meta){
-		this.meta.set(index, new BytesWritable(ByteUtil.intToBytes(meta)));
-	}
-
-	/**
-	 * Serialize the fields of this object to <code>out</code>.
-	 *
-	 * @param out <code>DataOuput</code> to serialize this object into.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void write(DataOutput out) throws IOException {
-		out.writeInt(this.initialCapacity);
-		this.value.write(out);
-		this.meta.write(out);
-	}
-
-	/**
-	 * Deserialize the fields of this object from <code>in</code>.
-	 * <p/>
-	 * <p>For efficiency, implementations should attempt to re-use storage in the
-	 * existing object where possible.</p>
-	 *
-	 * @param in <code>DataInput</code> to deseriablize this object from.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void readFields(DataInput in) throws IOException {
-		this.initialCapacity = in.readInt();
-		this.value.readFields(in);
-		this.meta.readFields(in);
-	}
+public class GroupbyValue implements Writable {
+    private final WritableList<DoubleWritable> value;
+    private WritableList<BytesWritable> meta;
+    private int initialCapacity = 1;
+
+    public GroupbyValue() {
+        this(1);
+    }
+
+    /**
+     * Constructs an empty list with the specified initial capacity.
+     *
+     * @param   initialCapacity   the initial capacity of the list
+     * @exception IllegalArgumentException if the specified initial capacity
+     *            is negative
+     */
+    public GroupbyValue(int initialCapacity) {
+        this.initialCapacity = initialCapacity;
+        this.value = new WritableList<DoubleWritable>(DoubleWritable.class,this.initialCapacity);
+        this.meta = new WritableList<BytesWritable>(BytesWritable.class,this.initialCapacity);
+    }
+
+    public WritableList<DoubleWritable> getValue() {
+        return this.value;
+    }
+
+    public DoubleWritable get(int index) {
+        return this.value.get(index);
+    }
+
+    public WritableList<BytesWritable> getMeta() {
+        return this.meta;
+    }
+
+    public BytesWritable getMeta(int index) {
+        if (this.meta == null) {
+            return null;
+        }
+        return this.meta.get(index);
+    }
+
+    // Values
+    public void add(DoubleWritable value) {
+        this.value.add(value);
+    }
+
+    public void add(Double value) {
+        this.value.add(new DoubleWritable(value));
+    }
+
+    public void set(int index,DoubleWritable value) {
+        this.value.set(index, value);
+    }
+
+    //////////////
+    // Meta
+    /////////////
+    public void addMeta(BytesWritable meta) {
+        this.meta.add(meta);
+    }
+
+    public void addMeta(int meta) {
+        this.meta.add(new BytesWritable(ByteUtil.intToBytes(meta)));
+    }
+
+    public void setMeta(int index,BytesWritable meta) {
+        this.meta.set(index,meta);
+    }
+
+    public void setMeta(int index,int meta) {
+        this.meta.set(index, new BytesWritable(ByteUtil.intToBytes(meta)));
+    }
+
+    /**
+     * Serialize the fields of this object to <code>out</code>.
+     *
+     * @param out <code>DataOuput</code> to serialize this object into.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void write(DataOutput out) throws IOException {
+        out.writeInt(this.initialCapacity);
+        this.value.write(out);
+        this.meta.write(out);
+    }
+
+    /**
+     * Deserialize the fields of this object from <code>in</code>.
+     * <p/>
+     * <p>For efficiency, implementations should attempt to re-use storage in the
+     * existing object where possible.</p>
+     *
+     * @param in <code>DataInput</code> to deseriablize this object from.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void readFields(DataInput in) throws IOException {
+        this.initialCapacity = in.readInt();
+        this.value.readFields(in);
+        this.meta.readFields(in);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawAggregator.java
index 0468074..5883b20 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawAggregator.java
@@ -25,47 +25,47 @@ import java.util.ListIterator;
 import java.util.Map;
 
 public class RawAggregator implements QualifierCreationListener,GroupbyKeyAggregatable {
-	private List<String> groupbyFields;
-	private GroupbyKey key;
-	private static final byte[] UNASSIGNED = "unassigned".getBytes();
-	private RawGroupbyBucket bucket;
+    private List<String> groupbyFields;
+    private GroupbyKey key;
+    private static final byte[] UNASSIGNED = "unassigned".getBytes();
+    private RawGroupbyBucket bucket;
 
-	public RawAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFunctionTypes, List<String> aggregatedFields, EntityDefinition ed){
-		this.groupbyFields = groupbyFields;
-		key = new GroupbyKey();
-		bucket = new RawGroupbyBucket(aggregateFunctionTypes, aggregatedFields, ed);
-	}
+    public RawAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFunctionTypes, List<String> aggregatedFields, EntityDefinition ed) {
+        this.groupbyFields = groupbyFields;
+        key = new GroupbyKey();
+        bucket = new RawGroupbyBucket(aggregateFunctionTypes, aggregatedFields, ed);
+    }
 
-	@Override
-	public void qualifierCreated(Map<String, byte[]> qualifiers){
-		key.clear();
-		ListIterator<String> it = groupbyFields.listIterator();
-		while(it.hasNext()){
-			byte[] groupbyFieldValue = qualifiers.get(it.next());
-			if(groupbyFieldValue == null){
-				key.addValue(UNASSIGNED);
-			}else{
-				key.addValue(groupbyFieldValue);
-			}
-		}
-		GroupbyKey newKey = null;
-		if(bucket.exists(key)){
-			newKey = key;
-		}else{
-			newKey = new GroupbyKey(key);
-		}
-		
-		bucket.addDatapoint(newKey, qualifiers);
-	}
+    @Override
+    public void qualifierCreated(Map<String, byte[]> qualifiers) {
+        key.clear();
+        ListIterator<String> it = groupbyFields.listIterator();
+        while (it.hasNext()) {
+            byte[] groupbyFieldValue = qualifiers.get(it.next());
+            if (groupbyFieldValue == null) {
+                key.addValue(UNASSIGNED);
+            } else {
+                key.addValue(groupbyFieldValue);
+            }
+        }
+        GroupbyKey newKey = null;
+        if (bucket.exists(key)) {
+            newKey = key;
+        } else {
+            newKey = new GroupbyKey(key);
+        }
 
-	/**
-	 * @return
-	 */
-	public Map<List<String>, List<Double>> result(){
-		return bucket.result();
-	}
+        bucket.addDatapoint(newKey, qualifiers);
+    }
 
-	public List<GroupbyKeyValue> getGroupbyKeyValues(){
-		return bucket.groupbyKeyValues();
-	}
+    /**
+     * @return
+     */
+    public Map<List<String>, List<Double>> result() {
+        return bucket.result();
+    }
+
+    public List<GroupbyKeyValue> getGroupbyKeyValues() {
+        return bucket.groupbyKeyValues();
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawGroupbyBucket.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawGroupbyBucket.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawGroupbyBucket.java
index 47b84a0..b0aa79c 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawGroupbyBucket.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/RawGroupbyBucket.java
@@ -30,167 +30,174 @@ import org.slf4j.LoggerFactory;
 import java.util.*;
 
 public class RawGroupbyBucket {
-	private final static Logger LOG = LoggerFactory.getLogger(RawGroupbyBucket.class);
+    private static final Logger LOG = LoggerFactory.getLogger(RawGroupbyBucket.class);
 
-	private List<String> aggregatedFields;
-	private EntityDefinition entityDefinition;
+    private List<String> aggregatedFields;
+    private EntityDefinition entityDefinition;
 
-	
-	private List<AggregateFunctionType> types;
-	private SortedMap<GroupbyKey, List<Function>> group2FunctionMap =
-			new TreeMap<GroupbyKey, List<Function>>(new GroupbyKeyComparator());
 
-	public RawGroupbyBucket(List<AggregateFunctionType> types, List<String> aggregatedFields, EntityDefinition ed){
-		this.types = types;
-		this.aggregatedFields = aggregatedFields;
-		this.entityDefinition = ed;
-	}
+    private List<AggregateFunctionType> types;
+    private SortedMap<GroupbyKey, List<Function>> group2FunctionMap =
+        new TreeMap<GroupbyKey, List<Function>>(new GroupbyKeyComparator());
 
-	public boolean exists(GroupbyKey key){
-		return group2FunctionMap.containsKey(key);
-	}
+    public RawGroupbyBucket(List<AggregateFunctionType> types, List<String> aggregatedFields, EntityDefinition ed) {
+        this.types = types;
+        this.aggregatedFields = aggregatedFields;
+        this.entityDefinition = ed;
+    }
 
-	public void addDatapoint(GroupbyKey groupbyKey, Map<String, byte[]> values){
-		// locate groupby bucket
-		List<Function> functions = group2FunctionMap.get(groupbyKey);
-		if(functions == null){
-			functions = new ArrayList<Function>();
-			for(AggregateFunctionType type : types){
-				FunctionFactory ff = FunctionFactory.locateFunctionFactory(type);
-				if(ff == null){
-					LOG.error("FunctionFactory of AggregationFunctionType:"+type+" is null");
-				}else{
-					functions.add(ff.createFunction());
-				}
-			}
-			group2FunctionMap.put(groupbyKey, functions);
-		}
-		ListIterator<Function> e1 = functions.listIterator();
-		ListIterator<String> e2 = aggregatedFields.listIterator();
-		while(e1.hasNext() && e2.hasNext()){
-			Function f = e1.next();
-			String aggregatedField = e2.next();
-			byte[] v = values.get(aggregatedField);
-			if(f instanceof Function.Count){ // handle count
-				if(entityDefinition.getMetricDefinition()==null) {
-					f.run(1.0);
-					continue;
-				}else if(v == null){
-					aggregatedField = GenericMetricEntity.VALUE_FIELD;
-					v = values.get(aggregatedField);
-				}
-			}
-			if(v != null){
-				Qualifier q = entityDefinition.getDisplayNameMap().get(aggregatedField);
-				EntitySerDeser<?> serDeser = q.getSerDeser();
-				// double d = 0.0;
-				if(serDeser instanceof IntSerDeser){
-					double d= (Integer)serDeser.deserialize(v);
-					f.run(d);
-				}else if(serDeser instanceof LongSerDeser){
-					double d = (Long)serDeser.deserialize(v);
-					f.run(d);
-				}else if(serDeser instanceof DoubleSerDeser){
-					double d = (Double)serDeser.deserialize(v);
-					f.run(d);
-				// TODO: support numeric array type that is not metric
-				}else if(serDeser instanceof DoubleArraySerDeser){
-					double[] d = ((DoubleArraySerDeser) serDeser).deserialize(v);
-					if(f instanceof Function.Count){
-						f.run(d.length);
-					} else {
-						for(double i:d) f.run(i);
-					}
-				}else if(serDeser instanceof IntArraySerDeser){
-					int[] d = ((IntArraySerDeser) serDeser).deserialize(v);
-					if(f instanceof Function.Count){
-						f.run(d.length);
-					}else{
-						for(int i:d) f.run(i);
-					}
-				}else{
-					if(LOG.isDebugEnabled()) LOG.debug("EntitySerDeser of field "+aggregatedField+" is not IntSerDeser or LongSerDeser or DoubleSerDeser or IntArraySerDeser or DoubleArraySerDeser, default as 0.0");
-				}
-			}else if(TokenConstant.isExpression(aggregatedField)){
-				String expression = TokenConstant.parseExpressionContent(aggregatedField);
-				try {
-					Map<String,Double> doubleMap = EntityQualifierUtils.bytesMapToDoubleMap(values, entityDefinition);
-					if(entityDefinition.getMetricDefinition() == null) {
-						double value = ExpressionParser.eval(expression,doubleMap);
-						// LOG.info("DEBUG: Eval "+expression +" = "+value);
-						f.run(value);
-					}else{
-						Qualifier qualifier = entityDefinition.getDisplayNameMap().get(GenericMetricEntity.VALUE_FIELD);
-						EntitySerDeser _serDeser = qualifier.getSerDeser();
-						byte[] valueBytes = values.get(GenericMetricEntity.VALUE_FIELD);
-						if( _serDeser instanceof DoubleArraySerDeser){
-							double[] d = (double[]) _serDeser.deserialize(valueBytes);
-							if(f instanceof Function.Count) {
-								f.run(d.length);
-							}else{
-								for(double i:d){
-									doubleMap.put(GenericMetricEntity.VALUE_FIELD,i);
-									f.run(ExpressionParser.eval(expression, doubleMap));
-								}
-							}
-						}else if(_serDeser instanceof IntArraySerDeser){
-							int[] d = (int[]) _serDeser.deserialize(valueBytes);
-							if(f instanceof Function.Count) {
-								f.run(d.length);
-							}else {
-								for (double i : d) {
-									doubleMap.put(GenericMetricEntity.VALUE_FIELD, i);
-									f.run(ExpressionParser.eval(expression, doubleMap));
-								}
-							}
-						}else{
-							double value = ExpressionParser.eval(expression,doubleMap);
-							f.run(value);
-						}
-					}
-				} catch (Exception e) {
-					LOG.error("Got exception to evaluate expression: "+expression+", exception: "+e.getMessage(),e);
-				}
-			}
-		}
-	}
+    public boolean exists(GroupbyKey key) {
+        return group2FunctionMap.containsKey(key);
+    }
 
-	/**
-	 * expensive operation - create objects and format the result
-	 * @return
-	 */
-	public List<GroupbyKeyValue> groupbyKeyValues(){
-		List<GroupbyKeyValue> results = new ArrayList<GroupbyKeyValue>();
-		for(Map.Entry<GroupbyKey, List<Function>> entry : this.group2FunctionMap.entrySet()){
-			GroupbyValue value = new GroupbyValue();
-			for(Function f : entry.getValue()){
-				value.add(new DoubleWritable(f.result()));
-				value.addMeta(f.count());
-			}
-			results.add(new GroupbyKeyValue(entry.getKey(),value));
-		}
-		return results;
-	}
+    public void addDatapoint(GroupbyKey groupbyKey, Map<String, byte[]> values) {
+        // locate groupby bucket
+        List<Function> functions = group2FunctionMap.get(groupbyKey);
+        if (functions == null) {
+            functions = new ArrayList<Function>();
+            for (AggregateFunctionType type : types) {
+                FunctionFactory ff = FunctionFactory.locateFunctionFactory(type);
+                if (ff == null) {
+                    LOG.error("FunctionFactory of AggregationFunctionType:" + type + " is null");
+                } else {
+                    functions.add(ff.createFunction());
+                }
+            }
+            group2FunctionMap.put(groupbyKey, functions);
+        }
+        ListIterator<Function> e1 = functions.listIterator();
+        ListIterator<String> e2 = aggregatedFields.listIterator();
+        while (e1.hasNext() && e2.hasNext()) {
+            Function f = e1.next();
+            String aggregatedField = e2.next();
+            byte[] v = values.get(aggregatedField);
+            if (f instanceof Function.Count) { // handle count
+                if (entityDefinition.getMetricDefinition() == null) {
+                    f.run(1.0);
+                    continue;
+                } else if (v == null) {
+                    aggregatedField = GenericMetricEntity.VALUE_FIELD;
+                    v = values.get(aggregatedField);
+                }
+            }
+            if (v != null) {
+                Qualifier q = entityDefinition.getDisplayNameMap().get(aggregatedField);
+                EntitySerDeser<?> serDeser = q.getSerDeser();
+                // double d = 0.0;
+                if (serDeser instanceof IntSerDeser) {
+                    double d = (Integer)serDeser.deserialize(v);
+                    f.run(d);
+                } else if (serDeser instanceof LongSerDeser) {
+                    double d = (Long)serDeser.deserialize(v);
+                    f.run(d);
+                } else if (serDeser instanceof DoubleSerDeser) {
+                    double d = (Double)serDeser.deserialize(v);
+                    f.run(d);
+                    // TODO: support numeric array type that is not metric
+                } else if (serDeser instanceof DoubleArraySerDeser) {
+                    double[] d = ((DoubleArraySerDeser) serDeser).deserialize(v);
+                    if (f instanceof Function.Count) {
+                        f.run(d.length);
+                    } else {
+                        for (double i:d) {
+                            f.run(i);
+                        }
+                    }
+                } else if (serDeser instanceof IntArraySerDeser) {
+                    int[] d = ((IntArraySerDeser) serDeser).deserialize(v);
+                    if (f instanceof Function.Count) {
+                        f.run(d.length);
+                    } else {
+                        for (int i:d) {
+                            f.run(i);
+                        }
+                    }
+                } else {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("EntitySerDeser of field " + aggregatedField
+                                  + " is not IntSerDeser or LongSerDeser or DoubleSerDeser or IntArraySerDeser or DoubleArraySerDeser, default as 0.0");
+                    }
+                }
+            } else if (TokenConstant.isExpression(aggregatedField)) {
+                String expression = TokenConstant.parseExpressionContent(aggregatedField);
+                try {
+                    Map<String,Double> doubleMap = EntityQualifierUtils.bytesMapToDoubleMap(values, entityDefinition);
+                    if (entityDefinition.getMetricDefinition() == null) {
+                        double value = ExpressionParser.eval(expression,doubleMap);
+                        // LOG.info("DEBUG: Eval "+expression +" = "+value);
+                        f.run(value);
+                    } else {
+                        Qualifier qualifier = entityDefinition.getDisplayNameMap().get(GenericMetricEntity.VALUE_FIELD);
+                        EntitySerDeser _serDeser = qualifier.getSerDeser();
+                        byte[] valueBytes = values.get(GenericMetricEntity.VALUE_FIELD);
+                        if ( _serDeser instanceof DoubleArraySerDeser) {
+                            double[] d = (double[]) _serDeser.deserialize(valueBytes);
+                            if (f instanceof Function.Count) {
+                                f.run(d.length);
+                            } else {
+                                for (double i:d) {
+                                    doubleMap.put(GenericMetricEntity.VALUE_FIELD,i);
+                                    f.run(ExpressionParser.eval(expression, doubleMap));
+                                }
+                            }
+                        } else if (_serDeser instanceof IntArraySerDeser) {
+                            int[] d = (int[]) _serDeser.deserialize(valueBytes);
+                            if (f instanceof Function.Count) {
+                                f.run(d.length);
+                            } else {
+                                for (double i : d) {
+                                    doubleMap.put(GenericMetricEntity.VALUE_FIELD, i);
+                                    f.run(ExpressionParser.eval(expression, doubleMap));
+                                }
+                            }
+                        } else {
+                            double value = ExpressionParser.eval(expression,doubleMap);
+                            f.run(value);
+                        }
+                    }
+                } catch (Exception e) {
+                    LOG.error("Got exception to evaluate expression: " + expression + ", exception: " + e.getMessage(), e);
+                }
+            }
+        }
+    }
 
-	/**
-	 * expensive operation - create objects and format the result
-	 * @return
-	 */
-	public Map<List<String>, List<Double>> result(){
-		Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>();
-		for(Map.Entry<GroupbyKey, List<Function>> entry : this.group2FunctionMap.entrySet()){
-			List<Double> values = new ArrayList<Double>();
-			for(Function f : entry.getValue()){
-				values.add(f.result());
-			}
-			GroupbyKey key = entry.getKey();
-			List<BytesWritable> list1 = key.getValue();
-			List<String> list2 = new ArrayList<String>();
-			for(BytesWritable e : list1){
-				list2.add(new String(e.copyBytes()));
-			}
-			result.put(list2, values);
-		}
-		return result;
-	}
+    /**
+     * expensive operation - create objects and format the result
+     * @return
+     */
+    public List<GroupbyKeyValue> groupbyKeyValues() {
+        List<GroupbyKeyValue> results = new ArrayList<GroupbyKeyValue>();
+        for (Map.Entry<GroupbyKey, List<Function>> entry : this.group2FunctionMap.entrySet()) {
+            GroupbyValue value = new GroupbyValue();
+            for (Function f : entry.getValue()) {
+                value.add(new DoubleWritable(f.result()));
+                value.addMeta(f.count());
+            }
+            results.add(new GroupbyKeyValue(entry.getKey(),value));
+        }
+        return results;
+    }
+
+    /**
+     * expensive operation - create objects and format the result
+     * @return
+     */
+    public Map<List<String>, List<Double>> result() {
+        Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>();
+        for (Map.Entry<GroupbyKey, List<Function>> entry : this.group2FunctionMap.entrySet()) {
+            List<Double> values = new ArrayList<Double>();
+            for (Function f : entry.getValue()) {
+                values.add(f.result());
+            }
+            GroupbyKey key = entry.getKey();
+            List<BytesWritable> list1 = key.getValue();
+            List<String> list2 = new ArrayList<String>();
+            for (BytesWritable e : list1) {
+                list2.add(new String(e.copyBytes()));
+            }
+            result.put(list2, values);
+        }
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/WritableList.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/WritableList.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/WritableList.java
index f9932a5..f3d6afd 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/WritableList.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/raw/WritableList.java
@@ -27,78 +27,75 @@ import java.util.ArrayList;
 /**
  * @since : 11/6/14,2014
  */
-public class WritableList<E extends Writable> extends ArrayList<E> implements Writable{
-	private Class<E> itemTypeClass;
+public class WritableList<E extends Writable> extends ArrayList<E> implements Writable {
+    private Class<E> itemTypeClass;
 
-	public WritableList(Class<E> typeClass){
-		this.itemTypeClass = typeClass;
-	}
+    public WritableList(Class<E> typeClass) {
+        this.itemTypeClass = typeClass;
+    }
 
-	public WritableList(Class<E> typeClass,int initialCapacity){
-		super(initialCapacity);
-		this.itemTypeClass = typeClass;
-	}
+    public WritableList(Class<E> typeClass,int initialCapacity) {
+        super(initialCapacity);
+        this.itemTypeClass = typeClass;
+    }
 
 
-	/**
-	 * <h3> Get item class by </h3>
-	 * <pre>
-	 * (Class<E>) ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
-	 * </pre>
-	 */
-	@Deprecated
-	public WritableList(){
-		this.itemTypeClass = (Class<E>) ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
-	}
+    /**
+     * <h3> Get item class by </h3>
+     */
+    @Deprecated
+    public WritableList() {
+        this.itemTypeClass = (Class<E>) ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
+    }
 
-	private void check() throws IOException{
-		if(this.itemTypeClass == null){
-			throw new IOException("Class Type of WritableArrayList<E extends Writable> is null");
-		}
-	}
+    private void check() throws IOException {
+        if (this.itemTypeClass == null) {
+            throw new IOException("Class Type of WritableArrayList<E extends Writable> is null");
+        }
+    }
 
-	public Class<E> getItemClass(){
-		return itemTypeClass;
-	}
+    public Class<E> getItemClass() {
+        return itemTypeClass;
+    }
 
-	/**
-	 * Serialize the fields of this object to <code>out</code>.
-	 *
-	 * @param out <code>DataOuput</code> to serialize this object into.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void write(DataOutput out) throws IOException {
-		this.check();
-		out.writeInt(this.size());
-		for(Writable item: this){
-			item.write(out);
-		}
-	}
+    /**
+     * Serialize the fields of this object to <code>out</code>.
+     *
+     * @param out <code>DataOuput</code> to serialize this object into.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void write(DataOutput out) throws IOException {
+        this.check();
+        out.writeInt(this.size());
+        for (Writable item: this) {
+            item.write(out);
+        }
+    }
 
-	/**
-	 * Deserialize the fields of this object from <code>in</code>.
-	 * <p/>
-	 * <p>For efficiency, implementations should attempt to re-use storage in the
-	 * existing object where possible.</p>
-	 *
-	 * @param in <code>DataInput</code> to deseriablize this object from.
-	 * @throws java.io.IOException
-	 */
-	@Override
-	public void readFields(DataInput in) throws IOException {
-		this.check();
-		int size = in.readInt();
-		for(int i=0;i<size;i++){
-			try {
-				E item = itemTypeClass.newInstance();
-				item.readFields(in);
-				this.add(item);
-			} catch (InstantiationException e) {
-				throw new IOException("Got exception to create instance for class: "+itemTypeClass+": "+e.getMessage(),e);
-			} catch (IllegalAccessException e) {
-				throw new IOException("Got exception to create instance for class: "+itemTypeClass+": "+e.getMessage(),e);
-			}
-		}
-	}
+    /**
+     * Deserialize the fields of this object from <code>in</code>.
+     * <p/>
+     * <p>For efficiency, implementations should attempt to re-use storage in the
+     * existing object where possible.</p>
+     *
+     * @param in <code>DataInput</code> to deseriablize this object from.
+     * @throws java.io.IOException
+     */
+    @Override
+    public void readFields(DataInput in) throws IOException {
+        this.check();
+        int size = in.readInt();
+        for (int i = 0; i < size; i++) {
+            try {
+                E item = itemTypeClass.newInstance();
+                item.readFields(in);
+                this.add(item);
+            } catch (InstantiationException e) {
+                throw new IOException("Got exception to create instance for class: " + itemTypeClass + ": " + e.getMessage(), e);
+            } catch (IllegalAccessException e) {
+                throw new IOException("Got exception to create instance for class: " + itemTypeClass + ": " + e.getMessage(), e);
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/AbstractAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/AbstractAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/AbstractAggregator.java
index deb0838..a4c6d98 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/AbstractAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/AbstractAggregator.java
@@ -32,161 +32,163 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 
-public abstract class AbstractAggregator implements Aggregator, EntityCreationListener{
-	private final static Logger LOG = LoggerFactory.getLogger(AbstractAggregator.class);
+public abstract class AbstractAggregator implements Aggregator, EntityCreationListener {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractAggregator.class);
 
-	private static final String UNASSIGNED = "unassigned";
-	protected List<String> groupbyFields;
-	protected List<AggregateFunctionType> aggregateFunctionTypes;
-	protected List<String> aggregatedFields;
-	// a cache to know immediately if groupby field should come from tags(true) or qualifiers(false)
-	private Boolean[] _groupbyFieldPlacementCache;
-	private Method[] _aggregateFieldReflectedMethodCache;
+    private static final String UNASSIGNED = "unassigned";
+    protected List<String> groupbyFields;
+    protected List<AggregateFunctionType> aggregateFunctionTypes;
+    protected List<String> aggregatedFields;
+    // a cache to know immediately if groupby field should come from tags(true) or qualifiers(false)
+    private Boolean[] groupbyFieldPlacementCache;
+    private Method[] aggregateFieldReflectedMethodCache;
 
-	public AbstractAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields){
-		this.groupbyFields = groupbyFields;
-		this.aggregateFunctionTypes = aggregateFuntionTypes;
-		this.aggregatedFields = aggregatedFields;
-		_aggregateFieldReflectedMethodCache = new Method[this.aggregatedFields.size()];
-		_groupbyFieldPlacementCache = new Boolean[this.groupbyFields.size()];
-	}
-	
-	@Override
-	public void entityCreated(TaggedLogAPIEntity entity) throws Exception{
-		accumulate(entity);
-	}
-	
-	public abstract Object result();
-	
-	protected String createGroupFromTags(TaggedLogAPIEntity entity, String groupbyField, int i){
-		String groupbyFieldValue = entity.getTags().get(groupbyField);
-		if(groupbyFieldValue != null){
-			_groupbyFieldPlacementCache[i] = true;
-			return groupbyFieldValue;
-		}
-		return null;
-	}
-	
-	protected String createGroupFromQualifiers(TaggedLogAPIEntity entity, String groupbyField, int i){
-		try{
-			PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(entity, groupbyField);
-			if(pd == null)
-				return null;
-//			_groupbyFieldPlacementCache.put(groupbyField, false);
-			_groupbyFieldPlacementCache[i] = false;
-			return (String)(pd.getReadMethod().invoke(entity));
-		}catch(NoSuchMethodException ex){
-			return null;
-		}catch(InvocationTargetException ex){
-			return null;
-		}catch(IllegalAccessException ex){
-			return null;
-		}
-	}
-	
-	protected String determineGroupbyFieldValue(TaggedLogAPIEntity entity, String groupbyField, int i){
-		Boolean placement = _groupbyFieldPlacementCache[i];
-		String groupbyFieldValue = null; 
-		if(placement != null){
-			groupbyFieldValue = placement.booleanValue() ? createGroupFromTags(entity, groupbyField, i) : createGroupFromQualifiers(entity, groupbyField, i); 
-		}else{
-			groupbyFieldValue = createGroupFromTags(entity, groupbyField, i);
-			if(groupbyFieldValue == null){
-				groupbyFieldValue = createGroupFromQualifiers(entity, groupbyField, i);
-			}
-		}
-		groupbyFieldValue = (groupbyFieldValue == null ? UNASSIGNED : groupbyFieldValue);
-		return groupbyFieldValue;
-	}
-	
-	/**
-	 * TODO For count aggregation, special treatment is the value is always 0 unless we support count(*) or count(<fieldname>) which counts number of rows or 
-	 * number of non-null field
-	 * For other aggregation, like sum,min,max,avg, we should resort to qualifiers
-	 * @param entity
-	 * @return
-	 */
-	protected List<Double> createPreAggregatedValues(TaggedLogAPIEntity entity) throws Exception{
-		List<Double> values = new ArrayList<Double>();
-		int functionIndex = 0;
-		for(AggregateFunctionType type : aggregateFunctionTypes){
-			if(type.name().equals(AggregateFunctionType.count.name())){
-				values.add(new Double(1));
-			}else{
-				// find value in qualifier by checking java bean
-				String aggregatedField = aggregatedFields.get(functionIndex);
-				if(TokenConstant.isExpression(aggregatedField)){
-					try {
-						String expr = TokenConstant.parseExpressionContent(aggregatedField);
-						values.add(ExpressionParser.eval(expr, entity));
-					}catch (Exception ex){
-						LOG.error("Failed to evaluate expression-based aggregation: " + aggregatedField, ex);
-						throw ex;
-					}
-				}else {
-					try {
-						Method m = _aggregateFieldReflectedMethodCache[functionIndex];
-						if (m == null) {
-//						pd = PropertyUtils.getPropertyDescriptor(entity, aggregatedField);
-//						if (pd == null) {
-//							final String errMsg = "Field/tag " + aggregatedField + " is not defined for entity " + entity.getClass().getSimpleName();
-//							logger.error(errMsg);
-//							throw new Exception(errMsg);
-//						}
-//						Object obj = pd.getReadMethod().invoke(entity);
-							String tmp = aggregatedField.substring(0, 1).toUpperCase() + aggregatedField.substring(1);
-							m = entity.getClass().getMethod("get" + tmp);
-							_aggregateFieldReflectedMethodCache[functionIndex] = m;
-						}
-						Object obj = m.invoke(entity);
-						values.add(numberToDouble(obj));
-					} catch (Exception ex) {
-						LOG.error("Cannot do aggregation for field " + aggregatedField, ex);
-						throw ex;
-					}
-				}
-			}
-			functionIndex++;
-		}
-		return values;
-	}
-	
-	/**
-	 * TODO this is a hack, we need elegant way to convert type to a broad precision
+    public AbstractAggregator(List<String> groupbyFields, List<AggregateFunctionType> aggregateFuntionTypes, List<String> aggregatedFields) {
+        this.groupbyFields = groupbyFields;
+        this.aggregateFunctionTypes = aggregateFuntionTypes;
+        this.aggregatedFields = aggregatedFields;
+        aggregateFieldReflectedMethodCache = new Method[this.aggregatedFields.size()];
+        groupbyFieldPlacementCache = new Boolean[this.groupbyFields.size()];
+    }
+
+    @Override
+    public void entityCreated(TaggedLogAPIEntity entity) throws Exception {
+        accumulate(entity);
+    }
+
+    public abstract Object result();
+
+    protected String createGroupFromTags(TaggedLogAPIEntity entity, String groupbyField, int i) {
+        String groupbyFieldValue = entity.getTags().get(groupbyField);
+        if (groupbyFieldValue != null) {
+            groupbyFieldPlacementCache[i] = true;
+            return groupbyFieldValue;
+        }
+        return null;
+    }
+
+    protected String createGroupFromQualifiers(TaggedLogAPIEntity entity, String groupbyField, int i) {
+        try {
+            PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(entity, groupbyField);
+            if (pd == null) {
+                return null;
+            }
+            //          groupbyFieldPlacementCache.put(groupbyField, false);
+            groupbyFieldPlacementCache[i] = false;
+            return (String)(pd.getReadMethod().invoke(entity));
+        } catch (NoSuchMethodException ex) {
+            return null;
+        } catch (InvocationTargetException ex) {
+            return null;
+        } catch (IllegalAccessException ex) {
+            return null;
+        }
+    }
+
+    protected String determineGroupbyFieldValue(TaggedLogAPIEntity entity, String groupbyField, int i) {
+        Boolean placement = groupbyFieldPlacementCache[i];
+        String groupbyFieldValue = null;
+        if (placement != null) {
+            groupbyFieldValue = placement.booleanValue() ? createGroupFromTags(entity, groupbyField, i) : createGroupFromQualifiers(entity, groupbyField, i);
+        } else {
+            groupbyFieldValue = createGroupFromTags(entity, groupbyField, i);
+            if (groupbyFieldValue == null) {
+                groupbyFieldValue = createGroupFromQualifiers(entity, groupbyField, i);
+            }
+        }
+        groupbyFieldValue = (groupbyFieldValue == null ? UNASSIGNED : groupbyFieldValue);
+        return groupbyFieldValue;
+    }
+
+    /**
+     * TODO For count aggregation, special treatment is the value is always 0 unless we support count(*) or count(<fieldname>) which counts number of rows or
+     * number of non-null field
+     * For other aggregation, like sum,min,max,avg, we should resort to qualifiers
+     * @param entity
+     * @return
+     */
+    protected List<Double> createPreAggregatedValues(TaggedLogAPIEntity entity) throws Exception {
+        List<Double> values = new ArrayList<Double>();
+        int functionIndex = 0;
+        for (AggregateFunctionType type : aggregateFunctionTypes) {
+            if (type.name().equals(AggregateFunctionType.count.name())) {
+                values.add(new Double(1));
+            } else {
+                // find value in qualifier by checking java bean
+                String aggregatedField = aggregatedFields.get(functionIndex);
+                if (TokenConstant.isExpression(aggregatedField)) {
+                    try {
+                        String expr = TokenConstant.parseExpressionContent(aggregatedField);
+                        values.add(ExpressionParser.eval(expr, entity));
+                    } catch (Exception ex) {
+                        LOG.error("Failed to evaluate expression-based aggregation: " + aggregatedField, ex);
+                        throw ex;
+                    }
+                } else {
+                    try {
+                        Method m = aggregateFieldReflectedMethodCache[functionIndex];
+                        if (m == null) {
+                            //                      pd = PropertyUtils.getPropertyDescriptor(entity, aggregatedField);
+                            //                      if (pd == null) {
+                            //                          final String errMsg = "Field/tag " + aggregatedField + " is not defined for entity " + entity.getClass().getSimpleName();
+                            //                          logger.error(errMsg);
+                            //                          throw new Exception(errMsg);
+                            //                      }
+                            //                      Object obj = pd.getReadMethod().invoke(entity);
+                            String tmp = aggregatedField.substring(0, 1).toUpperCase() + aggregatedField.substring(1);
+                            m = entity.getClass().getMethod("get" + tmp);
+                            aggregateFieldReflectedMethodCache[functionIndex] = m;
+                        }
+                        Object obj = m.invoke(entity);
+                        values.add(numberToDouble(obj));
+                    } catch (Exception ex) {
+                        LOG.error("Cannot do aggregation for field " + aggregatedField, ex);
+                        throw ex;
+                    }
+                }
+            }
+            functionIndex++;
+        }
+        return values;
+    }
+
+    /**
+     * TODO this is a hack, we need elegant way to convert type to a broad precision
      *
-	 * @param obj
-	 * @return
-	 */
-	protected Double numberToDouble(Object obj){
-		if(obj instanceof Double)
-			return (Double)obj;
-		if(obj instanceof Integer){
-			return new Double(((Integer)obj).doubleValue());
-		}
-		if(obj instanceof Long){
-			return new Double(((Long)obj).doubleValue());
-		}
-		// TODO hack to support string field for demo purpose, should be removed
-		if(obj == null){
-			return new Double(0.0);
-		}
-		if(obj instanceof String){
-			try{
-				return new Double((String)obj);
-			}catch(Exception ex){
-				LOG.warn("Datapoint ignored because it can not be converted to correct number for " + obj, ex);
-				return new Double(0.0);
-			}
-		}
-		if(obj instanceof double[]){
-			double[] value = (double[]) obj;
-			if(value.length > 0){
-				return new Double(value[0]);
-			}else{
-				return new Double(0.0);
-			}
-		}
-		
-		throw new IllegalAggregateFieldTypeException(obj.getClass().toString() + " type is not support. The aggregated field must be numeric type, int, long or double");
-	}
+     * @param obj
+     * @return
+     */
+    protected Double numberToDouble(Object obj) {
+        if (obj instanceof Double) {
+            return (Double)obj;
+        }
+        if (obj instanceof Integer) {
+            return new Double(((Integer)obj).doubleValue());
+        }
+        if (obj instanceof Long) {
+            return new Double(((Long)obj).doubleValue());
+        }
+        // TODO hack to support string field for demo purpose, should be removed
+        if (obj == null) {
+            return new Double(0.0);
+        }
+        if (obj instanceof String) {
+            try {
+                return new Double((String)obj);
+            } catch (Exception ex) {
+                LOG.warn("Datapoint ignored because it can not be converted to correct number for " + obj, ex);
+                return new Double(0.0);
+            }
+        }
+        if (obj instanceof double[]) {
+            double[] value = (double[]) obj;
+            if (value.length > 0) {
+                return new Double(value[0]);
+            } else {
+                return new Double(0.0);
+            }
+        }
+
+        throw new IllegalAggregateFieldTypeException(obj.getClass().toString() + " type is not support. The aggregated field must be numeric type, int, long or double");
+    }
 }

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/Aggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/Aggregator.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/Aggregator.java
index 1e70e91..db62cfc 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/Aggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/Aggregator.java
@@ -25,5 +25,5 @@ public interface Aggregator {
      * @param entity accumulated entity instance
      * @throws Exception
      */
-	public void accumulate(TaggedLogAPIEntity entity) throws Exception;
+    void accumulate(TaggedLogAPIEntity entity) throws Exception;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/EntityCreationListenerFactory.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/EntityCreationListenerFactory.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/EntityCreationListenerFactory.java
index 7e35bec..a7a69e0 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/EntityCreationListenerFactory.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/aggregate/timeseries/EntityCreationListenerFactory.java
@@ -19,7 +19,8 @@ package org.apache.eagle.query.aggregate.timeseries;
 import org.apache.eagle.log.entity.EntityCreationListener;
 
 public class EntityCreationListenerFactory {
-	public static EntityCreationListener synchronizedEntityCreationListener(EntityCreationListener listener){
-		return new SynchronizedEntityCreationListener(listener);
-	}
+
+    public static EntityCreationListener synchronizedEntityCreationListener(EntityCreationListener listener) {
+        return new SynchronizedEntityCreationListener(listener);
+    }
 }