protected AccumuloRecordWriter(TaskAttemptContext context) throws AccumuloException, AccumuloSecurityException, IOException { Level l = getLogLevel(context); if (l != null) log.setLevel(getLogLevel(context)); this.simulate = getSimulationMode(context); this.createTables = canCreateTables(context); if (simulate) log.info("Simulating output only. No writes to tables will occur"); this.bws = new HashMap<Text, BatchWriter>(); String tname = getDefaultTableName(context); this.defaultTableName = (tname == null) ? null : new Text(tname); if (!simulate) { this.conn = getInstance(context) .getConnector(getPrincipal(context), getAuthenticationToken(context)); mtbw = conn.createMultiTableBatchWriter(getBatchWriterOptions(context)); } }
public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException { System.out.println("START"); String instanceName = "development"; String zooKeepers = "localhost"; String user = "******"; byte[] pass = "******".getBytes(); String tableName = "users"; ZooKeeperInstance instance = new ZooKeeperInstance(instanceName, zooKeepers); Connector connector = instance.getConnector(user, pass); MultiTableBatchWriter writer = connector.createMultiTableBatchWriter(200000l, 300, 4); if (!connector.tableOperations().exists(tableName)) { connector.tableOperations().create(tableName); } BatchWriter bw = writer.getBatchWriter(tableName); try { String userId = "medined"; int age = 48; int height = 70; Mutation m = new Mutation(new Text(userId)); m.put(new Text("age"), new Text(""), new Value(new Integer(age).toString().getBytes())); m.put(new Text("height"), new Text(""), new Value(new Integer(height).toString().getBytes())); bw.addMutation(m); } finally { if (writer != null) { writer.close(); } } System.out.println("END"); }