@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { S s = getPromotedValueFromProto(ci, resp, 0); sum = ci.add(sum, s); } }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { sum = ci.add(sum, getPromotedValueFromProto(ci, resp, 0)); sumSq = ci.add(sumSq, getPromotedValueFromProto(ci, resp, 1)); count += resp.getSecondPart().asReadOnlyByteBuffer().getLong(); } }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { sum = ci.add(sum, getPromotedValueFromProto(ci, resp, 0)); count += resp.getSecondPart().asReadOnlyByteBuffer().getLong(); } }
@Override public void onNext(Result[] results, ScanController controller) { try { for (Result result : results) { Cell weightCell = result.getColumnLatestCell(family, weightQualifier); R weight = ci.getValue(family, weightQualifier, weightCell); sum = ci.add(sum, ci.castToReturnType(weight)); if (ci.divideForAvg(sum, 1L) > halfSum) { if (value != null) { future.complete(value); } else { future.completeExceptionally(new NoSuchElementException()); } controller.terminate(); return; } Cell valueCell = result.getColumnLatestCell(family, valueQualifier); value = ci.getValue(family, valueQualifier, valueCell); } } catch (IOException e) { future.completeExceptionally(e); controller.terminate(); } }
for (Map.Entry<byte[], S> entry : sumByRegion.entrySet()) { startRow = entry.getKey(); S newMovingSum = ci.add(movingSum, entry.getValue()); if (ci.divideForAvg(newMovingSum, 1L) > halfSum) { break;
int listSize = results.size(); for (int i = 0; i < listSize; i++) { sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily, qualifier, results.get(i))));
for (int i = 0; i < listSize; i++) { Cell kv = results.get(i); tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily, valQualifier, kv))); if (weightQualifier != null) { tempWeight = ci.add(tempWeight, ci.castToReturnType(ci.getValue(colFamily, weightQualifier, kv))); sumVal = ci.add(sumVal, tempVal); sumWeights = ci.add(sumWeights, tempWeight); } while (hasMoreRows); ByteString first_sumVal = ci.getProtoForPromotedType(sumVal).toByteString();
temp = ci.getValue(colFamily, qualifier, results.get(i)); if (temp != null) { sumVal = ci.add(sumVal, ci.castToReturnType(temp));
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { S s = getPromotedValueFromProto(ci, resp, 0); sum = ci.add(sum, s); } }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { S s = getPromotedValueFromProto(ci, resp, 0); sum = ci.add(sum, s); } }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { sum = ci.add(sum, getPromotedValueFromProto(ci, resp, 0)); sumSq = ci.add(sumSq, getPromotedValueFromProto(ci, resp, 1)); count += resp.getSecondPart().asReadOnlyByteBuffer().getLong(); } }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { sum = ci.add(sum, getPromotedValueFromProto(ci, resp, 0)); sumSq = ci.add(sumSq, getPromotedValueFromProto(ci, resp, 1)); count += resp.getSecondPart().asReadOnlyByteBuffer().getLong(); } }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { sum = ci.add(sum, getPromotedValueFromProto(ci, resp, 0)); count += resp.getSecondPart().asReadOnlyByteBuffer().getLong(); } }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { sum = ci.add(sum, getPromotedValueFromProto(ci, resp, 0)); count += resp.getSecondPart().asReadOnlyByteBuffer().getLong(); } }
@Override public void onNext(Result[] results, ScanController controller) { try { for (Result result : results) { Cell weightCell = result.getColumnLatestCell(family, weightQualifier); R weight = ci.getValue(family, weightQualifier, weightCell); sum = ci.add(sum, ci.castToReturnType(weight)); if (ci.divideForAvg(sum, 1L) > halfSum) { if (value != null) { future.complete(value); } else { future.completeExceptionally(new NoSuchElementException()); } controller.terminate(); return; } Cell valueCell = result.getColumnLatestCell(family, valueQualifier); value = ci.getValue(family, valueQualifier, valueCell); } } catch (IOException e) { future.completeExceptionally(e); controller.terminate(); } }
@Override public void onNext(Result[] results, ScanController controller) { try { for (Result result : results) { Cell weightCell = result.getColumnLatestCell(family, weightQualifier); R weight = ci.getValue(family, weightQualifier, weightCell); sum = ci.add(sum, ci.castToReturnType(weight)); if (ci.divideForAvg(sum, 1L) > halfSum) { if (value != null) { future.complete(value); } else { future.completeExceptionally(new NoSuchElementException()); } controller.terminate(); return; } Cell valueCell = result.getColumnLatestCell(family, valueQualifier); value = ci.getValue(family, valueQualifier, valueCell); } } catch (IOException e) { future.completeExceptionally(e); controller.terminate(); } }
@Override public <T, S> Pair<S, Long> getAvg(ColumnInterpreter<T, S> ci, Scan scan) throws IOException { S sumVal = null; Long rowCountVal = 0l; InternalScanner scanner = ((RegionCoprocessorEnvironment) getEnvironment()) .getRegion().getScanner(scan); byte[] colFamily = scan.getFamilies()[0]; byte[] qualifier = scan.getFamilyMap().get(colFamily).pollFirst(); List<KeyValue> results = new ArrayList<KeyValue>(); boolean hasMoreRows = false; try { do { results.clear(); hasMoreRows = scanner.next(results); for (KeyValue kv : results) { sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily, qualifier, kv))); } rowCountVal++; } while (hasMoreRows); } finally { scanner.close(); } Pair<S, Long> pair = new Pair<S, Long>(sumVal, rowCountVal); return pair; }
@Override public <T, S> S getSum(ColumnInterpreter<T, S> ci, Scan scan) throws IOException { long sum = 0l; S sumVal = null; T temp; InternalScanner scanner = ((RegionCoprocessorEnvironment) getEnvironment()) .getRegion().getScanner(scan); byte[] colFamily = scan.getFamilies()[0]; byte[] qualifier = scan.getFamilyMap().get(colFamily).pollFirst(); List<KeyValue> results = new ArrayList<KeyValue>(); try { boolean hasMoreRows = false; do { hasMoreRows = scanner.next(results); for (KeyValue kv : results) { temp = ci.getValue(colFamily, qualifier, kv); 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; }