mikewalch commented on a change in pull request #11: Fixes #10 - Update
helloworld example to new Connector builder
URL: https://github.com/apache/accumulo-examples/pull/11#discussion_r178435260
##########
File path:
src/main/java/org/apache/accumulo/examples/helloworld/InsertWithBatchWriter.java
##########
@@ -20,46 +20,42 @@
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.MultiTableBatchWriter;
-import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.TableExistsException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.examples.cli.BatchWriterOpts;
-import org.apache.accumulo.examples.cli.ClientOnRequiredTable;
import org.apache.hadoop.io.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Inserts 10K rows (50K entries) into accumulo with each row having 5 entries.
*/
public class InsertWithBatchWriter {
- public static void main(String[] args) throws AccumuloException,
AccumuloSecurityException, MutationsRejectedException, TableExistsException,
+ private static final Logger log =
LoggerFactory.getLogger(InsertWithBatchWriter.class);
+
+ public static void main(String[] args) throws AccumuloException,
AccumuloSecurityException, TableExistsException,
TableNotFoundException {
- ClientOnRequiredTable opts = new ClientOnRequiredTable();
- BatchWriterOpts bwOpts = new BatchWriterOpts();
- opts.parseArgs(InsertWithBatchWriter.class.getName(), args, bwOpts);
- Connector connector = opts.getConnector();
- MultiTableBatchWriter mtbw =
connector.createMultiTableBatchWriter(bwOpts.getBatchWriterConfig());
+ Connector connector =
Connector.builder().usingProperties("conf/accumulo-client.properties").build();
- if (!connector.tableOperations().exists(opts.getTableName()))
- connector.tableOperations().create(opts.getTableName());
- BatchWriter bw = mtbw.getBatchWriter(opts.getTableName());
+ if (!connector.tableOperations().exists("hellotable")) {
+ connector.tableOperations().create("hellotable");
+ }
- Text colf = new Text("colfam");
- System.out.println("writing ...");
- for (int i = 0; i < 10000; i++) {
- Mutation m = new Mutation(new Text(String.format("row_%d", i)));
- for (int j = 0; j < 5; j++) {
- m.put(colf, new Text(String.format("colqual_%d", j)), new
Value((String.format("value_%d_%d", i, j)).getBytes()));
+ try (BatchWriter bw = connector.createBatchWriter("hellotable")) {
+ Text colf = new Text("colfam");
+ log.trace("writing ...");
+ for (int i = 0; i < 10000; i++) {
+ Mutation m = new Mutation(new Text(String.format("row_%d", i)));
+ for (int j = 0; j < 5; j++) {
+ m.put(colf, new Text(String.format("colqual_%d", j)), new
Value((String.format("value_%d_%d", i, j)).getBytes()));
+ }
+ bw.addMutation(m);
+ if (i % 100 == 0)
+ log.trace(String.valueOf(i));
Review comment:
I want users to be able to the class doing the logging. Also, logging is
now automatically set up for the user so there is no risk they won't see these
messages.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services