use of org.apache.accumulo.core.client.Scanner in project presto by prestodb.
the class AccumuloClient method getDefaultTabletLocation.
private Optional<String> getDefaultTabletLocation(String fulltable) {
try {
String tableId = connector.tableOperations().tableIdMap().get(fulltable);
// Create a scanner over the metadata table, fetching the 'loc' column of the default tablet row
Scanner scan = connector.createScanner("accumulo.metadata", connector.securityOperations().getUserAuthorizations(username));
scan.fetchColumnFamily(new Text("loc"));
scan.setRange(new Range(tableId + '<'));
// scan the entry
Optional<String> location = Optional.empty();
for (Entry<Key, Value> entry : scan) {
if (location.isPresent()) {
throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, "Scan for default tablet returned more than one entry");
}
location = Optional.of(entry.getValue().toString());
}
scan.close();
return location;
} catch (Exception e) {
// Swallow this exception so the query does not fail due to being unable to locate the tablet server for the default tablet.
// This is purely an optimization, but we will want to log the error.
LOG.error("Failed to get tablet location, returning dummy location", e);
return Optional.empty();
}
}
use of org.apache.accumulo.core.client.Scanner 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;
}
use of org.apache.accumulo.core.client.Scanner in project gora by apache.
the class AccumuloStore method deleteByQuery.
@Override
public long deleteByQuery(Query<K, T> query) {
try {
Scanner scanner = createScanner(query);
// add iterator that drops values on the server side
scanner.addScanIterator(new IteratorSetting(Integer.MAX_VALUE, SortedKeyIterator.class));
RowIterator iterator = new RowIterator(scanner.iterator());
long count = 0;
while (iterator.hasNext()) {
Iterator<Entry<Key, Value>> row = iterator.next();
Mutation m = null;
while (row.hasNext()) {
Entry<Key, Value> entry = row.next();
Key key = entry.getKey();
if (m == null)
m = new Mutation(key.getRow());
// TODO optimize to avoid continually creating column vis? prob does not matter for empty
m.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp());
}
getBatchWriter().addMutation(m);
count++;
}
return count;
} catch (TableNotFoundException e) {
// TODO return 0?
LOG.error(e.getMessage(), e);
return 0;
} catch (MutationsRejectedException e) {
LOG.error(e.getMessage(), e);
return 0;
} catch (IOException e) {
LOG.error(e.getMessage(), e);
return 0;
}
}
use of org.apache.accumulo.core.client.Scanner 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;
}
}
Aggregations