Search in sources :

Example 1 with BatchScannerOpts

use of org.apache.accumulo.examples.cli.BatchScannerOpts in project accumulo-examples by apache.

the class ContinuousQuery method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    BatchScannerOpts bsOpts = new BatchScannerOpts();
    opts.parseArgs(ContinuousQuery.class.getName(), args, bsOpts);
    Connector conn = opts.getConnector();
    ArrayList<Text[]> randTerms = findRandomTerms(conn.createScanner(opts.doc2Term, opts.auths), opts.numTerms);
    Random rand = new Random();
    BatchScanner bs = conn.createBatchScanner(opts.tableName, opts.auths, bsOpts.scanThreads);
    bs.setTimeout(bsOpts.scanTimeout, TimeUnit.MILLISECONDS);
    for (long i = 0; i < opts.iterations; i += 1) {
        Text[] columns = randTerms.get(rand.nextInt(randTerms.size()));
        bs.clearScanIterators();
        bs.clearColumns();
        IteratorSetting ii = new IteratorSetting(20, "ii", IntersectingIterator.class);
        IntersectingIterator.setColumnFamilies(ii, columns);
        bs.addScanIterator(ii);
        bs.setRanges(Collections.singleton(new Range()));
        long t1 = System.currentTimeMillis();
        int count = Iterators.size(bs.iterator());
        long t2 = System.currentTimeMillis();
        System.out.printf("  %s %,d %6.3f%n", Arrays.asList(columns), count, (t2 - t1) / 1000.0);
    }
    bs.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ClientOpts(org.apache.accumulo.examples.cli.ClientOpts) BatchScannerOpts(org.apache.accumulo.examples.cli.BatchScannerOpts) BatchScannerOpts(org.apache.accumulo.examples.cli.BatchScannerOpts) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Random(java.util.Random) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting)

Example 2 with BatchScannerOpts

use of org.apache.accumulo.examples.cli.BatchScannerOpts in project accumulo-examples by apache.

the class RandomBatchScanner method main.

/**
 * Scans over a specified number of entries to Accumulo using a {@link BatchScanner}. Completes scans twice to compare times for a fresh query with those for
 * a repeated query which has cached metadata and connections already established.
 */
public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    Opts opts = new Opts();
    BatchScannerOpts bsOpts = new BatchScannerOpts();
    opts.parseArgs(RandomBatchScanner.class.getName(), args, bsOpts);
    Connector connector = opts.getConnector();
    BatchScanner batchReader = connector.createBatchScanner(opts.getTableName(), opts.auths, bsOpts.scanThreads);
    batchReader.setTimeout(bsOpts.scanTimeout, TimeUnit.MILLISECONDS);
    Random r;
    if (opts.seed == null)
        r = new Random();
    else
        r = new Random(opts.seed);
    // do one cold
    boolean status = doRandomQueries(opts.num, opts.min, opts.max, opts.size, r, batchReader);
    System.gc();
    System.gc();
    System.gc();
    if (opts.seed == null)
        r = new Random();
    else
        r = new Random(opts.seed);
    // do one hot (connections already established, metadata table cached)
    status = status && doRandomQueries(opts.num, opts.min, opts.max, opts.size, r, batchReader);
    batchReader.close();
    if (!status) {
        System.exit(1);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Random(java.util.Random) BatchScannerOpts(org.apache.accumulo.examples.cli.BatchScannerOpts) BatchScannerOpts(org.apache.accumulo.examples.cli.BatchScannerOpts) BatchScanner(org.apache.accumulo.core.client.BatchScanner)

Example 3 with BatchScannerOpts

use of org.apache.accumulo.examples.cli.BatchScannerOpts in project accumulo-examples by apache.

the class Query method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    BatchScannerOpts bsOpts = new BatchScannerOpts();
    opts.parseArgs(Query.class.getName(), args, bsOpts);
    Connector conn = opts.getConnector();
    BatchScanner bs = conn.createBatchScanner(opts.getTableName(), opts.auths, bsOpts.scanThreads);
    bs.setTimeout(bsOpts.scanTimeout, TimeUnit.MILLISECONDS);
    if (opts.useSample) {
        SamplerConfiguration samplerConfig = conn.tableOperations().getSamplerConfiguration(opts.getTableName());
        CutoffIntersectingIterator.validateSamplerConfig(conn.tableOperations().getSamplerConfiguration(opts.getTableName()));
        bs.setSamplerConfiguration(samplerConfig);
    }
    for (String entry : query(bs, opts.terms, opts.sampleCutoff)) System.out.println("  " + entry);
    bs.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchScannerOpts(org.apache.accumulo.examples.cli.BatchScannerOpts) BatchScannerOpts(org.apache.accumulo.examples.cli.BatchScannerOpts) BatchScanner(org.apache.accumulo.core.client.BatchScanner) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration)

Aggregations

BatchScanner (org.apache.accumulo.core.client.BatchScanner)3 Connector (org.apache.accumulo.core.client.Connector)3 BatchScannerOpts (org.apache.accumulo.examples.cli.BatchScannerOpts)3 Random (java.util.Random)2 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 SamplerConfiguration (org.apache.accumulo.core.client.sample.SamplerConfiguration)1 Range (org.apache.accumulo.core.data.Range)1 ClientOpts (org.apache.accumulo.examples.cli.ClientOpts)1 Text (org.apache.hadoop.io.Text)1