Search in sources :

Example 36 with SummarizerConfiguration

use of org.apache.accumulo.core.client.summary.SummarizerConfiguration in project accumulo by apache.

the class SummaryIT method testExceptions.

@Test
public void testExceptions() throws Exception {
    Connector c = getConnector();
    try {
        c.tableOperations().summaries("foo").retrieve();
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        c.tableOperations().addSummarizers("foo", SummarizerConfiguration.builder(VisibilitySummarizer.class).build());
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        c.tableOperations().listSummarizers("foo");
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        c.tableOperations().removeSummarizers("foo", sc -> true);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    SummarizerConfiguration sc1 = SummarizerConfiguration.builder(FamilySummarizer.class).setPropertyId("p1").build();
    SummarizerConfiguration sc2 = SummarizerConfiguration.builder(VisibilitySummarizer.class).setPropertyId("p1").build();
    c.tableOperations().create("foo");
    c.tableOperations().addSummarizers("foo", sc1);
    c.tableOperations().addSummarizers("foo", sc1);
    try {
        // adding second summarizer with same id should fail
        c.tableOperations().addSummarizers("foo", sc2);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    }
    c.tableOperations().removeSummarizers("foo", sc -> true);
    Assert.assertEquals(0, c.tableOperations().listSummarizers("foo").size());
    try {
        // adding two summarizers at the same time with same id should fail
        c.tableOperations().addSummarizers("foo", sc1, sc2);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    }
    Assert.assertEquals(0, c.tableOperations().listSummarizers("foo").size());
    c.tableOperations().offline("foo", true);
    try {
        c.tableOperations().summaries("foo").retrieve();
        Assert.fail();
    } catch (TableOfflineException e) {
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Test(org.junit.Test)

Example 37 with SummarizerConfiguration

use of org.apache.accumulo.core.client.summary.SummarizerConfiguration in project accumulo by apache.

the class SummarizerConfigurationUtil method getSummarizerConfigsFiltered.

private static List<SummarizerConfiguration> getSummarizerConfigsFiltered(SortedMap<String, String> sprops) {
    if (sprops.size() == 0) {
        return Collections.emptyList();
    }
    SummarizerConfiguration.Builder builder = null;
    List<SummarizerConfiguration> configs = new ArrayList<>();
    final int preLen = Property.TABLE_SUMMARIZER_PREFIX.getKey().length();
    for (Entry<String, String> entry : sprops.entrySet()) {
        String k = entry.getKey().substring(preLen);
        String[] tokens = k.split("\\.");
        String id = tokens[0];
        if (tokens.length == 1) {
            if (builder != null) {
                configs.add(builder.build());
            }
            builder = SummarizerConfiguration.builder(entry.getValue()).setPropertyId(id);
        } else if (tokens.length == 3 || tokens[1].equals("opt")) {
            builder.addOption(tokens[2], entry.getValue());
        } else {
            throw new IllegalArgumentException("Unable to parse summarizer property : " + k);
        }
    }
    configs.add(builder.build());
    return configs;
}
Also used : ArrayList(java.util.ArrayList) Builder(org.apache.accumulo.core.client.summary.SummarizerConfiguration.Builder) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration)

Example 38 with SummarizerConfiguration

use of org.apache.accumulo.core.client.summary.SummarizerConfiguration in project accumulo by apache.

the class SummarizerConfigurationUtil method toTablePropertiesMap.

public static Map<String, String> toTablePropertiesMap(List<SummarizerConfiguration> summarizers) {
    if (summarizers.size() == 0) {
        return Collections.emptyMap();
    }
    Map<String, String> props = new HashMap<>();
    for (SummarizerConfiguration sconf : summarizers) {
        String cid = sconf.getPropertyId();
        String prefix = Property.TABLE_SUMMARIZER_PREFIX.getKey() + cid;
        if (props.containsKey(prefix)) {
            throw new IllegalArgumentException("Duplicate summarizer config id : " + cid);
        }
        props.put(prefix, sconf.getClassName());
        Set<Entry<String, String>> es = sconf.getOptions().entrySet();
        StringBuilder sb = new StringBuilder(prefix + ".opt.");
        int resetLen = sb.length();
        for (Entry<String, String> entry : es) {
            sb.append(entry.getKey());
            props.put(sb.toString(), entry.getValue());
            sb.setLength(resetLen);
        }
    }
    return props;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration)

Example 39 with SummarizerConfiguration

use of org.apache.accumulo.core.client.summary.SummarizerConfiguration in project accumulo by apache.

the class SummaryCollection method getSummaries.

public List<Summary> getSummaries() {
    ArrayList<Summary> ret = new ArrayList<>(mergedSummaries.size());
    for (Entry<SummarizerConfiguration, MergedSummary> entry : mergedSummaries.entrySet()) {
        SummarizerConfiguration config = entry.getKey();
        MergedSummary ms = entry.getValue();
        ret.add(new Summary(ms.summary, config, totalFiles, (totalFiles - deletedFiles) - ms.filesContaining, ms.filesExceedingBoundry, ms.filesLarge, deletedFiles));
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Summary(org.apache.accumulo.core.client.summary.Summary) TSummary(org.apache.accumulo.core.data.thrift.TSummary) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration)

Example 40 with SummarizerConfiguration

use of org.apache.accumulo.core.client.summary.SummarizerConfiguration in project accumulo by apache.

the class SummaryReader method load.

private static List<SummarySerializer> load(BlockReader bcReader, Predicate<SummarizerConfiguration> summarySelector) throws IOException {
    try (DataInputStream in = bcReader.getMetaBlock(SummaryWriter.METASTORE_INDEX)) {
        List<SummarySerializer> stores = new ArrayList<>();
        readHeader(in);
        int numSummaries = WritableUtils.readVInt(in);
        for (int i = 0; i < numSummaries; i++) {
            SummarizerConfiguration conf = readConfig(in);
            boolean inline = in.readBoolean();
            if (inline) {
                if (summarySelector.test(conf)) {
                    stores.add(SummarySerializer.load(conf, in));
                } else {
                    SummarySerializer.skip(in);
                }
            } else {
                int block = WritableUtils.readVInt(in);
                int offset = WritableUtils.readVInt(in);
                if (summarySelector.test(conf)) {
                    try (DataInputStream summaryIn = bcReader.getMetaBlock(SummaryWriter.METASTORE_PREFIX + "." + block)) {
                        long skipped = in.skip(offset);
                        while (skipped < offset) {
                            skipped += in.skip(offset - skipped);
                        }
                        stores.add(SummarySerializer.load(conf, summaryIn));
                    } catch (MetaBlockDoesNotExist e) {
                        // this is unexpected
                        throw new IOException(e);
                    }
                }
            }
        }
        return stores;
    } catch (MetaBlockDoesNotExist e) {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) MetaBlockDoesNotExist(org.apache.accumulo.core.file.rfile.bcfile.MetaBlockDoesNotExist) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) DataInputStream(java.io.DataInputStream) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration)

Aggregations

SummarizerConfiguration (org.apache.accumulo.core.client.summary.SummarizerConfiguration)41 Test (org.junit.Test)33 HashMap (java.util.HashMap)28 Key (org.apache.accumulo.core.data.Key)22 Value (org.apache.accumulo.core.data.Value)22 Collector (org.apache.accumulo.core.client.summary.Summarizer.Collector)19 EntryLengthSummarizer (org.apache.accumulo.core.client.summary.summarizers.EntryLengthSummarizer)16 Summary (org.apache.accumulo.core.client.summary.Summary)13 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)10 CounterSummary (org.apache.accumulo.core.client.summary.CounterSummary)10 Connector (org.apache.accumulo.core.client.Connector)9 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 Text (org.apache.hadoop.io.Text)8 FamilySummarizer (org.apache.accumulo.core.client.summary.summarizers.FamilySummarizer)7 ArrayList (java.util.ArrayList)6 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)6 IOException (java.io.IOException)5 Collection (java.util.Collection)5 Map (java.util.Map)5 Entry (java.util.Map.Entry)5