Search in sources :

Example 6 with MultiTableBatchWriter

use of org.apache.accumulo.core.client.MultiTableBatchWriter in project accumulo by apache.

the class TestMultiTableIngest method main.

public static void main(String[] args) throws Exception {
    ArrayList<String> tableNames = new ArrayList<>();
    Opts opts = new Opts();
    ScannerOpts scanOpts = new ScannerOpts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(TestMultiTableIngest.class.getName(), args, scanOpts, bwOpts);
    // create the test table within accumulo
    Connector connector;
    try {
        connector = opts.getConnector();
    } catch (AccumuloException | AccumuloSecurityException e) {
        throw new RuntimeException(e);
    }
    for (int i = 0; i < opts.tables; i++) {
        tableNames.add(String.format(opts.prefix + "%04d", i));
    }
    if (!opts.readonly) {
        for (String table : tableNames) connector.tableOperations().create(table);
        MultiTableBatchWriter b;
        try {
            b = connector.createMultiTableBatchWriter(bwOpts.getBatchWriterConfig());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        // populate
        for (int i = 0; i < opts.count; i++) {
            Mutation m = new Mutation(new Text(String.format("%06d", i)));
            m.put(new Text("col" + Integer.toString((i % 3) + 1)), new Text("qual"), new Value("junk".getBytes(UTF_8)));
            b.getBatchWriter(tableNames.get(i % tableNames.size())).addMutation(m);
        }
        try {
            b.close();
        } catch (MutationsRejectedException e) {
            throw new RuntimeException(e);
        }
    }
    try {
        readBack(opts, scanOpts, connector, tableNames);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) ClientOpts(org.apache.accumulo.core.cli.ClientOpts) BatchWriterOpts(org.apache.accumulo.core.cli.BatchWriterOpts) ScannerOpts(org.apache.accumulo.core.cli.ScannerOpts) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ScannerOpts(org.apache.accumulo.core.cli.ScannerOpts) Value(org.apache.accumulo.core.data.Value) BatchWriterOpts(org.apache.accumulo.core.cli.BatchWriterOpts) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Aggregations

Connector (org.apache.accumulo.core.client.Connector)6 MultiTableBatchWriter (org.apache.accumulo.core.client.MultiTableBatchWriter)6 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)5 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 IOException (java.io.IOException)2 Mutation (org.apache.accumulo.core.data.Mutation)2 AccumuloTemporalIndexer (org.apache.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BatchWriterOpts (org.apache.accumulo.core.cli.BatchWriterOpts)1 ClientOpts (org.apache.accumulo.core.cli.ClientOpts)1 ScannerOpts (org.apache.accumulo.core.cli.ScannerOpts)1 BatchScanner (org.apache.accumulo.core.client.BatchScanner)1 BatchWriter (org.apache.accumulo.core.client.BatchWriter)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Value (org.apache.accumulo.core.data.Value)1 Configuration (org.apache.hadoop.conf.Configuration)1