@Test public void testAvg() throws InterruptedException, ExecutionException { assertEquals((COUNT - 1) / 2.0, AsyncAggregationClient .avg(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), DELTA); }
public static <R, S, P extends Message, Q extends Message, T extends Message> CompletableFuture<R> median(AsyncTable<AdvancedScanResultConsumer> table, ColumnInterpreter<R, S, P, Q, T> ci, Scan scan) { CompletableFuture<R> future = new CompletableFuture<>(); sumByRegion(table, ci, scan).whenComplete((sumByRegion, error) -> { if (error != null) { future.completeExceptionally(error); } else if (sumByRegion.isEmpty()) { future.completeExceptionally(new NoSuchElementException()); } else { findMedian(future, table, ci, ReflectionUtils.newInstance(scan.getClass(), scan), sumByRegion); } }); return future; } }
@Test public void testMax() throws InterruptedException, ExecutionException { assertEquals(COUNT - 1, AsyncAggregationClient .max(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); }
.<AggregateService, AggregateResponse> coprocessorService(AggregateService::newStub, (stub, controller, rpcCallback) -> stub.getMedian(controller, req, rpcCallback), callback) .fromRow(nullToEmpty(scan.getStartRow()), scan.includeStartRow()) .toRow(nullToEmpty(scan.getStopRow()), scan.includeStopRow()).execute(); return future;
@Test public void testMedian() throws InterruptedException, ExecutionException { long halfSum = COUNT * (COUNT - 1) / 4; long median = 0L; long sum = 0L; for (int i = 0; i < COUNT; i++) { sum += i; if (sum > halfSum) { median = i - 1; break; } } assertEquals(median, AsyncAggregationClient .median(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get() .longValue()); }
@Test public void testStd() throws InterruptedException, ExecutionException { double avgSq = LongStream.range(0, COUNT).map(l -> l * l).reduce((l1, l2) -> l1 + l2).getAsLong() / (double) COUNT; double avg = (COUNT - 1) / 2.0; double std = Math.sqrt(avgSq - avg * avg); assertEquals(std, AsyncAggregationClient .std(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), DELTA); }
@Test public void testRowCount() throws InterruptedException, ExecutionException { assertEquals(COUNT, AsyncAggregationClient .rowCount(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get() .longValue()); }
@Test public void testSum() throws InterruptedException, ExecutionException { assertEquals(COUNT * (COUNT - 1) / 2, AsyncAggregationClient .sum(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); }
@Test public void testMin() throws InterruptedException, ExecutionException { assertEquals(0, AsyncAggregationClient .min(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); }
.<AggregateService, AggregateResponse> coprocessorService(AggregateService::newStub, (stub, controller, rpcCallback) -> stub.getStd(controller, req, rpcCallback), callback) .fromRow(nullToEmpty(scan.getStartRow()), scan.includeStartRow()) .toRow(nullToEmpty(scan.getStopRow()), scan.includeStopRow()).execute(); return future;
@Test public void testMedianWithWeight() throws InterruptedException, ExecutionException { long halfSum = LongStream.range(0, COUNT).map(l -> l * l).reduce((l1, l2) -> l1 + l2).getAsLong() / 2; long median = 0L; long sum = 0L; for (int i = 0; i < COUNT; i++) { sum += i * i; if (sum > halfSum) { median = i - 1; break; } } assertEquals(median, AsyncAggregationClient .median(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ).addColumn(CF, CQ2)) .get().longValue()); } }
@Test public void testStd() throws InterruptedException, ExecutionException { double avgSq = LongStream.range(0, COUNT).map(l -> l * l).reduce((l1, l2) -> l1 + l2).getAsLong() / (double) COUNT; double avg = (COUNT - 1) / 2.0; double std = Math.sqrt(avgSq - avg * avg); assertEquals(std, AsyncAggregationClient .std(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), DELTA); }
@Test public void testRowCount() throws InterruptedException, ExecutionException { assertEquals(COUNT, AsyncAggregationClient .rowCount(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get() .longValue()); }
@Test public void testSum() throws InterruptedException, ExecutionException { assertEquals(COUNT * (COUNT - 1) / 2, AsyncAggregationClient .sum(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); }
@Test public void testMin() throws InterruptedException, ExecutionException { assertEquals(0, AsyncAggregationClient .min(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); }
public static <R, S, P extends Message, Q extends Message, T extends Message> CompletableFuture<Long> rowCount(AsyncTable<?> table, ColumnInterpreter<R, S, P, Q, T> ci, Scan scan) { CompletableFuture<Long> future = new CompletableFuture<>(); AggregateRequest req; try { req = validateArgAndGetPB(scan, ci, true); } catch (IOException e) { future.completeExceptionally(e); return future; } AbstractAggregationCallback<Long> callback = new AbstractAggregationCallback<Long>(future) { private long count; @Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { count += resp.getFirstPart(0).asReadOnlyByteBuffer().getLong(); } @Override protected Long getFinalResult() { return count; } }; table .<AggregateService, AggregateResponse> coprocessorService(AggregateService::newStub, (stub, controller, rpcCallback) -> stub.getRowNum(controller, req, rpcCallback), callback) .fromRow(nullToEmpty(scan.getStartRow()), scan.includeStartRow()) .toRow(nullToEmpty(scan.getStopRow()), scan.includeStopRow()).execute(); return future; }
public static <R, S, P extends Message, Q extends Message, T extends Message> CompletableFuture<R> median(AsyncTable<AdvancedScanResultConsumer> table, ColumnInterpreter<R, S, P, Q, T> ci, Scan scan) { CompletableFuture<R> future = new CompletableFuture<>(); sumByRegion(table, ci, scan).whenComplete((sumByRegion, error) -> { if (error != null) { future.completeExceptionally(error); } else if (sumByRegion.isEmpty()) { future.completeExceptionally(new NoSuchElementException()); } else { findMedian(future, table, ci, ReflectionUtils.newInstance(scan.getClass(), scan), sumByRegion); } }); return future; } }
@Test public void testMedian() throws InterruptedException, ExecutionException { long halfSum = COUNT * (COUNT - 1) / 4; long median = 0L; long sum = 0L; for (int i = 0; i < COUNT; i++) { sum += i; if (sum > halfSum) { median = i - 1; break; } } assertEquals(median, AsyncAggregationClient .median(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get() .longValue()); }
@Test public void testAvg() throws InterruptedException, ExecutionException { assertEquals((COUNT - 1) / 2.0, AsyncAggregationClient .avg(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), DELTA); }
@Test public void testStd() throws InterruptedException, ExecutionException { double avgSq = LongStream.range(0, COUNT).map(l -> l * l).reduce((l1, l2) -> l1 + l2).getAsLong() / (double) COUNT; double avg = (COUNT - 1) / 2.0; double std = Math.sqrt(avgSq - avg * avg); assertEquals(std, AsyncAggregationClient .std(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), DELTA); }