Search in sources :

Example 1 with IsolatedScanner

use of org.apache.accumulo.core.client.IsolatedScanner in project gora by apache.

the class AccumuloStore method createScanner.

private Scanner createScanner(Query<K, T> query) throws TableNotFoundException {
    // TODO make isolated scanner optional?
    Scanner scanner = new IsolatedScanner(conn.createScanner(mapping.tableName, Authorizations.EMPTY));
    setFetchColumns(scanner, query.getFields());
    scanner.setRange(createRange(query));
    if (query.getStartTime() != -1 || query.getEndTime() != -1) {
        IteratorSetting is = new IteratorSetting(30, TimestampFilter.class);
        if (query.getStartTime() != -1)
            TimestampFilter.setStart(is, query.getStartTime(), true);
        if (query.getEndTime() != -1)
            TimestampFilter.setEnd(is, query.getEndTime(), true);
        scanner.addScanIterator(is);
    }
    return scanner;
}
Also used : IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner)

Example 2 with IsolatedScanner

use of org.apache.accumulo.core.client.IsolatedScanner in project gora by apache.

the class AccumuloStore method get.

@Override
public T get(K key, String[] fields) {
    try {
        // TODO make isolated scanner optional?
        Scanner scanner = new IsolatedScanner(conn.createScanner(mapping.tableName, Authorizations.EMPTY));
        Range rowRange = new Range(new Text(toBytes(key)));
        scanner.setRange(rowRange);
        setFetchColumns(scanner, fields);
        T persistent = newPersistent();
        ByteSequence row = populate(scanner.iterator(), persistent);
        if (row == null)
            return null;
        return persistent;
    } catch (TableNotFoundException e) {
        LOG.error(e.getMessage(), e);
        return null;
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
        return null;
    }
}
Also used : IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) ByteSequence(org.apache.accumulo.core.data.ByteSequence)

Aggregations

IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)2 Scanner (org.apache.accumulo.core.client.Scanner)2 IOException (java.io.IOException)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 ByteSequence (org.apache.accumulo.core.data.ByteSequence)1 Range (org.apache.accumulo.core.data.Range)1 Text (org.apache.hadoop.io.Text)1