Search in sources :

Example 1 with BatchWriterOpts

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

the class Reverse method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    ScannerOpts scanOpts = new ScannerOpts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(Reverse.class.getName(), args, scanOpts, bwOpts);
    Connector conn = opts.getConnector();
    Scanner scanner = conn.createScanner(opts.shardTable, opts.auths);
    scanner.setBatchSize(scanOpts.scanBatchSize);
    BatchWriter bw = conn.createBatchWriter(opts.doc2TermTable, bwOpts.getBatchWriterConfig());
    for (Entry<Key, Value> entry : scanner) {
        Key key = entry.getKey();
        Mutation m = new Mutation(key.getColumnQualifier());
        m.put(key.getColumnFamily(), new Text(), new Value(new byte[0]));
        bw.addMutation(m);
    }
    bw.close();
}
Also used : ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) ClientOpts(org.apache.accumulo.examples.cli.ClientOpts) Value(org.apache.accumulo.core.data.Value) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key)

Example 2 with BatchWriterOpts

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

the class SampleExample method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(RandomBatchWriter.class.getName(), args, bwOpts);
    Connector conn = opts.getConnector();
    if (!conn.tableOperations().exists(opts.getTableName())) {
        conn.tableOperations().create(opts.getTableName());
    } else {
        System.out.println("Table exists, not doing anything.");
        return;
    }
    // write some data
    BatchWriter bw = conn.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
    bw.addMutation(createMutation("9225", "abcde", "file://foo.txt"));
    bw.addMutation(createMutation("8934", "accumulo scales", "file://accumulo_notes.txt"));
    bw.addMutation(createMutation("2317", "milk, eggs, bread, parmigiano-reggiano", "file://groceries/9/txt"));
    bw.addMutation(createMutation("3900", "EC2 ate my homework", "file://final_project.txt"));
    bw.flush();
    SamplerConfiguration sc1 = new SamplerConfiguration(RowSampler.class.getName());
    sc1.setOptions(ImmutableMap.of("hasher", "murmur3_32", "modulus", "3"));
    conn.tableOperations().setSamplerConfiguration(opts.getTableName(), sc1);
    Scanner scanner = conn.createScanner(opts.getTableName(), Authorizations.EMPTY);
    System.out.println("Scanning all data :");
    print(scanner);
    System.out.println();
    System.out.println("Scanning with sampler configuration.  Data was written before sampler was set on table, scan should fail.");
    scanner.setSamplerConfiguration(sc1);
    try {
        print(scanner);
    } catch (SampleNotPresentException e) {
        System.out.println("  Saw sample not present exception as expected.");
    }
    System.out.println();
    // compact table to recreate sample data
    conn.tableOperations().compact(opts.getTableName(), new CompactionConfig().setCompactionStrategy(NO_SAMPLE_STRATEGY));
    System.out.println("Scanning after compaction (compaction should have created sample data) : ");
    print(scanner);
    System.out.println();
    // update a document in the sample data
    bw.addMutation(createMutation("2317", "milk, eggs, bread, parmigiano-reggiano, butter", "file://groceries/9/txt"));
    bw.close();
    System.out.println("Scanning sample after updating content for docId 2317 (should see content change in sample data) : ");
    print(scanner);
    System.out.println();
    // change tables sampling configuration...
    SamplerConfiguration sc2 = new SamplerConfiguration(RowSampler.class.getName());
    sc2.setOptions(ImmutableMap.of("hasher", "murmur3_32", "modulus", "2"));
    conn.tableOperations().setSamplerConfiguration(opts.getTableName(), sc2);
    // compact table to recreate sample data using new configuration
    conn.tableOperations().compact(opts.getTableName(), new CompactionConfig().setCompactionStrategy(NO_SAMPLE_STRATEGY));
    System.out.println("Scanning with old sampler configuration.  Sample data was created using new configuration with a compaction.  Scan should fail.");
    try {
        // try scanning with old sampler configuration
        print(scanner);
    } catch (SampleNotPresentException e) {
        System.out.println("  Saw sample not present exception as expected ");
    }
    System.out.println();
    // update expected sampler configuration on scanner
    scanner.setSamplerConfiguration(sc2);
    System.out.println("Scanning with new sampler configuration : ");
    print(scanner);
    System.out.println();
}
Also used : RowSampler(org.apache.accumulo.core.client.sample.RowSampler) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) RandomBatchWriter(org.apache.accumulo.examples.client.RandomBatchWriter) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) RandomBatchWriter(org.apache.accumulo.examples.client.RandomBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 3 with BatchWriterOpts

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

the class Index method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(Index.class.getName(), args, bwOpts);
    String splitRegex = "\\W+";
    BatchWriter bw = opts.getConnector().createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
    for (String filename : opts.files) {
        index(opts.partitions, new File(filename), splitRegex, bw);
    }
    bw.close();
}
Also used : BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriter(org.apache.accumulo.core.client.BatchWriter) File(java.io.File)

Example 4 with BatchWriterOpts

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

the class InterferenceTest method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(InterferenceTest.class.getName(), args, bwOpts);
    if (opts.iterations < 1)
        opts.iterations = Long.MAX_VALUE;
    Connector conn = opts.getConnector();
    if (!conn.tableOperations().exists(opts.getTableName()))
        conn.tableOperations().create(opts.getTableName());
    Thread writer = new Thread(new Writer(conn.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig()), opts.iterations));
    writer.start();
    Reader r;
    if (opts.isolated)
        r = new Reader(new IsolatedScanner(conn.createScanner(opts.getTableName(), opts.auths)));
    else
        r = new Reader(conn.createScanner(opts.getTableName(), opts.auths));
    Thread reader;
    reader = new Thread(r);
    reader.start();
    writer.join();
    r.stopNow();
    reader.join();
    System.out.println("finished");
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 5 with BatchWriterOpts

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

the class FileCount method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    ScannerOpts scanOpts = new ScannerOpts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    String programName = FileCount.class.getName();
    opts.parseArgs(programName, args, scanOpts, bwOpts);
    FileCount fileCount = new FileCount(opts.getConnector(), opts.getTableName(), opts.auths, opts.visibility, scanOpts, bwOpts);
    fileCount.run();
}
Also used : ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts)

Aggregations

BatchWriterOpts (org.apache.accumulo.examples.cli.BatchWriterOpts)11 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 Connector (org.apache.accumulo.core.client.Connector)7 Scanner (org.apache.accumulo.core.client.Scanner)4 Mutation (org.apache.accumulo.core.data.Mutation)4 ScannerOpts (org.apache.accumulo.examples.cli.ScannerOpts)4 Value (org.apache.accumulo.core.data.Value)3 ClientOpts (org.apache.accumulo.examples.cli.ClientOpts)3 Text (org.apache.hadoop.io.Text)3 File (java.io.File)2 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)2 Key (org.apache.accumulo.core.data.Key)2 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Random (java.util.Random)1 Set (java.util.Set)1 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)1