Search in sources :

Example 1 with DataRow

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

the class TSDBQuery method getAllTablesWithDataRanges.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public static ListMultimap<String, TableDefEx> getAllTablesWithDataRanges(final File tsdbFile) throws IOException {
    ListMultimap<String, TableDefEx> result = ArrayListMultimap.create();
    TLongObjectMap<TableDefEx> id2Def = new TLongObjectHashMap<>();
    try (TSDBReader reader = new TSDBReader(tsdbFile, 8192)) {
        Either<TableDef, DataBlock> read;
        while ((read = reader.read()) != null) {
            if (read.isLeft()) {
                final TableDef left = read.getLeft();
                final TableDefEx tableDefEx = new TableDefEx(left, Long.MAX_VALUE, 0L);
                id2Def.put(left.id, tableDefEx);
                result.put(tableDefEx.getTableDef().getName(), tableDefEx);
            } else {
                DataBlock right = read.getRight();
                long baseTs = right.baseTimestamp;
                for (DataRow row : right.getValues()) {
                    TableDefEx tdex = id2Def.get(row.tableDefId);
                    if (tdex == null) {
                        throw new IOException("Potentially corupted file data row with no tableDef " + row);
                    }
                    long ts = baseTs + row.relTimeStamp;
                    if (ts < tdex.getStartTime()) {
                        tdex.setStartTime(ts);
                    }
                    if (ts > tdex.getEndTime()) {
                        tdex.setEndTime(ts);
                    }
                }
            }
        }
    }
    return result;
}
Also used : TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) IOException(java.io.IOException) TableDef(org.spf4j.tsdb2.avro.TableDef) DataRow(org.spf4j.tsdb2.avro.DataRow) DataBlock(org.spf4j.tsdb2.avro.DataBlock) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with DataRow

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

the class TSDBWriter method writeDataRow.

public synchronized void writeDataRow(final long tableId, final long timestamp, final long... data) throws IOException {
    if (this.writeBlock.values.size() >= this.maxRowsPerBlock) {
        flush();
    }
    long baseTs = writeBlock.baseTimestamp;
    DataRow row = new DataRow();
    row.relTimeStamp = (int) (timestamp - baseTs);
    row.tableDefId = tableId;
    row.setData(Longs.asList(data));
    this.writeBlock.values.add(row);
}
Also used : DataRow(org.spf4j.tsdb2.avro.DataRow)

Example 3 with DataRow

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

the class TSDBQuery method getTimeSeries.

public static TimeSeries getTimeSeries(final File tsdbFile, final long[] tableIds, final long startTimeMillis, final long endTimeMillis) throws IOException {
    TLongList timestamps = new TLongArrayList();
    List<long[]> metrics = new ArrayList<>();
    try (TSDBReader reader = new TSDBReader(tsdbFile, 8192)) {
        Either<TableDef, DataBlock> read;
        while ((read = reader.read()) != null) {
            if (read.isRight()) {
                DataBlock data = read.getRight();
                long baseTs = data.baseTimestamp;
                for (DataRow row : data.getValues()) {
                    for (long tableId : tableIds) {
                        if (tableId == row.tableDefId) {
                            final long ts = baseTs + row.relTimeStamp;
                            if (ts >= startTimeMillis && ts <= endTimeMillis) {
                                timestamps.add(ts);
                                metrics.add(Longs.toArray(row.data));
                            }
                        }
                    }
                }
            }
        }
    }
    return new TimeSeries(timestamps.toArray(), metrics.toArray(new long[metrics.size()][]));
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongList(gnu.trove.list.TLongList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) TableDef(org.spf4j.tsdb2.avro.TableDef) DataRow(org.spf4j.tsdb2.avro.DataRow) DataBlock(org.spf4j.tsdb2.avro.DataBlock)

Aggregations

DataRow (org.spf4j.tsdb2.avro.DataRow)3 DataBlock (org.spf4j.tsdb2.avro.DataBlock)2 TableDef (org.spf4j.tsdb2.avro.TableDef)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 TLongList (gnu.trove.list.TLongList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1