Search in sources :

Example 1 with TableDef

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;
}
Also used : TableDef(org.spf4j.tsdb2.avro.TableDef) DataBlock(org.spf4j.tsdb2.avro.DataBlock) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with TableDef

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;
}
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 3 with TableDef

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;
}
Also used : TableDef(org.spf4j.tsdb2.avro.TableDef)

Example 4 with TableDef

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;
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef)

Example 5 with TableDef

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');
    }
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef) TableDef(org.spf4j.tsdb2.avro.TableDef)

Aggregations

TableDef (org.spf4j.tsdb2.avro.TableDef)14 ColumnDef (org.spf4j.tsdb2.avro.ColumnDef)7 DataBlock (org.spf4j.tsdb2.avro.DataBlock)6 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)5 File (java.io.File)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 IOException (java.io.IOException)2 Map (java.util.Map)2 JFreeChart (org.jfree.chart.JFreeChart)2 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)2 TSDBWriter (org.spf4j.tsdb2.TSDBWriter)2 DataRow (org.spf4j.tsdb2.avro.DataRow)2 TLongList (gnu.trove.list.TLongList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TLongObjectMap (gnu.trove.map.TLongObjectMap)1 Dimension (java.awt.Dimension)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1