Search in sources :

Example 11 with FluxRecord

use of com.influxdb.query.FluxRecord in project nifi-influxdb-bundle by influxdata.

the class ITPutInfluxDatabaseRecord_2 method storeComplexData.

@Test
public void storeComplexData() {
    runner.setProperty(InfluxDBUtils.TAGS, "lang,keyword");
    runner.setProperty(InfluxDBUtils.TIMESTAMP_FIELD, "timestamp");
    runner.setProperty(InfluxDBUtils.FIELDS, "retweet_count,tweet_id,followers_count,screen_name,friends_count,favourites_count,user_verified,raw");
    recordReader.addSchemaField("lang", RecordFieldType.STRING);
    recordReader.addSchemaField("keyword", RecordFieldType.STRING);
    recordReader.addSchemaField("retweet_count", RecordFieldType.INT);
    recordReader.addSchemaField("tweet_id", RecordFieldType.STRING);
    recordReader.addSchemaField("followers_count", RecordFieldType.INT);
    recordReader.addSchemaField("screen_name", RecordFieldType.STRING);
    recordReader.addSchemaField("friends_count", RecordFieldType.INT);
    recordReader.addSchemaField("favourites_count", RecordFieldType.INT);
    recordReader.addSchemaField("user_verified", RecordFieldType.BOOLEAN);
    recordReader.addSchemaField("raw", RecordFieldType.STRING);
    recordReader.addSchemaField("timestamp", RecordFieldType.LONG);
    Date timeValue = new Date();
    recordReader.addRecord("en", "crypto", 10, "123456789id", 15, "my name", 5, 20, false, "crypto rules!", timeValue);
    runner.enqueue("");
    runner.run();
    runner.assertAllFlowFilesTransferred(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("en", record.getValueByKey("lang"));
    Assert.assertEquals("crypto", record.getValueByKey("keyword"));
    Assert.assertEquals("123456789id", record.getValueByKey("tweet_id"));
    Assert.assertEquals(15L, record.getValueByKey("followers_count"));
    Assert.assertEquals("my name", record.getValueByKey("screen_name"));
    Assert.assertEquals(5L, record.getValueByKey("friends_count"));
    Assert.assertEquals(20L, record.getValueByKey("favourites_count"));
    Assert.assertEquals(false, record.getValueByKey("user_verified"));
    long millis = TimeUnit.MILLISECONDS.convert(timeValue.getTime(), TimeUnit.MILLISECONDS);
    Assert.assertEquals(Instant.ofEpochMilli(millis), record.getTime());
}
Also used : FluxTable(com.influxdb.query.FluxTable) Date(java.util.Date) FluxRecord(com.influxdb.query.FluxRecord) Test(org.junit.Test)

Example 12 with FluxRecord

use of com.influxdb.query.FluxRecord in project nifi-influxdb-bundle by influxdata.

the class TestGetInfluxDatabaseRecord_2 method useMoreFlowFiles.

@Test
public void useMoreFlowFiles() {
    FluxRecord fluxRecord1 = new FluxRecord(0);
    fluxRecord1.getValues().put("value", 1L);
    FluxRecord fluxRecord2 = new FluxRecord(0);
    fluxRecord2.getValues().put("value", 2L);
    FluxRecord fluxRecord3 = new FluxRecord(0);
    fluxRecord3.getValues().put("value", 3L);
    FluxRecord fluxRecord4 = new FluxRecord(0);
    fluxRecord4.getValues().put("value", 4L);
    FluxRecord fluxRecord5 = new FluxRecord(0);
    fluxRecord5.getValues().put("value", 5L);
    FluxRecord fluxRecord6 = new FluxRecord(0);
    fluxRecord6.getValues().put("value", 6L);
    queryOnResponseRecords.add(fluxRecord1);
    queryOnResponseRecords.add(fluxRecord2);
    queryOnResponseRecords.add(fluxRecord3);
    queryOnResponseRecords.add(fluxRecord4);
    queryOnResponseRecords.add(fluxRecord5);
    queryOnResponseRecords.add(fluxRecord6);
    runner.setProperty(GetInfluxDatabase_2.RECORDS_PER_FLOWFILE, "2");
    runner.enqueue("");
    runner.run();
    runner.assertAllFlowFilesTransferred(REL_SUCCESS, 4);
    Assert.assertEquals(6, writer.getRecordsWritten().size());
    for (int i = 0; i < 6; i++) {
        Record nifiRecord = writer.getRecordsWritten().get(i);
        RecordSchema schema = nifiRecord.getSchema();
        Assert.assertEquals(RecordFieldType.LONG, schema.getField("value").get().getDataType().getFieldType());
        Assert.assertEquals((long) i + 1, nifiRecord.getValue("value"));
    }
}
Also used : FluxRecord(com.influxdb.query.FluxRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) Record(org.apache.nifi.serialization.record.Record) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) FluxRecord(com.influxdb.query.FluxRecord) Test(org.junit.Test)

Aggregations

FluxRecord (com.influxdb.query.FluxRecord)12 Test (org.junit.Test)6 FluxTable (com.influxdb.query.FluxTable)5 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)5 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)4 Record (org.apache.nifi.serialization.record.Record)4 Cancellable (com.influxdb.Cancellable)2 Row (cn.edu.tsinghua.iginx.engine.shared.data.read.Row)1 DataType (cn.edu.tsinghua.iginx.thrift.DataType)1 Status (cn.edu.tsinghua.iotdb.benchmark.measurement.Status)1 TsdbException (cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException)1 InfluxDBClient (com.influxdb.client.InfluxDBClient)1 QueryApi (com.influxdb.client.QueryApi)1 Query (com.influxdb.client.domain.Query)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 InitializationException (org.apache.nifi.reporting.InitializationException)1 ArrayListRecordWriter (org.apache.nifi.serialization.record.ArrayListRecordWriter)1