public Map<List<String>, List<Double>> result(){ Map<List<String>, List<Double>> result = new HashMap<List<String>, List<Double>>(); for(Map.Entry<List<String>, List<Function>> entry : this.group2FunctionMap.entrySet()){ List<Double> values = new ArrayList<Double>(); for(Function f : entry.getValue()){ values.add(f.result()); } result.put(entry.getKey(), values); } return result; }
public void addDatapoint(List<String> groupbyFieldValues, List<Double> values){ // LOG.info("DEBUG: addDatapoint: groupby=["+StringUtils.join(groupbyFieldValues,",")+"], values=["+StringUtils.join(values, ",")+"]"); // locate groupby bucket List<Function> functions = group2FunctionMap.get(groupbyFieldValues); if(functions == null){ functions = new ArrayList<Function>(); for(AggregateFunctionType type : types){ functions.add(_functionFactories.get(type.name()).createFunction()); } group2FunctionMap.put(groupbyFieldValues, functions); } int functionIndex = 0; for(Double v : values){ functions.get(functionIndex).run(v); functionIndex++; } }
public List<GroupbyKeyValue> getGroupbyKeyValue(){ List<GroupbyKeyValue> results = new ArrayList<GroupbyKeyValue>(); for(Map.Entry<List<String>, List<Function>> entry : this.group2FunctionMap.entrySet()){ GroupbyKey key = new GroupbyKey(); for(String keyStr:entry.getKey()){ try { key.addValue(keyStr.getBytes(QueryConstants.CHARSET)); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage(),e); } } GroupbyValue value = new GroupbyValue(); for(Function f : entry.getValue()){ value.add(f.result()); value.addMeta(f.count()); } results.add(new GroupbyKeyValue(key,value)); } return results; }
private void addDatapoint(HierarchicalAggregateEntity entity, List<Double> values){ List<GroupbyBucket.Function> functions = entity.getTmpValues(); // initialize list of function if(functions.isEmpty()){ for(AggregateFunctionType type : aggregateFunctionTypes){ functions.add(GroupbyBucket._functionFactories.get(type.name()).createFunction()); } } int functionIndex = 0; for(Double v : values){ functions.get(functionIndex).run(v); functionIndex++; } }
private void finalizeHierarchicalAggregateEntity(HierarchicalAggregateEntity entity){ for(GroupbyBucket.Function f : entity.getTmpValues()){ entity.getValues().add(f.result()); } for(HierarchicalAggregateEntity child : entity.getChildren().values()){ finalizeHierarchicalAggregateEntity(child); } entity.setTmpValues(null); }