use of org.apache.accumulo.core.client.RowIterator in project accumulo by apache.
the class TabletStateChangeIteratorIT method copyTable.
/**
* Create a copy of the source table by first gathering all the rows of the source in a list of
* mutations. Then create the copy of the table and apply the mutations to the copy.
*/
private void copyTable(AccumuloClient client, String source, String copy) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
try {
dropTables(client, copy);
} catch (TableNotFoundException ex) {
// ignored
}
log.info("Gathering rows to copy {} ", source);
List<Mutation> mutations = new ArrayList<>();
try (Scanner scanner = client.createScanner(source, Authorizations.EMPTY)) {
RowIterator rows = new RowIterator(new IsolatedScanner(scanner));
while (rows.hasNext()) {
Iterator<Entry<Key, Value>> row = rows.next();
Mutation m = null;
while (row.hasNext()) {
Entry<Key, Value> entry = row.next();
Key k = entry.getKey();
if (m == null)
m = new Mutation(k.getRow());
m.put(k.getColumnFamily(), k.getColumnQualifier(), k.getColumnVisibilityParsed(), k.getTimestamp(), entry.getValue());
}
mutations.add(m);
}
}
// metadata should be stable with only 7 rows (1 replication + 2 for each table)
log.debug("Gathered {} rows to create copy {}", mutations.size(), copy);
assertEquals("Metadata should have 7 rows (1 repl + 2 for each table)", 7, mutations.size());
client.tableOperations().create(copy);
try (BatchWriter writer = client.createBatchWriter(copy)) {
for (Mutation m : mutations) {
writer.addMutation(m);
}
}
log.info("Finished creating copy " + copy);
}
Aggregations