Search in sources :

Example 6 with ColumnDef

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

the class TSDBQuery method writeCsvTables.

public static void writeCsvTables(final File tsDB, final Set<String> tableNames, final File output) throws IOException {
    if (tableNames.isEmpty()) {
        return;
    }
    ListMultimap<String, TableDef> tables = getTables(tsDB, tableNames);
    try (Writer writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(output.toPath()), Charsets.UTF_8))) {
        TableDef table = tables.values().iterator().next();
        Csv.writeCsvElement("table", writer);
        writer.append(',');
        Csv.writeCsvElement("timestamp", writer);
        for (ColumnDef col : table.getColumns()) {
            writer.append(',');
            Csv.writeCsvElement(col.getName(), writer);
        }
        writer.write('\n');
        for (Map.Entry<String, Collection<TableDef>> tEntry : tables.asMap().entrySet()) {
            TimeSeries data = getTimeSeries(tsDB, getIds(tEntry.getValue()), 0, Long.MAX_VALUE);
            long[] timestamps = data.getTimeStamps();
            long[][] values = data.getValues();
            for (int i = 0; i < timestamps.length; i++) {
                Csv.writeCsvElement(tEntry.getKey(), writer);
                writer.append(',');
                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.write('\n');
            }
        }
    }
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef) TableDef(org.spf4j.tsdb2.avro.TableDef) BufferedWriter(java.io.BufferedWriter) Collection(java.util.Collection) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TLongObjectMap(gnu.trove.map.TLongObjectMap) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer)

Example 7 with ColumnDef

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

the class TSDBQuery method getColumnUnitsOfMeasurement.

public static String[] getColumnUnitsOfMeasurement(final TableDef td) {
    List<ColumnDef> columns = td.getColumns();
    String[] result = new String[columns.size()];
    int i = 0;
    for (ColumnDef cd : columns) {
        result[i++] = cd.getUnitOfMeasurement();
    }
    return result;
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef)

Aggregations

ColumnDef (org.spf4j.tsdb2.avro.ColumnDef)7 TableDef (org.spf4j.tsdb2.avro.TableDef)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TLongObjectMap (gnu.trove.map.TLongObjectMap)1 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 JFreeChart (org.jfree.chart.JFreeChart)1 Pair (org.spf4j.base.Pair)1