use of org.apache.accumulo.core.client.IteratorSetting.Column in project accumulo by apache.
the class ReplicationTableUtilTest method setsCombinerOnMetadataCorrectly.
@Test
public void setsCombinerOnMetadataCorrectly() throws Exception {
AccumuloClient client = createMock(AccumuloClient.class);
TableOperations tops = createMock(TableOperations.class);
String myMetadataTable = "mymetadata";
Map<String, EnumSet<IteratorScope>> iterators = new HashMap<>();
iterators.put("vers", EnumSet.of(IteratorScope.majc, IteratorScope.minc, IteratorScope.scan));
IteratorSetting combiner = new IteratorSetting(9, "replcombiner", StatusCombiner.class);
Combiner.setColumns(combiner, Collections.singletonList(new Column(ReplicationSection.COLF)));
expect(client.tableOperations()).andReturn(tops);
expect(tops.listIterators(myMetadataTable)).andReturn(iterators);
tops.attachIterator(myMetadataTable, combiner);
expectLastCall().once();
expect(tops.getConfiguration(myMetadataTable)).andReturn(Collections.emptyMap());
tops.setProperty(myMetadataTable, Property.TABLE_FORMATTER_CLASS.getKey(), ReplicationTableUtil.STATUS_FORMATTER_CLASS_NAME);
expectLastCall().once();
replay(client, tops);
ReplicationTableUtil.configureMetadataTable(client, myMetadataTable);
verify(client, tops);
}
use of org.apache.accumulo.core.client.IteratorSetting.Column in project accumulo by apache.
the class MultiTableInputFormatTest method testManyTables.
@Test
public void testManyTables() throws Exception {
JobConf job = new JobConf();
Properties clientProps = org.apache.accumulo.hadoop.mapreduce.AccumuloInputFormatTest.setupClientProperties();
// if auths are not set client will try to get from server, we dont want that here
Authorizations auths = Authorizations.EMPTY;
// set the client properties once then loop over tables
InputFormatBuilder.TableParams<JobConf> opts = AccumuloInputFormat.configure().clientProperties(clientProps);
for (int i = 0; i < 10_000; i++) {
List<Range> ranges = singletonList(new Range("a" + i, "b" + i));
Set<Column> cols = singleton(new Column(new Text("CF" + i), new Text("CQ" + i)));
IteratorSetting iter = new IteratorSetting(50, "iter" + i, "iterclass" + i);
opts.table("table" + i).auths(auths).ranges(ranges).fetchColumns(cols).addIterator(iter);
}
opts.store(job);
// verify
Map<String, InputTableConfig> configs = InputConfigurator.getInputTableConfigs(CLASS, job);
assertEquals(10_000, configs.size());
// create objects to test against
for (int i = 0; i < 10_000; i++) {
InputTableConfig t = new InputTableConfig();
List<Range> ranges = singletonList(new Range("a" + i, "b" + i));
Set<Column> cols = singleton(new Column(new Text("CF" + i), new Text("CQ" + i)));
IteratorSetting iter = new IteratorSetting(50, "iter" + i, "iterclass" + i);
t.setScanAuths(auths).setRanges(ranges).fetchColumns(cols).addIterator(iter);
assertEquals(t, configs.get("table" + i));
}
}
use of org.apache.accumulo.core.client.IteratorSetting.Column in project accumulo by apache.
the class StatusCombinerTest method initCombiner.
@Before
public void initCombiner() throws IOException {
key = new Key();
combiner = new StatusCombiner();
builder = Status.newBuilder();
IteratorSetting cfg = new IteratorSetting(50, StatusCombiner.class);
Combiner.setColumns(cfg, Collections.singletonList(new Column(StatusSection.NAME)));
combiner.init(new DevNull(), cfg.getOptions(), new TestIE());
}
use of org.apache.accumulo.core.client.IteratorSetting.Column in project accumulo by apache.
the class ReplicationTableUtil method configureMetadataTable.
public static synchronized void configureMetadataTable(Connector conn, String tableName) {
TableOperations tops = conn.tableOperations();
Map<String, EnumSet<IteratorScope>> iterators = null;
try {
iterators = tops.listIterators(tableName);
} catch (AccumuloSecurityException | AccumuloException | TableNotFoundException e) {
throw new RuntimeException(e);
}
if (!iterators.containsKey(COMBINER_NAME)) {
// Set our combiner and combine all columns
// Need to set the combiner beneath versioning since we don't want to turn it off
IteratorSetting setting = new IteratorSetting(9, COMBINER_NAME, StatusCombiner.class);
Combiner.setColumns(setting, Collections.singletonList(new Column(MetadataSchema.ReplicationSection.COLF)));
try {
tops.attachIterator(tableName, setting);
} catch (AccumuloSecurityException | AccumuloException | TableNotFoundException e) {
throw new RuntimeException(e);
}
}
// Make sure the StatusFormatter is set on the metadata table
Iterable<Entry<String, String>> properties;
try {
properties = tops.getProperties(tableName);
} catch (AccumuloException | TableNotFoundException e) {
throw new RuntimeException(e);
}
for (Entry<String, String> property : properties) {
if (Property.TABLE_FORMATTER_CLASS.getKey().equals(property.getKey())) {
if (!STATUS_FORMATTER_CLASS_NAME.equals(property.getValue())) {
log.info("Setting formatter for {} from {} to {}", tableName, property.getValue(), STATUS_FORMATTER_CLASS_NAME);
try {
tops.setProperty(tableName, Property.TABLE_FORMATTER_CLASS.getKey(), STATUS_FORMATTER_CLASS_NAME);
} catch (AccumuloException | AccumuloSecurityException e) {
throw new RuntimeException(e);
}
}
// Don't need to keep iterating over the properties after we found the one we were looking for
return;
}
}
// Set the formatter on the table because it wasn't already there
try {
tops.setProperty(tableName, Property.TABLE_FORMATTER_CLASS.getKey(), STATUS_FORMATTER_CLASS_NAME);
} catch (AccumuloException | AccumuloSecurityException e) {
throw new RuntimeException(e);
}
}
use of org.apache.accumulo.core.client.IteratorSetting.Column in project accumulo by apache.
the class Combiner method setColumns.
/**
* A convenience method to set which columns a combiner should be applied to. For each column
* specified, all versions of a Key which match that @{link IteratorSetting.Column} will be
* combined individually in each row. This method is likely to be used in conjunction with
* {@link ScannerBase#fetchColumnFamily(Text)} or {@link ScannerBase#fetchColumn(Text,Text)}.
*
* @param is
* iterator settings object to configure
* @param columns
* a list of columns to encode as the value for the combiner column configuration
*/
public static void setColumns(IteratorSetting is, List<IteratorSetting.Column> columns) {
String sep = "";
StringBuilder sb = new StringBuilder();
for (Column col : columns) {
sb.append(sep);
sep = ",";
sb.append(ColumnSet.encodeColumns(col.getFirst(), col.getSecond()));
}
is.addOption(COLUMNS_OPTION, sb.toString());
}
Aggregations