/** * Counts the rows from the {@code scanner} until exhaustion. It doesn't require the scanner to be * new, so it can be used to finish scanning a previously-started scan. */ protected static int countRowsInScan(AsyncKuduScanner scanner) throws Exception { final AtomicInteger counter = new AtomicInteger(); Callback<Object, RowResultIterator> cb = new Callback<Object, RowResultIterator>() { @Override public Object call(RowResultIterator arg) throws Exception { if (arg == null) return null; counter.addAndGet(arg.getNumRows()); return null; } }; while (scanner.hasMoreRows()) { Deferred<RowResultIterator> data = scanner.nextRows(); data.addCallbacks(cb, defaultErrorCB); data.join(DEFAULT_SLEEP); } Deferred<RowResultIterator> closer = scanner.close(); closer.addCallbacks(cb, defaultErrorCB); closer.join(DEFAULT_SLEEP); return counter.get(); }
/** * Returns if this scanner was configured to cache data blocks or not. * * @return true if this scanner will cache blocks, else else. */ public boolean getCacheBlocks() { return asyncScanner.getCacheBlocks(); }
/** * Returns the maximum number of bytes returned by the scanner, on each batch. * * @return a long representing the maximum number of bytes that a scanner can receive at once from * a tablet server */ public long getBatchSizeBytes() { return asyncScanner.getBatchSizeBytes(); }
/** * Returns the maximum number of rows that this scanner was configured to return. * * @return a long representing the maximum number of rows that can be returned */ public long getLimit() { return asyncScanner.getLimit(); }
/** * Closes this scanner (don't forget to call this when you're done with it!). * * <p>Closing a scanner already closed has no effect. * * @return a deferred object that indicates the completion of the request */ public RowResultIterator close() throws Exception { Deferred<RowResultIterator> d = asyncScanner.close(); return d.join(asyncScanner.scanRequestTimeout); }
/** * Tells if the last rpc returned that there might be more rows to scan. * * @return true if there might be more data to scan, else false */ public boolean hasMoreRows() { return asyncScanner.hasMoreRows(); }
/** * Returns the projection schema of this scanner. If specific columns were not specified during * scanner creation, the table schema is returned. * * @return the projection schema for this scanner */ public Schema getProjectionSchema() { return asyncScanner.getProjectionSchema(); }
/** * Returns the ReadMode for this scanner. * * @return the configured read mode for this scanner */ public ReadMode getReadMode() { return asyncScanner.getReadMode(); }