Search in sources :

Example 1 with InfluxLineProtocolReader

use of org.influxdata.nifi.serialization.InfluxLineProtocolReader in project nifi-influxdb-bundle by influxdata.

the class ITPutInfluxDatabaseRecord_2 method saveInfluxLineProtocol.

@Test
public void saveInfluxLineProtocol() throws InitializationException {
    String data = "weather,location=us-midwest temperature=82 1465839830100400200";
    InfluxLineProtocolReader readerFactory = new InfluxLineProtocolReader();
    runner.addControllerService("inline-reader", readerFactory);
    runner.setProperty(readerFactory, InfluxLineProtocolReader.CHARSET, StandardCharsets.UTF_8.name());
    runner.enableControllerService(readerFactory);
    runner.setProperty(PutInfluxDatabaseRecord.RECORD_READER_FACTORY, "inline-reader");
    runner.setProperty(InfluxDBUtils.TAGS, "tags");
    runner.setProperty(InfluxDBUtils.FIELDS, "fields");
    runner.setProperty(InfluxDBUtils.TIMESTAMP_FIELD, "timestamp");
    runner.enqueue(data);
    runner.run();
    runner.assertTransferCount(AbstractInfluxDatabaseProcessor.REL_SUCCESS, 1);
    List<FluxTable> tables = queryApi.query("from(bucket:\"" + bucketName + "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")");
    Assert.assertEquals(1, tables.size());
    Assert.assertEquals(1, tables.get(0).getRecords().size());
    FluxRecord record = tables.get(0).getRecords().get(0);
    Assert.assertEquals("testRecordMeasurement", record.getMeasurement());
    Assert.assertEquals("us-midwest", record.getValueByKey("location"));
    Assert.assertEquals(82D, record.getValueByKey("temperature"));
    Assert.assertEquals(Instant.ofEpochSecond(0, 1465839830100400200L), record.getTime());
}
Also used : InfluxLineProtocolReader(org.influxdata.nifi.serialization.InfluxLineProtocolReader) FluxTable(com.influxdb.query.FluxTable) FluxRecord(com.influxdb.query.FluxRecord) Test(org.junit.Test)

Example 2 with InfluxLineProtocolReader

use of org.influxdata.nifi.serialization.InfluxLineProtocolReader in project nifi-influxdb-bundle by influxdata.

the class ITPutInfluxDatabaseRecord method saveInfluxLineProtocol.

@Test
public void saveInfluxLineProtocol() throws InitializationException {
    String data = "weather,location=us-midwest temperature=82 1465839830100400200";
    InfluxLineProtocolReader readerFactory = new InfluxLineProtocolReader();
    runner.addControllerService("inline-reader", readerFactory);
    runner.setProperty(readerFactory, InfluxLineProtocolReader.CHARSET, StandardCharsets.UTF_8.name());
    runner.enableControllerService(readerFactory);
    runner.setProperty(PutInfluxDatabaseRecord.RECORD_READER_FACTORY, "inline-reader");
    runner.setProperty(InfluxDBUtils.TAGS, "tags");
    runner.setProperty(InfluxDBUtils.FIELDS, "fields");
    runner.setProperty(InfluxDBUtils.TIMESTAMP_FIELD, "timestamp");
    runner.enqueue(data);
    runner.run();
    runner.assertTransferCount(PutInfluxDatabaseRecord.REL_SUCCESS, 1);
    List<QueryResult.Result> results = runQuery("select * from testRecordMeasurement GROUP BY *").getResults();
    QueryResult.Series series = results.get(0).getSeries().get(0);
    Assert.assertEquals("testRecordMeasurement", series.getName());
    Assert.assertEquals(1, series.getTags().size());
    Assert.assertEquals("us-midwest", series.getTags().get("location"));
    Assert.assertEquals(2, series.getColumns().size());
    Assert.assertEquals(1, series.getValues().size());
    List<Object> values = series.getValues().get(0);
    assertThat(values.get(series.getColumns().indexOf("temperature")), new ComparableMatcher(82D));
    double time = (double) values.get(series.getColumns().indexOf("time"));
    assertThat(time, new ComparableMatcher(1465839830100400200D));
}
Also used : InfluxLineProtocolReader(org.influxdata.nifi.serialization.InfluxLineProtocolReader) QueryResult(org.influxdb.dto.QueryResult) JsonObject(com.google.gson.JsonObject) QueryResult(org.influxdb.dto.QueryResult) Test(org.junit.Test)

Aggregations

InfluxLineProtocolReader (org.influxdata.nifi.serialization.InfluxLineProtocolReader)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 FluxRecord (com.influxdb.query.FluxRecord)1 FluxTable (com.influxdb.query.FluxTable)1 QueryResult (org.influxdb.dto.QueryResult)1