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());
}
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"));
}
}
Aggregations