Search in sources :

Example 21 with Reader

use of com.srotya.sidewinder.core.storage.compression.Reader in project sidewinder by srotya.

the class TimeSeries method getReader.

/**
 * Get {@link Reader} with time and value filter predicates pushed-down to it.
 *
 * @param timePredicate
 * @param valuePredicate
 * @return point in time instance of reader
 * @throws IOException
 */
public static Reader getReader(Writer writer, Predicate timePredicate, Predicate valuePredicate) throws IOException {
    Reader reader = writer.getReader();
    reader.setTimePredicate(timePredicate);
    reader.setValuePredicate(valuePredicate);
    return reader;
}
Also used : Reader(com.srotya.sidewinder.core.storage.compression.Reader)

Example 22 with Reader

use of com.srotya.sidewinder.core.storage.compression.Reader in project sidewinder by srotya.

the class TimeSeries method queryDataPoints.

/**
 * Extract {@link DataPoint}s for the supplied time range and value predicate.
 *
 * Each {@link DataPoint} has the appendFieldValue and appendTags set in it.
 *
 * @param appendFieldValueName
 *            fieldname to append to each datapoint
 * @param startTime
 *            time range beginning
 * @param endTime
 *            time range end
 * @param valuePredicate
 *            pushed down filter for values
 * @return list of datapoints
 * @throws IOException
 */
public List<DataPoint> queryDataPoints(String appendFieldValueName, long startTime, long endTime, Predicate valuePredicate) throws IOException {
    if (startTime > endTime) {
        // swap start and end times if they are off
        startTime = startTime ^ endTime;
        endTime = endTime ^ startTime;
        startTime = startTime ^ endTime;
    }
    BetweenPredicate timeRangePredicate = new BetweenPredicate(startTime, endTime);
    logger.fine(getSeriesId() + " " + bucketMap.size() + " " + bucketCount + " " + startTime + "  " + endTime + " " + valuePredicate + " " + timeRangePredicate + " diff:" + (endTime - startTime));
    SortedMap<String, List<Writer>> series = correctTimeRangeScan(startTime, endTime);
    List<Reader> readers = new ArrayList<>();
    for (List<Writer> writers : series.values()) {
        for (Writer writer : writers) {
            readers.add(getReader(writer, timeRangePredicate, valuePredicate));
        }
    }
    List<DataPoint> points = new ArrayList<>();
    for (Reader reader : readers) {
        readerToDataPoints(points, reader);
    }
    return points;
}
Also used : BetweenPredicate(com.srotya.sidewinder.core.predicates.BetweenPredicate) ArrayList(java.util.ArrayList) Reader(com.srotya.sidewinder.core.storage.compression.Reader) ArrayList(java.util.ArrayList) List(java.util.List) Writer(com.srotya.sidewinder.core.storage.compression.Writer)

Example 23 with Reader

use of com.srotya.sidewinder.core.storage.compression.Reader in project sidewinder by srotya.

the class TimeSeries method seriesToDataPoints.

/**
 * Converts timeseries to a list of datapoints appended to the supplied list
 * object. Datapoints are filtered by the supplied predicates before they are
 * returned. These predicates are pushed down to the reader for efficiency and
 * performance as it prevents unnecessary object creation.
 *
 * @param appendFieldValueName
 * @param appendTags
 *
 * @param points
 *            list data points are appended to
 * @param writer
 *            to extract the data points from
 * @param timePredicate
 *            time range filter
 * @param valuePredicate
 *            value filter
 * @return the points argument
 * @throws IOException
 */
public static List<DataPoint> seriesToDataPoints(String appendFieldValueName, List<String> appendTags, List<DataPoint> points, Writer writer, Predicate timePredicate, Predicate valuePredicate, boolean isFp) throws IOException {
    Reader reader = getReader(writer, timePredicate, valuePredicate);
    DataPoint point = null;
    while (true) {
        try {
            point = reader.readPair();
            if (point != null) {
                points.add(point);
            }
        } catch (IOException e) {
            if (e instanceof RejectException) {
            } else {
                e.printStackTrace();
            }
            break;
        }
    }
    return points;
}
Also used : Reader(com.srotya.sidewinder.core.storage.compression.Reader) IOException(java.io.IOException)

Example 24 with Reader

use of com.srotya.sidewinder.core.storage.compression.Reader in project sidewinder by srotya.

the class Measurement method queryReadersWithMap.

public default void queryReadersWithMap(String valueFieldName, long startTime, long endTime, LinkedHashMap<Reader, List<Tag>> readers) throws IOException {
    for (String entry : getSeriesKeys()) {
        SeriesFieldMap m = getSeriesFromKey(entry);
        TimeSeries series = m.get(valueFieldName);
        if (series == null) {
            continue;
        }
        List<Tag> seriesTags = decodeStringToTags(getTagIndex(), entry);
        for (Reader reader : series.queryReader(valueFieldName, seriesTags, startTime, endTime, null)) {
            readers.put(reader, seriesTags);
        }
    }
}
Also used : Reader(com.srotya.sidewinder.core.storage.compression.Reader) Tag(com.srotya.sidewinder.core.filters.Tag)

Example 25 with Reader

use of com.srotya.sidewinder.core.storage.compression.Reader in project sidewinder by srotya.

the class Measurement method queryReaders.

public default void queryReaders(String valueFieldName, long startTime, long endTime, LinkedHashMap<Reader, Boolean> readers) throws IOException {
    for (String entry : getSeriesKeys()) {
        SeriesFieldMap m = getSeriesFromKey(entry);
        TimeSeries series = m.get(valueFieldName);
        if (series == null) {
            continue;
        }
        List<Tag> seriesTags = decodeStringToTags(getTagIndex(), entry);
        for (Reader reader : series.queryReader(valueFieldName, seriesTags, startTime, endTime, null)) {
            readers.put(reader, series.isFp());
        }
    }
}
Also used : Reader(com.srotya.sidewinder.core.storage.compression.Reader) Tag(com.srotya.sidewinder.core.filters.Tag)

Aggregations

Reader (com.srotya.sidewinder.core.storage.compression.Reader)25 Test (org.junit.Test)17 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)14 ByteBuffer (java.nio.ByteBuffer)12 Writer (com.srotya.sidewinder.core.storage.compression.Writer)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)8 RejectException (com.srotya.sidewinder.core.storage.RejectException)6 HashMap (java.util.HashMap)6 List (java.util.List)6 RollOverException (com.srotya.sidewinder.core.storage.compression.RollOverException)5 BetweenPredicate (com.srotya.sidewinder.core.predicates.BetweenPredicate)4 Tag (com.srotya.sidewinder.core.filters.Tag)3 Point (com.srotya.sidewinder.core.rpc.Point)2 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)2 File (java.io.File)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GreaterThanEqualsPredicate (com.srotya.sidewinder.core.predicates.GreaterThanEqualsPredicate)1