Search in sources :

Example 1 with Aggregation

use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.

the class TimeSeriesRecord method accumulate.

/**
 * Temporary, until better implementation.
 * @param accumulator
 * @param r2
 */
@Beta
default void accumulate(final TimeSeriesRecord r2) {
    Schema recSchema = getSchema();
    Iterator<Schema.Field> it = recSchema.getFields().iterator();
    it.next();
    put(0, r2.get(0));
    while (it.hasNext()) {
        Schema.Field nf = it.next();
        int pos = nf.pos();
        Aggregation agg;
        String prop = nf.schema().getProp(AGGREGATION_TYPE_PROP);
        if (prop != null) {
            agg = Aggregation.valueOf(prop);
        } else {
            agg = inferAggregationFromName(nf, recSchema);
        }
        switch(agg) {
            case SUM:
                put(pos, ((Long) get(pos)) + ((Long) r2.get(pos)));
                break;
            case MIN:
                put(pos, Math.min((Long) get(pos), ((Long) r2.get(pos))));
                break;
            case MAX:
                put(pos, Math.max((Long) get(pos), ((Long) r2.get(pos))));
                break;
            case FIRST:
                break;
            case LAST:
            case UNKNOWN:
                put(pos, ((Long) r2.get(pos)));
                break;
            default:
                throw new UnsupportedOperationException("Unsupported aggregation: " + agg);
        }
    }
}
Also used : Aggregation(org.spf4j.tsdb2.avro.Aggregation) Schema(org.apache.avro.Schema) Beta(com.google.common.annotations.Beta)

Example 2 with Aggregation

use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.

the class TimeSeriesRecord method accumulateObservations.

@Beta
static void accumulateObservations(final Schema recSchema, final Observation r1, final Observation r2) {
    r1.setRelTimeStamp(r2.getRelTimeStamp());
    r1.setTableDefId(-1L);
    Iterator<Schema.Field> it = recSchema.getFields().iterator();
    it.next();
    List<Long> r1d = r1.getData();
    List<Long> r2d = r2.getData();
    while (it.hasNext()) {
        Schema.Field nf = it.next();
        int pos = nf.pos();
        Aggregation agg;
        String prop = nf.schema().getProp(AGGREGATION_TYPE_PROP);
        if (prop != null) {
            agg = Aggregation.valueOf(prop);
        } else {
            agg = inferAggregationFromName(nf, recSchema);
        }
        int apos = pos - 1;
        switch(agg) {
            case SUM:
                r1d.set(apos, r1d.get(apos) + r2d.get(apos));
                break;
            case MIN:
                r1d.set(apos, Math.min(r1d.get(apos), r2d.get(apos)));
                break;
            case MAX:
                r1d.set(apos, Math.max(r1d.get(apos), r2d.get(apos)));
                break;
            case FIRST:
                break;
            case LAST:
            case UNKNOWN:
                r1d.set(apos, r2d.get(apos));
                break;
            default:
                throw new UnsupportedOperationException("Unsupported aggregation: " + agg);
        }
    }
}
Also used : Aggregation(org.spf4j.tsdb2.avro.Aggregation) Schema(org.apache.avro.Schema) Beta(com.google.common.annotations.Beta)

Example 3 with Aggregation

use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.

the class RecorderFactory method createDirectRecorder.

public static MultiMeasurementRecorder createDirectRecorder(final Object measuredEntity, final String description, final String[] measurementNames, final String[] measurementUnits) {
    Aggregation[] aggs = new Aggregation[measurementNames.length];
    Arrays.fill(aggs, Aggregation.UNKNOWN);
    DirectStoreMultiAccumulator mr = new DirectStoreMultiAccumulator(new MeasurementsInfoImpl(measuredEntity, description, measurementNames, measurementUnits, aggs, MeasurementType.UNTYPED), MEASUREMENT_STORE);
    mr.registerJmx();
    return mr;
}
Also used : Aggregation(org.spf4j.tsdb2.avro.Aggregation) DirectStoreMultiAccumulator(org.spf4j.perf.impl.acc.DirectStoreMultiAccumulator)

Example 4 with Aggregation

use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.

the class RecorderFactory method createDirectRecorder.

public static MultiMeasurementRecorder createDirectRecorder(final Object measuredEntity, final String description, final String[] measurementNames, final String[] measurementUnits, final MeasurementType type) {
    Aggregation[] aggs = new Aggregation[measurementNames.length];
    Arrays.fill(aggs, Aggregation.UNKNOWN);
    DirectStoreMultiAccumulator mr = new DirectStoreMultiAccumulator(new MeasurementsInfoImpl(measuredEntity, description, measurementNames, measurementUnits, aggs, type), MEASUREMENT_STORE);
    mr.registerJmx();
    return mr;
}
Also used : Aggregation(org.spf4j.tsdb2.avro.Aggregation) DirectStoreMultiAccumulator(org.spf4j.perf.impl.acc.DirectStoreMultiAccumulator)

Example 5 with Aggregation

use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.

the class TableDefs method from.

public static TableDef from(final MeasurementsInfo measurement, final int sampleTimeMillis, final long id) {
    int numberOfMeasurements = measurement.getNumberOfMeasurements();
    List<ColumnDef> columns = new ArrayList<>(numberOfMeasurements);
    for (int i = 0; i < numberOfMeasurements; i++) {
        String mname = measurement.getMeasurementName(i);
        String unit = measurement.getMeasurementUnit(i);
        Aggregation aggregation = measurement.getMeasurementAggregation(i);
        ColumnDef cd = new ColumnDef(mname, Type.LONG, unit, "", aggregation);
        columns.add(cd);
    }
    return new TableDef(id, measurement.getMeasuredEntity().toString(), "", columns, sampleTimeMillis, measurement.getMeasurementType());
}
Also used : Aggregation(org.spf4j.tsdb2.avro.Aggregation) ArrayList(java.util.ArrayList) ColumnDef(org.spf4j.tsdb2.avro.ColumnDef) TableDef(org.spf4j.tsdb2.avro.TableDef)

Aggregations

Aggregation (org.spf4j.tsdb2.avro.Aggregation)6 Schema (org.apache.avro.Schema)3 Beta (com.google.common.annotations.Beta)2 DirectStoreMultiAccumulator (org.spf4j.perf.impl.acc.DirectStoreMultiAccumulator)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 MeasurementStoreQuery (org.spf4j.perf.MeasurementStoreQuery)1 TimeSeriesRecord (org.spf4j.perf.TimeSeriesRecord)1 MeasurementsInfoImpl (org.spf4j.perf.impl.MeasurementsInfoImpl)1 ColumnDef (org.spf4j.tsdb2.avro.ColumnDef)1 TableDef (org.spf4j.tsdb2.avro.TableDef)1