Search in sources :

Example 6 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)

Example 7 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 {
    Job job = Job.getInstance();
    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<Job> 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.getConfiguration());
    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) 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) Job(org.apache.hadoop.mapreduce.Job) Test(org.junit.Test)

Example 8 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(AccumuloClient client, String tableName) {
    TableOperations tops = client.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
        @SuppressWarnings("deprecation") var statusCombinerClass = org.apache.accumulo.server.replication.StatusCombiner.class;
        IteratorSetting setting = new IteratorSetting(9, COMBINER_NAME, statusCombinerClass);
        Combiner.setColumns(setting, Collections.singletonList(new Column(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
    Map<String, String> properties;
    try {
        properties = tops.getConfiguration(tableName);
    } catch (AccumuloException | TableNotFoundException e) {
        throw new RuntimeException(e);
    }
    for (Entry<String, String> property : properties.entrySet()) {
        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);
                }
            }
            // 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) 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 9 with Column

use of org.apache.accumulo.core.client.IteratorSetting.Column in project accumulo by apache.

the class ReplicationIT method verifyReplicationTableConfig.

@Test
public void verifyReplicationTableConfig() throws AccumuloException, TableNotFoundException, AccumuloSecurityException {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
        TableOperations tops = client.tableOperations();
        Map<String, EnumSet<IteratorScope>> iterators = tops.listIterators(ReplicationTable.NAME);
        // verify combiners are only iterators (no versioning)
        assertEquals(1, iterators.size());
        // look for combiner
        assertTrue(iterators.containsKey(ReplicationTable.COMBINER_NAME));
        assertTrue(iterators.get(ReplicationTable.COMBINER_NAME).containsAll(EnumSet.allOf(IteratorScope.class)));
        for (IteratorScope scope : EnumSet.allOf(IteratorScope.class)) {
            IteratorSetting is = tops.getIteratorSetting(ReplicationTable.NAME, ReplicationTable.COMBINER_NAME, scope);
            assertEquals(30, is.getPriority());
            assertEquals(StatusCombiner.class.getName(), is.getIteratorClass());
            assertEquals(1, is.getOptions().size());
            assertTrue(is.getOptions().containsKey("columns"));
            String cols = is.getOptions().get("columns");
            Column statusSectionCol = new Column(StatusSection.NAME);
            Column workSectionCol = new Column(WorkSection.NAME);
            assertEquals(ColumnSet.encodeColumns(statusSectionCol.getColumnFamily(), statusSectionCol.getColumnQualifier()) + "," + ColumnSet.encodeColumns(workSectionCol.getColumnFamily(), workSectionCol.getColumnQualifier()), cols);
        }
        boolean foundLocalityGroups = false;
        boolean foundLocalityGroupDef1 = false;
        boolean foundLocalityGroupDef2 = false;
        boolean foundFormatter = false;
        Joiner j = Joiner.on(",");
        for (Entry<String, String> p : tops.getProperties(ReplicationTable.NAME)) {
            String key = p.getKey();
            String val = p.getValue();
            // STATUS_LG_NAME, STATUS_LG_COLFAMS, WORK_LG_NAME, WORK_LG_COLFAMS
            if (key.equals(Property.TABLE_FORMATTER_CLASS.getKey()) && val.equals(StatusFormatter.class.getName())) {
                // look for formatter
                foundFormatter = true;
            } else if (key.equals(Property.TABLE_LOCALITY_GROUPS.getKey()) && val.equals(j.join(ReplicationTable.LOCALITY_GROUPS.keySet()))) {
                // look for locality groups enabled
                foundLocalityGroups = true;
            } else if (key.startsWith(Property.TABLE_LOCALITY_GROUP_PREFIX.getKey())) {
                // look for locality group column family definitions
                if (key.equals(Property.TABLE_LOCALITY_GROUP_PREFIX.getKey() + ReplicationTable.STATUS_LG_NAME) && val.equals(j.join(Iterables.transform(ReplicationTable.STATUS_LG_COLFAMS, Text::toString)))) {
                    foundLocalityGroupDef1 = true;
                } else if (key.equals(Property.TABLE_LOCALITY_GROUP_PREFIX.getKey() + ReplicationTable.WORK_LG_NAME) && val.equals(j.join(Iterables.transform(ReplicationTable.WORK_LG_COLFAMS, Text::toString)))) {
                    foundLocalityGroupDef2 = true;
                }
            }
        }
        assertTrue(foundLocalityGroups);
        assertTrue(foundLocalityGroupDef1);
        assertTrue(foundLocalityGroupDef2);
        assertTrue(foundFormatter);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Joiner(com.google.common.base.Joiner) EnumSet(java.util.EnumSet) Text(org.apache.hadoop.io.Text) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Column(org.apache.accumulo.core.client.IteratorSetting.Column) StatusCombiner(org.apache.accumulo.server.replication.StatusCombiner) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.Test)

Aggregations

Column (org.apache.accumulo.core.client.IteratorSetting.Column)9 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)8 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 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)2 Authorizations (org.apache.accumulo.core.security.Authorizations)2 InputTableConfig (org.apache.accumulo.hadoopImpl.mapreduce.InputTableConfig)2 Joiner (com.google.common.base.Joiner)1 CombinerConfiguration (datawave.ingest.table.aggregator.CombinerConfiguration)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Key (org.apache.accumulo.core.data.Key)1