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();
}
}
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());
}
}
Aggregations