use of java.util.LongSummaryStatistics in project lucene-solr by apache.
the class TestDocValuesStatsCollector method testDocsWithLongValues.
public void testDocsWithLongValues() throws IOException {
try (Directory dir = newDirectory();
IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig())) {
String field = "numeric";
int numDocs = TestUtil.nextInt(random(), 1, 100);
long[] docValues = new long[numDocs];
int nextVal = 1;
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
if (random().nextBoolean()) {
// not all documents have a value
doc.add(new NumericDocValuesField(field, nextVal));
doc.add(new StringField("id", "doc" + i, Store.NO));
docValues[i] = nextVal;
++nextVal;
}
indexWriter.addDocument(doc);
}
// 20% of cases delete some docs
if (random().nextDouble() < 0.2) {
for (int i = 0; i < numDocs; i++) {
if (random().nextBoolean()) {
indexWriter.deleteDocuments(new Term("id", "doc" + i));
docValues[i] = 0;
}
}
}
try (DirectoryReader reader = DirectoryReader.open(indexWriter)) {
IndexSearcher searcher = new IndexSearcher(reader);
LongDocValuesStats stats = new LongDocValuesStats(field);
searcher.search(new MatchAllDocsQuery(), new DocValuesStatsCollector(stats));
int expCount = (int) Arrays.stream(docValues).filter(v -> v > 0).count();
assertEquals(expCount, stats.count());
int numDocsWithoutField = (int) getZeroValues(docValues).count();
assertEquals(computeExpMissing(numDocsWithoutField, numDocs, reader), stats.missing());
if (stats.count() > 0) {
LongSummaryStatistics sumStats = getPositiveValues(docValues).summaryStatistics();
assertEquals(sumStats.getMax(), stats.max().longValue());
assertEquals(sumStats.getMin(), stats.min().longValue());
assertEquals(sumStats.getAverage(), stats.mean(), 0.00001);
assertEquals(sumStats.getSum(), stats.sum().longValue());
double variance = computeVariance(docValues, stats.mean, stats.count());
assertEquals(variance, stats.variance(), 0.00001);
assertEquals(Math.sqrt(variance), stats.stdev(), 0.00001);
}
}
}
}
use of java.util.LongSummaryStatistics in project intellij-community by JetBrains.
the class Main method testSummaryStatistics.
public static LongSummaryStatistics testSummaryStatistics(List<String> list) {
LongSummaryStatistics stat = new LongSummaryStatistics();
for (String s : list) {
System.out.println(s);
long length = s.length();
stat.accept(length);
}
return stat;
}
use of java.util.LongSummaryStatistics in project orgzly-android by orgzly.
the class OrgFormatterSpeedTest method test.
public void test(String str) throws IOException {
long t1, t2;
long[] times = new long[ITERATIONS];
for (int i = 0; i < ITERATIONS; i++) {
t1 = System.currentTimeMillis();
OrgFormatter.INSTANCE.parse(str);
t2 = System.currentTimeMillis();
times[i] = t2 - t1;
}
LongSummaryStatistics stats = Arrays.stream(times).skip(SKIP_FIRST).summaryStatistics();
Assert.fail(stats.toString());
}
use of java.util.LongSummaryStatistics in project accumulo by apache.
the class SummaryIT method basicSummaryTest.
@Test
public void basicSummaryTest() throws Exception {
final String table = getUniqueNames(1)[0];
Connector c = getConnector();
NewTableConfiguration ntc = new NewTableConfiguration();
SummarizerConfiguration sc1 = SummarizerConfiguration.builder(BasicSummarizer.class.getName()).build();
ntc.enableSummarization(sc1);
c.tableOperations().create(table, ntc);
BatchWriter bw = writeData(table, c);
Collection<Summary> summaries = c.tableOperations().summaries(table).flush(false).retrieve();
Assert.assertEquals(0, summaries.size());
LongSummaryStatistics stats = getTimestampStats(table, c);
summaries = c.tableOperations().summaries(table).flush(true).retrieve();
checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 100_000l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0l);
Mutation m = new Mutation(String.format("r%09x", 999));
m.put("f1", "q1", "999-0");
m.putDelete("f1", "q2");
bw.addMutation(m);
bw.flush();
c.tableOperations().flush(table, null, null, true);
stats = getTimestampStats(table, c);
summaries = c.tableOperations().summaries(table).retrieve();
checkSummaries(summaries, sc1, 2, 0, 0, TOTAL_STAT, 100_002l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 1l);
bw.close();
c.tableOperations().compact(table, new CompactionConfig().setWait(true));
summaries = c.tableOperations().summaries(table).retrieve();
checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 100_000l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0l);
// split tablet into two
String sp1 = String.format("r%09x", 50_000);
addSplits(table, c, sp1);
summaries = c.tableOperations().summaries(table).retrieve();
checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 100_000l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0l);
// compact 2nd tablet
c.tableOperations().compact(table, new CompactionConfig().setStartRow(new Text(sp1)).setWait(true));
summaries = c.tableOperations().summaries(table).retrieve();
checkSummaries(summaries, sc1, 2, 0, 1, TOTAL_STAT, 113_999l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0l);
// get summaries for first tablet
stats = getTimestampStats(table, c, sp1, null);
summaries = c.tableOperations().summaries(table).startRow(sp1).retrieve();
checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 49_999l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0l);
// compact all tablets and regenerate all summaries
c.tableOperations().compact(table, new CompactionConfig());
summaries = c.tableOperations().summaries(table).retrieve();
stats = getTimestampStats(table, c);
checkSummaries(summaries, sc1, 2, 0, 0, TOTAL_STAT, 100_000l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0l);
summaries = c.tableOperations().summaries(table).startRow(String.format("r%09x", 75_000)).endRow(String.format("r%09x", 80_000)).retrieve();
Summary summary = Iterables.getOnlyElement(summaries);
Assert.assertEquals(1, summary.getFileStatistics().getTotal());
Assert.assertEquals(1, summary.getFileStatistics().getExtra());
long total = summary.getStatistics().get(TOTAL_STAT);
Assert.assertTrue("Total " + total + " out of expected range", total > 0 && total <= 10_000);
// test adding and removing
c.tableOperations().removeSummarizers(table, sc -> sc.getClassName().contains("foo"));
List<SummarizerConfiguration> summarizers = c.tableOperations().listSummarizers(table);
Assert.assertEquals(1, summarizers.size());
Assert.assertTrue(summarizers.contains(sc1));
c.tableOperations().removeSummarizers(table, sc -> sc.getClassName().equals(BasicSummarizer.class.getName()));
summarizers = c.tableOperations().listSummarizers(table);
Assert.assertEquals(0, summarizers.size());
c.tableOperations().compact(table, new CompactionConfig().setWait(true));
summaries = c.tableOperations().summaries(table).retrieve();
Assert.assertEquals(0, summaries.size());
c.tableOperations().addSummarizers(table, sc1);
c.tableOperations().compact(table, new CompactionConfig().setWait(true));
summaries = c.tableOperations().summaries(table).retrieve();
checkSummaries(summaries, sc1, 2, 0, 0, TOTAL_STAT, 100_000l, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0l);
}
use of java.util.LongSummaryStatistics in project hazelcast-jet by hazelcast.
the class LongStreamTest method summaryStatistics.
@Test
public void summaryStatistics() {
LongSummaryStatistics longSummaryStatistics = stream.summaryStatistics();
assertEquals(COUNT, longSummaryStatistics.getCount());
assertEquals(COUNT - 1, longSummaryStatistics.getMax());
assertEquals(0, longSummaryStatistics.getMin());
assertEquals(COUNT * (COUNT - 1) / 2, longSummaryStatistics.getSum());
assertEquals((COUNT - 1) / 2.0, longSummaryStatistics.getAverage(), 0.0);
}
Aggregations