@Override
public <T, S> S getSum(ColumnInterpreter<T, S> ci, Scan scan, byte[] qualifier) throws IOException {
long sum = 0l;
S sumVal = null;
T temp;
InternalScanner scanner = ((RegionCoprocessorEnvironment) getEnvironment())
.getRegion().getScanner(scan);
byte[] colFamily = scan.getFamilies()[0];
List<KeyValue> results = new ArrayList<KeyValue>();
try {
boolean hasMoreRows = false;
do {
hasMoreRows = scanner.next(results);
log.info("results size is " + results.size());
for (KeyValue kv : results) {
if(!Bytes.equals(kv.getQualifier(), qualifier)) {
continue;
}
temp = ci.getValue(colFamily, qualifier, kv);
log.info("WaspAggregateImplementation log : qualifier="
+ Bytes.toString(qualifier) + " value is :" + Bytes.toStringBinary(kv.getValue()) + " sum is :" + sumVal
+ " temp is :" + temp + " row is :" + Bytes.toStringBinary(kv.getRow()));
if (temp != null)
sumVal = ci.add(sumVal, ci.castToReturnType(temp));
}
results.clear();
} while (hasMoreRows);
} finally {
scanner.close();
}
log.debug("Sum from this region is "
+ ((RegionCoprocessorEnvironment) getEnvironment()).getRegion()
.getRegionNameAsString() + ": " + sum);
return sumVal;