use of org.apache.accumulo.proxy.thrift.ScanColumn in project accumulo by apache.
the class ProxyServer method createScanner.
@Override
public String createScanner(ByteBuffer login, String tableName, ScanOptions opts) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException {
try {
Connector connector = getConnector(login);
Authorizations auth;
if (opts != null && opts.isSetAuthorizations()) {
auth = getAuthorizations(opts.authorizations);
} else {
auth = connector.securityOperations().getUserAuthorizations(connector.whoami());
}
Scanner scanner = connector.createScanner(tableName, auth);
if (opts != null) {
if (opts.iterators != null) {
for (org.apache.accumulo.proxy.thrift.IteratorSetting iter : opts.iterators) {
IteratorSetting is = new IteratorSetting(iter.getPriority(), iter.getName(), iter.getIteratorClass(), iter.getProperties());
scanner.addScanIterator(is);
}
}
org.apache.accumulo.proxy.thrift.Range prange = opts.range;
if (prange != null) {
Range range = new Range(Util.fromThrift(prange.getStart()), prange.startInclusive, Util.fromThrift(prange.getStop()), prange.stopInclusive);
scanner.setRange(range);
}
if (opts.columns != null) {
for (ScanColumn col : opts.columns) {
if (col.isSetColQualifier())
scanner.fetchColumn(ByteBufferUtil.toText(col.colFamily), ByteBufferUtil.toText(col.colQualifier));
else
scanner.fetchColumnFamily(ByteBufferUtil.toText(col.colFamily));
}
}
}
UUID uuid = UUID.randomUUID();
ScannerPlusIterator spi = new ScannerPlusIterator();
spi.scanner = scanner;
spi.iterator = scanner.iterator();
scannerCache.put(uuid, spi);
return uuid.toString();
} catch (Exception e) {
handleExceptionTNF(e);
return null;
}
}
use of org.apache.accumulo.proxy.thrift.ScanColumn in project accumulo by apache.
the class TestProxyReadWrite method readWriteBatchOneShotWithFullColumn.
/**
* Insert 100000 cells which have as the row [0..99999] (padded with zeros). Set a columnFamily + columnQualififer so only the entries with specified column
* come back (there should be 50,000)
*/
@Test
public void readWriteBatchOneShotWithFullColumn() throws Exception {
int maxInserts = 100000;
Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
String format = "%1$05d";
for (int i = 0; i < maxInserts; i++) {
addMutation(mutations, String.format(format, i), "cf" + (i % 2), "cq" + (i % 2), Util.randString(10));
if (i % 1000 == 0 || i == maxInserts - 1) {
tpc.proxy().updateAndFlush(userpass, testtable, mutations);
mutations.clear();
}
}
BatchScanOptions options = new BatchScanOptions();
ScanColumn sc = new ScanColumn();
sc.colFamily = ByteBuffer.wrap("cf0".getBytes());
sc.colQualifier = ByteBuffer.wrap("cq0".getBytes());
options.columns = Collections.singletonList(sc);
String cookie = tpc.proxy().createBatchScanner(userpass, testtable, options);
int i = 0;
boolean hasNext = true;
int k = 1000;
while (hasNext) {
ScanResult kvList = tpc.proxy().nextK(cookie, k);
i += kvList.getResultsSize();
hasNext = kvList.isMore();
}
assertEquals(i, 50000);
}
use of org.apache.accumulo.proxy.thrift.ScanColumn in project accumulo by apache.
the class SimpleProxyBase method countFiles.
// scan metadata for file entries for the given table
private int countFiles(String table) throws Exception {
Map<String, String> tableIdMap = client.tableIdMap(creds);
String tableId = tableIdMap.get(table);
Key start = new Key();
start.row = s2bb(tableId + ";");
Key end = new Key();
end.row = s2bb(tableId + "<");
end = client.getFollowing(end, PartialKey.ROW);
ScanOptions opt = new ScanOptions();
opt.range = new Range(start, true, end, false);
opt.columns = Collections.singletonList(new ScanColumn(s2bb("file")));
String scanner = client.createScanner(creds, MetadataTable.NAME, opt);
int result = 0;
while (true) {
ScanResult more = client.nextK(scanner, 100);
result += more.getResults().size();
if (!more.more)
break;
}
return result;
}
use of org.apache.accumulo.proxy.thrift.ScanColumn in project accumulo by apache.
the class TestProxyReadWrite method readWriteBatchOneShotWithColumnFamilyOnly.
/**
* Insert 100000 cells which have as the row [0..99999] (padded with zeros). Set a columnFamily so only the entries with specified column family come back
* (there should be 50,000)
*/
@Test
public void readWriteBatchOneShotWithColumnFamilyOnly() throws Exception {
int maxInserts = 100000;
Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
String format = "%1$05d";
for (int i = 0; i < maxInserts; i++) {
addMutation(mutations, String.format(format, i), "cf" + (i % 2), "cq" + (i % 2), Util.randString(10));
if (i % 1000 == 0 || i == maxInserts - 1) {
tpc.proxy().updateAndFlush(userpass, testtable, mutations);
mutations.clear();
}
}
BatchScanOptions options = new BatchScanOptions();
ScanColumn sc = new ScanColumn();
sc.colFamily = ByteBuffer.wrap("cf0".getBytes());
options.columns = Collections.singletonList(sc);
String cookie = tpc.proxy().createBatchScanner(userpass, testtable, options);
int i = 0;
boolean hasNext = true;
int k = 1000;
while (hasNext) {
ScanResult kvList = tpc.proxy().nextK(cookie, k);
i += kvList.getResultsSize();
hasNext = kvList.isMore();
}
assertEquals(i, 50000);
}
use of org.apache.accumulo.proxy.thrift.ScanColumn in project accumulo by apache.
the class ProxyServer method createBatchScanner.
@Override
public String createBatchScanner(ByteBuffer login, String tableName, BatchScanOptions opts) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException {
try {
Connector connector = getConnector(login);
int threads = 10;
Authorizations auth;
if (opts != null && opts.isSetAuthorizations()) {
auth = getAuthorizations(opts.authorizations);
} else {
auth = connector.securityOperations().getUserAuthorizations(connector.whoami());
}
if (opts != null && opts.threads > 0)
threads = opts.threads;
BatchScanner scanner = connector.createBatchScanner(tableName, auth, threads);
if (opts != null) {
if (opts.iterators != null) {
for (org.apache.accumulo.proxy.thrift.IteratorSetting iter : opts.iterators) {
IteratorSetting is = new IteratorSetting(iter.getPriority(), iter.getName(), iter.getIteratorClass(), iter.getProperties());
scanner.addScanIterator(is);
}
}
ArrayList<Range> ranges = new ArrayList<>();
if (opts.ranges == null) {
ranges.add(new Range());
} else {
for (org.apache.accumulo.proxy.thrift.Range range : opts.ranges) {
Range aRange = new Range(range.getStart() == null ? null : Util.fromThrift(range.getStart()), true, range.getStop() == null ? null : Util.fromThrift(range.getStop()), false);
ranges.add(aRange);
}
}
scanner.setRanges(ranges);
if (opts.columns != null) {
for (ScanColumn col : opts.columns) {
if (col.isSetColQualifier())
scanner.fetchColumn(ByteBufferUtil.toText(col.colFamily), ByteBufferUtil.toText(col.colQualifier));
else
scanner.fetchColumnFamily(ByteBufferUtil.toText(col.colFamily));
}
}
}
UUID uuid = UUID.randomUUID();
ScannerPlusIterator spi = new ScannerPlusIterator();
spi.scanner = scanner;
spi.iterator = scanner.iterator();
scannerCache.put(uuid, spi);
return uuid.toString();
} catch (Exception e) {
handleExceptionTNF(e);
return null;
}
}
Aggregations