Search in sources :

Example 1 with Column

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);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) Column(org.apache.accumulo.core.client.IteratorSetting.Column) EnumSet(java.util.EnumSet) Test(org.junit.Test)

Example 2 with Column

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));
    }
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) InputFormatBuilder(org.apache.accumulo.hadoop.mapreduce.InputFormatBuilder) Text(org.apache.hadoop.io.Text) Properties(java.util.Properties) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) InputTableConfig(org.apache.accumulo.hadoopImpl.mapreduce.InputTableConfig) Column(org.apache.accumulo.core.client.IteratorSetting.Column) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Example 3 with Column

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());
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Column(org.apache.accumulo.core.client.IteratorSetting.Column) DevNull(org.apache.accumulo.core.iterators.DevNull) Key(org.apache.accumulo.core.data.Key) Before(org.junit.Before)

Example 4 with Column

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);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) EnumSet(java.util.EnumSet) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Column(org.apache.accumulo.core.client.IteratorSetting.Column) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 5 with Column

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());
}
Also used : Column(org.apache.accumulo.core.client.IteratorSetting.Column)

Aggregations

Column (org.apache.accumulo.core.client.IteratorSetting.Column)8 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)7 EnumSet (java.util.EnumSet)4 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)4 Test (org.junit.Test)4 Text (org.apache.hadoop.io.Text)3 Properties (java.util.Properties)2 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 Range (org.apache.accumulo.core.data.Range)2 Authorizations (org.apache.accumulo.core.security.Authorizations)2 InputTableConfig (org.apache.accumulo.hadoopImpl.mapreduce.InputTableConfig)2 Joiner (com.google.common.base.Joiner)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Key (org.apache.accumulo.core.data.Key)1 DevNull (org.apache.accumulo.core.iterators.DevNull)1 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)1