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;
}
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);
}
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()][]));
}
Aggregations