Search in sources :

Example 1 with FluxRecord

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);
}
Also used : Status(cn.edu.tsinghua.iotdb.benchmark.measurement.Status) FluxTable(com.influxdb.query.FluxTable) ArrayList(java.util.ArrayList) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException) FluxRecord(com.influxdb.query.FluxRecord)

Example 2 with FluxRecord

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());
}
Also used : InfluxLineProtocolReader(org.influxdata.nifi.serialization.InfluxLineProtocolReader) FluxTable(com.influxdb.query.FluxTable) FluxRecord(com.influxdb.query.FluxRecord) Test(org.junit.Test)

Example 3 with FluxRecord

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"));
}
Also used : FluxRecord(com.influxdb.query.FluxRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) Record(org.apache.nifi.serialization.record.Record) ArrayDataType(org.apache.nifi.serialization.record.type.ArrayDataType) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) FluxRecord(com.influxdb.query.FluxRecord) Test(org.junit.Test)

Example 4 with FluxRecord

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

Example 5 with FluxRecord

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