use of org.apache.accumulo.core.client.TableNotFoundException in project apex-malhar by apache.
the class AccumuloTestHelper method populateAccumulo.
public static void populateAccumulo() throws IOException {
BatchWriterConfig config = new BatchWriterConfig();
BatchWriter batchwriter = null;
try {
batchwriter = con.createBatchWriter("tab1", config);
} catch (TableNotFoundException e) {
logger.error("error in test helper");
DTThrowable.rethrow(e);
}
try {
for (int i = 0; i < 500; ++i) {
String rowstr = "row" + i;
Mutation mutation = new Mutation(rowstr.getBytes());
for (int j = 0; j < 500; ++j) {
String colstr = "col" + "-" + j;
String valstr = "val" + "-" + i + "-" + j;
mutation.put(colfam0_bytes, colstr.getBytes(), System.currentTimeMillis(), valstr.getBytes());
}
batchwriter.addMutation(mutation);
}
batchwriter.close();
} catch (MutationsRejectedException e) {
logger.error("error in test helper");
DTThrowable.rethrow(e);
}
}
use of org.apache.accumulo.core.client.TableNotFoundException in project apex-malhar by apache.
the class AccumuloTestHelper method getAccumuloTuple.
public static AccumuloTuple getAccumuloTuple(String row, String colFam, String colName) {
Authorizations auths = new Authorizations();
Scanner scan = null;
try {
scan = con.createScanner("tab1", auths);
} catch (TableNotFoundException e) {
logger.error("error in test helper");
DTThrowable.rethrow(e);
}
scan.setRange(new Range(new Text(row)));
scan.fetchColumn(new Text(colFam), new Text(colName));
// assuming only one row
for (Entry<Key, Value> entry : scan) {
AccumuloTuple tuple = new AccumuloTuple();
tuple.setRow(entry.getKey().getRow().toString());
tuple.setColFamily(entry.getKey().getColumnFamily().toString());
tuple.setColName(entry.getKey().getColumnQualifier().toString());
tuple.setColValue(entry.getValue().toString());
return tuple;
}
return null;
}
use of org.apache.accumulo.core.client.TableNotFoundException in project YCSB by brianfrankcooper.
the class AccumuloClient method scan.
@Override
public Status scan(String t, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return Status.ERROR;
}
// There doesn't appear to be a way to create a range for a given
// LENGTH. Just start and end keys. So we'll do this the hard way for
// now:
// Just make the end 'infinity' and only read as much as we need.
scanScanner.clearColumns();
scanScanner.setRange(new Range(new Text(startkey), null));
// If no fields are provided, we assume one column/row.
if (fields != null) {
// And add each of them as fields we want.
for (String field : fields) {
scanScanner.fetchColumn(colFam, new Text(field));
}
}
String rowKey = "";
HashMap<String, ByteIterator> currentHM = null;
int count = 0;
// Begin the iteration.
for (Entry<Key, Value> entry : scanScanner) {
// Check for a new row.
if (!rowKey.equals(entry.getKey().getRow().toString())) {
if (count++ == recordcount) {
// Done reading the last row.
break;
}
rowKey = entry.getKey().getRow().toString();
if (fields != null) {
// Initial Capacity for all keys.
currentHM = new HashMap<String, ByteIterator>(fields.size());
} else {
// An empty result map.
currentHM = new HashMap<String, ByteIterator>();
}
result.add(currentHM);
}
// Now add the key to the hashmap.
Value v = entry.getValue();
byte[] buf = v.get();
currentHM.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
}
return Status.OK;
}
use of org.apache.accumulo.core.client.TableNotFoundException in project YCSB by brianfrankcooper.
the class AccumuloClient method read.
@Override
public Status read(String t, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return Status.ERROR;
}
try {
// Pick out the results we care about.
for (Entry<Key, Value> entry : getRow(new Text(key), null)) {
Value v = entry.getValue();
byte[] buf = v.get();
result.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
}
} catch (Exception e) {
System.err.println("Error trying to reading Accumulo table" + key + e);
return Status.ERROR;
}
return Status.OK;
}
use of org.apache.accumulo.core.client.TableNotFoundException in project Gaffer by gchq.
the class SplitTableTool method run.
@Override
public int run(final String[] arg0) throws OperationException {
LOGGER.info("Running SplitTableTool");
final Configuration conf = getConf();
FileSystem fs;
try {
fs = FileSystem.get(conf);
} catch (final IOException e) {
throw new OperationException("Failed to get Filesystem from configuration: " + e.getMessage(), e);
}
final SortedSet<Text> splits = new TreeSet<>();
try (final BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(new Path(operation.getInputPath())), CommonConstants.UTF_8))) {
String line = br.readLine();
while (line != null) {
splits.add(new Text(line));
line = br.readLine();
}
} catch (final IOException e) {
throw new OperationException(e.getMessage(), e);
}
try {
store.getConnection().tableOperations().addSplits(store.getProperties().getTable(), splits);
LOGGER.info("Added {} splits to table {}", splits.size(), store.getProperties().getTable());
} catch (final TableNotFoundException | AccumuloException | AccumuloSecurityException | StoreException e) {
LOGGER.error("Failed to add {} split points to table {}", splits.size(), store.getProperties().getTable());
throw new OperationException("Failed to add split points to the table specified: " + e.getMessage(), e);
}
return SUCCESS_RESPONSE;
}
Aggregations