Search in sources :

Example 1 with ScanColumn

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;
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) UnknownScanner(org.apache.accumulo.proxy.thrift.UnknownScanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) NoMoreEntriesException(org.apache.accumulo.proxy.thrift.NoMoreEntriesException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) UUID(java.util.UUID)

Example 2 with ScanColumn

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);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) HashMap(java.util.HashMap) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) List(java.util.List) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with ScanColumn

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;
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) Range(org.apache.accumulo.proxy.thrift.Range) PartialKey(org.apache.accumulo.proxy.thrift.PartialKey) Key(org.apache.accumulo.proxy.thrift.Key) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint)

Example 4 with ScanColumn

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);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) HashMap(java.util.HashMap) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) List(java.util.List) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with ScanColumn

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;
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Authorizations(org.apache.accumulo.core.security.Authorizations) BatchScanner(org.apache.accumulo.core.client.BatchScanner) ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) NoMoreEntriesException(org.apache.accumulo.proxy.thrift.NoMoreEntriesException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) UUID(java.util.UUID)

Aggregations

ScanColumn (org.apache.accumulo.proxy.thrift.ScanColumn)5 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)3 ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)3 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 List (java.util.List)2 UUID (java.util.UUID)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 BatchScanner (org.apache.accumulo.core.client.BatchScanner)2 Connector (org.apache.accumulo.core.client.Connector)2 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)2 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)2 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)2 NamespaceNotEmptyException (org.apache.accumulo.core.client.NamespaceNotEmptyException)2 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)2 TableExistsException (org.apache.accumulo.core.client.TableExistsException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)2 Range (org.apache.accumulo.core.data.Range)2