@Nullable public static <T> T getFirst(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return false; })); return ret.get(); }
@Nullable public static <T> T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return true; })); return ret.get(); }
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, @Output Map<Cell, byte[]> writeMap, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeMap.putAll(values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, Transaction writeT, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeT.put(destTable, values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }
@Test public void testBatchWrap2() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); final Mutable<Boolean> hasTripped = Mutables.newMutable(); AbortingVisitor<List<? extends Long>, RuntimeException> bv = item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }; AbortingVisitor<List<Long>, RuntimeException> wrap = AbortingVisitors.wrapBatching(bv); BatchingVisitableView.of(visitor).batchAccept(1000, wrap); assertTrue("should have been tripped!", hasTripped.get()); }
@Test public void testBatchWrap() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); final Mutable<Boolean> hasTripped = Mutables.newMutable(); AbortingVisitor<List<Object>, RuntimeException> bv = item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }; AbortingVisitor<List<Long>, RuntimeException> wrap = AbortingVisitors.wrapBatching(bv); BatchingVisitableView.of(visitor).batchAccept(1000, wrap); assertTrue("should have been tripped!", hasTripped.get()); }
@Test public void testBatchHints() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); Function<List<Long>, List<String>> trans = (input) -> { assertEquals("batched item had wrong size", 2, input.size()); return Lists.transform(input, Functions.toStringFunction()); }; BatchingVisitableView<String> visitable = BatchingVisitableView.of(visitor).transformBatch(trans) .hintBatchSize(2); final Mutable<Boolean> hasTripped = Mutables.newMutable(); visitable.batchAccept(10000, item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }); assertTrue("should have been tripped!", hasTripped.get()); }
@Nullable public static <T> T getFirst(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return false; })); return ret.get(); }
@Nullable public static <T> T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return true; })); return ret.get(); }
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, @Output Map<Cell, byte[]> writeMap, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeMap.putAll(values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, Transaction writeT, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeT.put(destTable, values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }