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);
}
}
Aggregations