anchor.diff:                      if ($cols.aggregationFunctions.size() >0) {
                        //TODO add groupby aggregations
                       }
  -                }  
  -                if ($cols.aggregationFunctions != null && $cols.aggregationFunctions.size() == 1) {
  -                  
  -                  String key = $cols.aggregationFunctions.keySet().iterator().next().toLowerCase();
  -                  JSONObject ret = null;
  -                  
  -                  String column = $cols.aggregationFunctions.get(key);
  -                  String senseiKey = ("sensei." + key).toLowerCase();
  -                  if (com.senseidb.search.req.mapred.impl.MapReduceRegistry.contains(senseiKey)) {
  -                    ret = new FastJSONObject().put("function", senseiKey).put("parameters", new FastJSONObject().put("column", column));
  -                  } else  if (com.senseidb.search.req.mapred.impl.MapReduceRegistry.contains(key)) {
  -                    ret =  new FastJSONObject().put("function", key).put("parameters", new FastJSONObject().put("column", column));
  -                  }
  -                  jsonObj.put("mapReduce", ret);
  -                }
  -                
  +                }                  
  +                 Map<String,String> aggregateFunctions = null;
  +                 if (cols != null) {
  +                    aggregateFunctions = $cols.aggregationFunctions;
  +                 }
  +                if (executeMapReduce != null) {
  +                   if (group_by != null) {
  +                      BQLParserUtils.decorateWithMapReduce(jsonObj, $cols.aggregationFunctions, $group_by.json, $executeMapReduce.functionName, $executeMapReduce.properties);
  +                   } else {
  +                      BQLParserUtils.decorateWithMapReduce(jsonObj, $cols.aggregationFunctions, null, $executeMapReduce.functionName, $executeMapReduce.properties);
  +                   }
  +                } else {
  +                   if (group_by != null) {
  +                      BQLParserUtils.decorateWithMapReduce(jsonObj, $cols.aggregationFunctions, $group_by.json, null, null);
  +                   } else {
  +                      BQLParserUtils.decorateWithMapReduce(jsonObj, $cols.aggregationFunctions, null, null, null);
  +                   }
  +                }
                   if (distinct != null) {
                       jsonObj.put("distinct", $distinct.json);
                   }
  
positive.code: ELSE : ('E'|'e')('L'|'l')('S'|'s')('E'|'e') ;
  END : ('E'|'e')('N'|'n')('D'|'d') ;
  EXCEPT : ('E'|'e')('X'|'x')('C'|'c')('E'|'e')('P'|'p')('T'|'t') ;
  FACET : ('F'|'f')('A'|'a')('C'|'c')('E'|'e')('T'|'t') ;
  FALSE : ('F'|'f')('A'|'a')('L'|'l')('S'|'s')('E'|'e') ;
  FETCHING : ('F'|'f')('E'|'e')('T'|'t')('C'|'c')('H'|'h')('I'|'i')('N'|'n')('G'|'g') ;
  
negative.code:                $aggregationFunctions.put($agrFunction.function, $agrFunction.column);
              }))*;
  aggregation_function returns [String function, String column]
   :   (id=function_name LPAR columnVar=column_name RPAR) {
      $function= $id.text;    
      $column= $columnVar.text;
   };
  