agg.prepare(flowProcess);
}
}
public void operate(FlowProcess fp, FunctionCall fc) {
Tuple group = fc.getArguments().selectTuple(groupFields);
Tuple sortArgs = null;
if (includeSort) {
if (sortFields != null) {
sortArgs = fc.getArguments().selectTuple(sortFields);
} else {
sortArgs = new Tuple();
}
}
Map<Integer, List<Object>> vals = combined.get(group);
if (vals == null) {
vals = new HashMap<Integer, List<Object>>(aggs.size());
combined.put(group, vals);
}
for (int i = 0; i < aggs.size(); i++) {
try {
Fields specArgFields = argFields.get(i);
List<Object> val;
ParallelAgg agg = aggs.get(i);
if (specArgFields == null) {
val = agg.init(new ArrayList<Object>());
} else {
Tuple args = fc.getArguments().selectTuple(specArgFields);
List<Object> toApply = new ArrayList<Object>();
if (sortArgs != null) {
toApply.add(Util.tupleToList(sortArgs));
}
Util.tupleIntoList(toApply, args);
val = agg.init(toApply);
}
if (vals.get(i) != null) {
List<Object> existing = vals.get(i);
val = agg.combine(existing, val);
}
vals.put(i, val);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
combined.put(group, vals);
if (combined.size() >= this.cacheSize) {
Tuple evict = combined.keySet().iterator().next();
Map<Integer, List<Object>> removing = combined.remove(evict);
writeMap(evict, removing, fc);
}
}