use of co.cask.cdap.api.annotation.ReadOnly in project cdap by caskdata.
the class HBaseTable method scanPersisted.
@ReadOnly
@Override
protected Scanner scanPersisted(co.cask.cdap.api.dataset.table.Scan scan) throws Exception {
ScanBuilder hScan = tableUtil.buildScan();
hScan.addFamily(columnFamily);
// todo: should be configurable
// NOTE: by default we assume scanner is used in mapreduce job, hence no cache blocks
hScan.setCacheBlocks(false);
hScan.setCaching(1000);
byte[] startRow = scan.getStartRow();
byte[] stopRow = scan.getStopRow();
if (startRow != null) {
hScan.setStartRow(startRow);
}
if (stopRow != null) {
hScan.setStopRow(stopRow);
}
setFilterIfNeeded(hScan, scan.getFilter());
hScan.setAttribute(TxConstants.TX_OPERATION_ATTRIBUTE_KEY, txCodec.encode(tx));
ResultScanner resultScanner = wrapResultScanner(hTable.getScanner(hScan.build()));
return new HBaseScanner(resultScanner, columnFamily);
}
use of co.cask.cdap.api.annotation.ReadOnly in project cdap by caskdata.
the class LevelDBTable method scanPersisted.
@ReadOnly
@Override
protected Scanner scanPersisted(Scan scan) throws Exception {
FuzzyRowFilter filter = null;
if (scan.getFilter() != null) {
// todo: currently we support only FuzzyRowFilter as an experimental feature
if (scan.getFilter() instanceof FuzzyRowFilter) {
filter = (FuzzyRowFilter) scan.getFilter();
} else {
throw new DataSetException("Unknown filter type: " + scan.getFilter());
}
}
final Scanner scanner = core.scan(scan.getStartRow(), scan.getStopRow(), filter, null, tx);
return new Scanner() {
@Nullable
@Override
public Row next() {
return LevelDBTable.this.next(scanner);
}
@Override
public void close() {
scanner.close();
}
};
}
use of co.cask.cdap.api.annotation.ReadOnly in project cdap by caskdata.
the class TopKCollector method readWordAssocs.
/**
* Returns the top words associated with the specified word and the number
* of times the words have appeared together.
* @param word the word of interest
* @param limit the number of associations to return, at most
* @return a map of the top associated words to their co-occurrence count
*/
@ReadOnly
public Map<String, Long> readWordAssocs(String word, int limit) {
// Retrieve all columns of the word’s row
Row result = this.table.get(new Get(word));
TopKCollector collector = new TopKCollector(limit);
if (!result.isEmpty()) {
// Iterate over all columns
for (Map.Entry<byte[], byte[]> entry : result.getColumns().entrySet()) {
collector.add(Bytes.toLong(entry.getValue()), Bytes.toString(entry.getKey()));
}
}
return collector.getTopK();
}
use of co.cask.cdap.api.annotation.ReadOnly in project cdap by caskdata.
the class KeyValueTable method readAll.
/**
* Reads the values for an array of given keys.
*
* @param keys the keys to be read
* @return a map of the stored values, keyed by key
*/
@ReadOnly
public Map<byte[], byte[]> readAll(byte[][] keys) {
List<Get> gets = new ArrayList<>(keys.length);
for (byte[] key : keys) {
gets.add(new Get(key).add(KEY_COLUMN));
}
List<Row> results = table.get(gets);
Map<byte[], byte[]> values = new TreeMap<>(Bytes.BYTES_COMPARATOR);
for (Row row : results) {
if (row.get(KEY_COLUMN) != null) {
values.put(row.getRow(), row.get(KEY_COLUMN));
}
}
return values;
}
Aggregations