use of org.apache.avro.file.DataFileStream in project spf4j by zolyfarkas.
the class AvroStackSampleSupplier method getMetaData.
@Override
public ProfileMetaData getMetaData(final Instant pfrom, final Instant pto) throws IOException {
Set<String> contexts = new HashSet<>();
Set<String> tags = new HashSet<>();
try (DataFileStream<ApplicationStackSamples> stream = new DataFileStream<>(Files.newInputStream(file), reader)) {
while (stream.hasNext()) {
ApplicationStackSamples samples = stream.next();
Instant sampleFrom = samples.getCollectedFrom();
Instant sampleTo = samples.getCollectedTo();
if ((sampleFrom.compareTo(sampleTo) == 0 && sampleFrom.compareTo(pfrom) >= 0 && sampleFrom.compareTo(pfrom) <= 0) || (sampleFrom.isBefore(pto) && sampleTo.isAfter(pfrom))) {
contexts.add(samples.getContext());
tags.add(samples.getTag());
}
}
}
return new ProfileMetaData(contexts, tags);
}
use of org.apache.avro.file.DataFileStream in project spf4j by zolyfarkas.
the class AvroStackSampleSupplier method getSamples.
@Override
public SampleNode getSamples(final String context, final String tag, final Instant pfrom, final Instant pto) throws IOException {
SampleNode result = null;
try (DataFileStream<ApplicationStackSamples> stream = new DataFileStream<>(Files.newInputStream(file), reader)) {
while (stream.hasNext()) {
ApplicationStackSamples samples = stream.next();
Instant sampleFrom = samples.getCollectedFrom();
Instant sampleTo = samples.getCollectedTo();
if (((sampleFrom.compareTo(sampleTo) == 0 && sampleFrom.compareTo(pfrom) >= 0 && sampleFrom.compareTo(pfrom) <= 0) || (sampleFrom.isBefore(pto) && sampleTo.isAfter(pfrom))) && (tag == null || samples.getTag().equals(tag)) && (context == null || samples.getContext().equals(context))) {
SampleNode currentSamples = Converter.convert(samples.getStackSamples().iterator());
if (result == null) {
result = currentSamples;
} else if (currentSamples != null) {
result.add(currentSamples);
}
}
}
}
return result;
}
use of org.apache.avro.file.DataFileStream in project spf4j by zolyfarkas.
the class AvroStackSampleSupplier method scanLimits.
private synchronized void scanLimits() throws IOException {
if (this.from == null) {
Instant lfrom = Instant.MIN;
Instant lto = Instant.MAX;
try (DataFileStream<ApplicationStackSamples> stream = new DataFileStream<>(Files.newInputStream(file), reader)) {
if (stream.hasNext()) {
ApplicationStackSamples samples = stream.next();
lfrom = samples.getCollectedFrom();
lto = samples.getCollectedTo();
}
while (stream.hasNext()) {
ApplicationStackSamples samples = stream.next();
lto = samples.getCollectedTo();
}
this.from = lfrom;
this.to = lto;
}
}
}
use of org.apache.avro.file.DataFileStream in project spf4j by zolyfarkas.
the class AvroMeasurementStoreReader method getMeasurements.
@Override
public Collection<Schema> getMeasurements(final Predicate<String> filter) throws IOException {
Map<String, Pair<Schema, Set<Long>>> result = new THashMap<>();
try (DataFileStream<TableDef> stream = new DataFileStream<TableDef>(Files.newInputStream(infoFile), new SpecificDatumReader<>(TableDef.class))) {
for (TableDef td : stream) {
String name = td.getName();
if (filter.test(TableDefs.sanitizeName(name))) {
Pair<Schema, Set<Long>> exSch = result.get(name);
if (exSch == null) {
Schema sch = TableDefs.createSchema(td);
Set<Long> ids = new HashSet<>(2);
ids.add(td.getId());
exSch = Pair.of(sch, ids);
result.put(name, exSch);
} else {
exSch.getValue().add(td.getId());
}
}
}
}
return result.values().stream().map(x -> {
Schema sch = x.getKey();
sch.addProp(TimeSeriesRecord.IDS_PROP, x.getValue());
return sch;
}).collect(Collectors.toCollection(() -> new ArrayList<>(result.size())));
}
Aggregations