use of com.influxdb.query.FluxRecord in project iotdb-benchmark by thulab.
the class InfluxDB method executeQueryAndGetStatus.
private Status executeQueryAndGetStatus(String sql) {
if (!config.isIS_QUIET_MODE()) {
LOGGER.debug("{} query SQL: {}", Thread.currentThread().getName(), sql);
}
int cnt = 0;
List<FluxTable> tables = new ArrayList<>();
try {
tables = client.getQueryApi().query(sql);
} catch (Exception e) {
LOGGER.error("Error when query {} : {}", sql, e.getMessage());
}
for (FluxTable table : tables) {
List<FluxRecord> fluxRecords = table.getRecords();
cnt += fluxRecords.size();
}
return new Status(true, cnt);
}
use of com.influxdb.query.FluxRecord 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());
}
use of com.influxdb.query.FluxRecord in project nifi-influxdb-bundle by influxdata.
the class TestGetInfluxDatabaseRecord_2 method success.
@Test
public void success() {
FluxRecord fluxRecord = new FluxRecord(0);
fluxRecord.getValues().put("bool_value", true);
fluxRecord.getValues().put("long_value", 123456789123456789L);
fluxRecord.getValues().put("double_value", 123456789.123456789D);
fluxRecord.getValues().put("base64Binary_value", "binary".getBytes());
fluxRecord.getValues().put("instant_value", Instant.ofEpochSecond(123456789));
fluxRecord.getValues().put("duration_value", Duration.ofNanos(10_000L));
fluxRecord.getValues().put("string_value", "InfluxDB rocks!");
fluxRecord.getValues().put("null_value", null);
queryOnResponseRecords.add(fluxRecord);
runner.enqueue("");
runner.run();
runner.assertAllFlowFilesTransferred(REL_SUCCESS, 1);
Assert.assertEquals(1, writer.getRecordsWritten().size());
Record nifiRecord = writer.getRecordsWritten().get(0);
RecordSchema schema = nifiRecord.getSchema();
Assert.assertEquals(7, schema.getFieldCount());
Assert.assertEquals(RecordFieldType.BOOLEAN, schema.getField("bool_value").get().getDataType().getFieldType());
Assert.assertEquals(RecordFieldType.LONG, schema.getField("long_value").get().getDataType().getFieldType());
Assert.assertEquals(RecordFieldType.DOUBLE, schema.getField("double_value").get().getDataType().getFieldType());
Assert.assertEquals(RecordFieldType.ARRAY, schema.getField("base64Binary_value").get().getDataType().getFieldType());
Assert.assertEquals(RecordFieldType.BYTE, ((ArrayDataType) schema.getField("base64Binary_value").get().getDataType()).getElementType().getFieldType());
Assert.assertEquals(RecordFieldType.TIMESTAMP, schema.getField("instant_value").get().getDataType().getFieldType());
Assert.assertEquals(RecordFieldType.LONG, schema.getField("duration_value").get().getDataType().getFieldType());
Assert.assertEquals(RecordFieldType.STRING, schema.getField("string_value").get().getDataType().getFieldType());
Assert.assertEquals(true, nifiRecord.getValue("bool_value"));
Assert.assertEquals(123456789123456789L, nifiRecord.getValue("long_value"));
Assert.assertEquals(123456789.123456789D, nifiRecord.getValue("double_value"));
Assert.assertArrayEquals("binary".getBytes(), (byte[]) nifiRecord.getValue("base64Binary_value"));
Assert.assertEquals(Date.from(Instant.ofEpochSecond(123456789)), nifiRecord.getValue("instant_value"));
Assert.assertEquals(10000L, nifiRecord.getValue("duration_value"));
Assert.assertEquals("InfluxDB rocks!", nifiRecord.getValue("string_value"));
}
use of com.influxdb.query.FluxRecord in project nifi-influxdb-bundle by influxdata.
the class TestGetInfluxDatabaseRecord_2 method moreRecords.
@Test
public void moreRecords() {
FluxRecord fluxRecord1 = new FluxRecord(0);
fluxRecord1.getValues().put("value", 1L);
FluxRecord fluxRecord2 = new FluxRecord(0);
fluxRecord2.getValues().put("value", "2");
queryOnResponseRecords.add(fluxRecord1);
queryOnResponseRecords.add(fluxRecord2);
runner.enqueue("");
runner.run();
runner.assertAllFlowFilesTransferred(REL_SUCCESS, 1);
Assert.assertEquals(2, writer.getRecordsWritten().size());
// Record 1
Record nifiRecord = writer.getRecordsWritten().get(0);
RecordSchema schema = nifiRecord.getSchema();
Assert.assertEquals(1, schema.getFieldCount());
Assert.assertEquals(RecordFieldType.LONG, schema.getField("value").get().getDataType().getFieldType());
Assert.assertEquals(1L, nifiRecord.getValue("value"));
// Record 2
nifiRecord = writer.getRecordsWritten().get(1);
schema = nifiRecord.getSchema();
Assert.assertEquals(1, schema.getFieldCount());
Assert.assertEquals(RecordFieldType.STRING, schema.getField("value").get().getDataType().getFieldType());
Assert.assertEquals("2", nifiRecord.getValue("value"));
}
use of com.influxdb.query.FluxRecord in project nifi-influxdb-bundle by influxdata.
the class TestGetInfluxDatabaseRecord_2 method moreTables.
@Test
public void moreTables() {
FluxRecord fluxRecord1 = new FluxRecord(0);
fluxRecord1.getValues().put("value", 1L);
FluxRecord fluxRecord2 = new FluxRecord(1);
fluxRecord2.getValues().put("value", "2");
queryOnResponseRecords.add(fluxRecord1);
queryOnResponseRecords.add(fluxRecord2);
runner.enqueue("");
runner.run();
runner.assertAllFlowFilesTransferred(REL_SUCCESS, 1);
Assert.assertEquals(2, writer.getRecordsWritten().size());
// Record 1
Record nifiRecord = writer.getRecordsWritten().get(0);
RecordSchema schema = nifiRecord.getSchema();
Assert.assertEquals(1, schema.getFieldCount());
Assert.assertEquals(RecordFieldType.LONG, schema.getField("value").get().getDataType().getFieldType());
Assert.assertEquals(1L, nifiRecord.getValue("value"));
// Record 2
nifiRecord = writer.getRecordsWritten().get(1);
schema = nifiRecord.getSchema();
Assert.assertEquals(1, schema.getFieldCount());
Assert.assertEquals(RecordFieldType.STRING, schema.getField("value").get().getDataType().getFieldType());
Assert.assertEquals("2", nifiRecord.getValue("value"));
}
Aggregations