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:51 UTC

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

[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;
+    }
 }