use of org.spf4j.tsdb2.avro.TableDef in project spf4j by zolyfarkas.
the class TSDBQuery method getAllTables.
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public static ListMultimap<String, TableDef> getAllTables(final File tsdbFile) throws IOException {
ListMultimap<String, TableDef> result = ArrayListMultimap.create();
try (TSDBReader reader = new TSDBReader(tsdbFile, 8192)) {
Either<TableDef, DataBlock> read;
while ((read = reader.read()) != null) {
if (read.isLeft()) {
final TableDef tdef = read.getLeft();
result.put(tdef.getName(), tdef);
}
}
}
return result;
}
use of org.spf4j.tsdb2.avro.TableDef 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.TableDef in project spf4j by zolyfarkas.
the class TSDBQuery method getIds.
public static long[] getIds(final Collection<TableDef> tableDefs) {
long[] result = new long[tableDefs.size()];
int i = 0;
for (TableDef tdef : tableDefs) {
result[i++] = tdef.id;
}
return result;
}
use of org.spf4j.tsdb2.avro.TableDef in project spf4j by zolyfarkas.
the class TSDBQuery method getColumnNames.
public static String[] getColumnNames(final TableDef td) {
List<ColumnDef> columns = td.getColumns();
String[] result = new String[columns.size()];
int i = 0;
for (ColumnDef cd : columns) {
result[i++] = cd.getName();
}
return result;
}
use of org.spf4j.tsdb2.avro.TableDef in project spf4j by zolyfarkas.
the class TSDBQuery method writeAsCsv.
public static void writeAsCsv(final Appendable writer, final File tsDB, final String tableName) throws IOException {
List<TableDef> tableDefs = getTableDef(tsDB, tableName);
TimeSeries data = getTimeSeries(tsDB, getIds(tableDefs), 0, Long.MAX_VALUE);
Csv.writeCsvElement("timestamp", writer);
for (ColumnDef col : tableDefs.get(0).getColumns()) {
writer.append(',');
Csv.writeCsvElement(col.getName(), writer);
}
writer.append('\n');
long[] timestamps = data.getTimeStamps();
long[][] values = data.getValues();
for (int i = 0; i < timestamps.length; i++) {
Csv.writeCsvElement(DateTimeFormats.TS_FORMAT.format(Instant.ofEpochMilli(timestamps[i])), writer);
for (long val : values[i]) {
writer.append(',');
Csv.writeCsvElement(Long.toString(val), writer);
}
writer.append('\n');
}
}
Aggregations