Search in sources :

Example 46 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project accumulo by apache.

the class SummaryIT method getTimestampStats.

private LongSummaryStatistics getTimestampStats(final String table, AccumuloClient c, String startRow, String endRow) throws TableNotFoundException {
    try (Scanner scanner = c.createScanner(table, Authorizations.EMPTY)) {
        scanner.setRange(new Range(startRow, false, endRow, true));
        Stream<Entry<Key, Value>> stream = StreamSupport.stream(scanner.spliterator(), false);
        return stream.mapToLong(e -> e.getKey().getTimestamp()).summaryStatistics();
    }
}
Also used : Arrays(java.util.Arrays) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) SortedSet(java.util.SortedSet) Collectors.counting(java.util.stream.Collectors.counting) DELETES_IGNORED_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.DELETES_IGNORED_STAT) TOO_MANY_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.TOO_MANY_STAT) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) IntPredicate(java.util.function.IntPredicate) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) MIN_TIMESTAMP_STAT(org.apache.accumulo.test.functional.BasicSummarizer.MIN_TIMESTAMP_STAT) Summarizer(org.apache.accumulo.core.client.summary.Summarizer) TOTAL_STAT(org.apache.accumulo.test.functional.BasicSummarizer.TOTAL_STAT) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) Value(org.apache.accumulo.core.data.Value) AfterClass(org.junit.AfterClass) PatternSyntaxException(java.util.regex.PatternSyntaxException) TOO_LONG_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.TOO_LONG_STAT) Collection(java.util.Collection) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Set(java.util.Set) SecurityErrorCode(org.apache.accumulo.core.client.security.SecurityErrorCode) Collectors(java.util.stream.Collectors) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) List(java.util.List) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Filter(org.apache.accumulo.core.iterators.Filter) Stream(java.util.stream.Stream) FamilySummarizer(org.apache.accumulo.core.client.summary.summarizers.FamilySummarizer) DELETES_STAT(org.apache.accumulo.test.functional.BasicSummarizer.DELETES_STAT) CompactionSelector(org.apache.accumulo.core.client.admin.compaction.CompactionSelector) Function.identity(java.util.function.Function.identity) Entry(java.util.Map.Entry) Scanner(org.apache.accumulo.core.client.Scanner) SEEN_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.SEEN_STAT) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) VisibilitySummarizer(org.apache.accumulo.core.client.summary.summarizers.VisibilitySummarizer) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Assert.assertThrows(org.junit.Assert.assertThrows) UtilWaitThread(org.apache.accumulo.fate.util.UtilWaitThread) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) FileStatistics(org.apache.accumulo.core.client.summary.Summary.FileStatistics) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Accumulo(org.apache.accumulo.core.client.Accumulo) TreeSet(java.util.TreeSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TablePermission(org.apache.accumulo.core.security.TablePermission) Lists(com.google.common.collect.Lists) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) EMITTED_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.EMITTED_STAT) MAX_TIMESTAMP_STAT(org.apache.accumulo.test.functional.BasicSummarizer.MAX_TIMESTAMP_STAT) StreamSupport(java.util.stream.StreamSupport) CounterSummary(org.apache.accumulo.core.client.summary.CounterSummary) LongSummaryStatistics(java.util.LongSummaryStatistics) Summary(org.apache.accumulo.core.client.summary.Summary) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SummaryRetriever(org.apache.accumulo.core.client.admin.SummaryRetriever) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) AccumuloServerException(org.apache.accumulo.core.clientImpl.AccumuloServerException) SharedMiniClusterBase(org.apache.accumulo.harness.SharedMiniClusterBase) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Scanner(org.apache.accumulo.core.client.Scanner) Entry(java.util.Map.Entry) Range(org.apache.accumulo.core.data.Range)

Example 47 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project accumulo by apache.

the class SummaryIT method selectionTest.

@Test
public void selectionTest() throws Exception {
    final String table = getUniqueNames(1)[0];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        NewTableConfiguration ntc = new NewTableConfiguration();
        SummarizerConfiguration sc1 = SummarizerConfiguration.builder(BasicSummarizer.class).build();
        SummarizerConfiguration sc2 = SummarizerConfiguration.builder(KeySizeSummarizer.class).addOption("maxLen", "512").build();
        ntc.enableSummarization(sc1, sc2);
        c.tableOperations().create(table, ntc);
        BatchWriter bw = writeData(table, c);
        bw.close();
        c.tableOperations().flush(table, null, null, true);
        LongSummaryStatistics stats = getTimestampStats(table, c);
        Collection<Summary> summaries = c.tableOperations().summaries(table).withConfiguration(sc2).retrieve();
        assertEquals(1, summaries.size());
        checkSummary(summaries, sc2, "len=14", 100_000L);
        summaries = c.tableOperations().summaries(table).withConfiguration(sc1).retrieve();
        assertEquals(1, summaries.size());
        checkSummary(summaries, sc1, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        // retrieve a nonexistent summary
        SummarizerConfiguration sc3 = SummarizerConfiguration.builder(KeySizeSummarizer.class.getName()).addOption("maxLen", "256").build();
        summaries = c.tableOperations().summaries(table).withConfiguration(sc3).retrieve();
        assertEquals(0, summaries.size());
        summaries = c.tableOperations().summaries(table).withConfiguration(sc1, sc2).retrieve();
        assertEquals(2, summaries.size());
        checkSummary(summaries, sc1, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        checkSummary(summaries, sc2, "len=14", 100_000L);
        summaries = c.tableOperations().summaries(table).retrieve();
        assertEquals(2, summaries.size());
        checkSummary(summaries, sc1, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        checkSummary(summaries, sc2, "len=14", 100_000L);
        summaries = c.tableOperations().summaries(table).withMatchingConfiguration(".*BasicSummarizer \\{\\}.*").retrieve();
        assertEquals(1, summaries.size());
        checkSummary(summaries, sc1, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        summaries = c.tableOperations().summaries(table).withMatchingConfiguration(".*KeySizeSummarizer \\{maxLen=512\\}.*").retrieve();
        assertEquals(1, summaries.size());
        checkSummary(summaries, sc2, "len=14", 100_000L);
        summaries = c.tableOperations().summaries(table).withMatchingConfiguration(".*KeySizeSummarizer \\{maxLen=256\\}.*").retrieve();
        assertEquals(0, summaries.size());
        summaries = c.tableOperations().summaries(table).withMatchingConfiguration(".*BasicSummarizer \\{\\}.*").withConfiguration(sc2).retrieve();
        assertEquals(2, summaries.size());
        checkSummary(summaries, sc1, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        checkSummary(summaries, sc2, "len=14", 100_000L);
        // Ensure a bad regex fails fast.
        assertThrows("Bad regex should have caused exception", PatternSyntaxException.class, () -> c.tableOperations().summaries(table).withMatchingConfiguration(".*KeySizeSummarizer {maxLen=256}.*").retrieve());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) LongSummaryStatistics(java.util.LongSummaryStatistics) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) CounterSummary(org.apache.accumulo.core.client.summary.CounterSummary) Summary(org.apache.accumulo.core.client.summary.Summary) BatchWriter(org.apache.accumulo.core.client.BatchWriter) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Test(org.junit.Test)

Aggregations

LongSummaryStatistics (java.util.LongSummaryStatistics)47 Test (org.junit.Test)18 List (java.util.List)15 Map (java.util.Map)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 ArrayList (java.util.ArrayList)10 Collectors (java.util.stream.Collectors)10 Set (java.util.Set)9 TimeUnit (java.util.concurrent.TimeUnit)9 LoggerFactory (org.slf4j.LoggerFactory)9 HashMap (java.util.HashMap)8 Logger (org.slf4j.Logger)8 BaseTest (io.scalecube.testlib.BaseTest)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5 Collections (java.util.Collections)4 Comparator (java.util.Comparator)4 Entry (java.util.Map.Entry)4