Search in sources :

Example 1 with Dialect

use of com.influxdb.client.domain.Dialect in project nifi-influxdb-bundle by influxdata.

the class TestGetInfluxDatabase_2 method queryValueWithCustomDialect.

@Test
public void queryValueWithCustomDialect() {
    runner.setProperty(GetInfluxDatabase_2.DIALECT_HEADER, "true");
    runner.setProperty(GetInfluxDatabase_2.DIALECT_DELIMITER, "|");
    runner.setProperty(GetInfluxDatabase_2.DIALECT_COMMENT_PREFIX, "§");
    runner.setProperty(GetInfluxDatabase_2.DIALECT_ANNOTATIONS, "datatype, group");
    runner.setProperty(GetInfluxDatabase_2.DIALECT_DATE_TIME_FORMAT, "RFC3339Nano");
    runner.enqueue("");
    runner.run();
    Query query = new Query().query("from(bucket:\"my-bucket\") |> range(start: 0) |> last()").dialect(new Dialect().header(true).delimiter("|").commentPrefix("§").addAnnotationsItem(Dialect.AnnotationsEnum.DATATYPE).addAnnotationsItem(Dialect.AnnotationsEnum.GROUP).dateTimeFormat(Dialect.DateTimeFormatEnum.RFC3339NANO));
    Mockito.verify(mockQueryApi, Mockito.only()).queryRaw(Mockito.eq(query), Mockito.eq("my-org"), Mockito.any(), Mockito.any(), Mockito.any());
}
Also used : Query(com.influxdb.client.domain.Query) Dialect(com.influxdb.client.domain.Dialect) Test(org.junit.Test)

Example 2 with Dialect

use of com.influxdb.client.domain.Dialect in project nifi-influxdb-bundle by influxdata.

the class AbstractGetInfluxDatabase_2 method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    boolean createdFlowFile = false;
    FlowFile flowFile = session.get();
    // If there aren't incoming connections.
    if (flowFile == null) {
        flowFile = session.create();
        createdFlowFile = true;
    }
    String org = context.getProperty(ORG).evaluateAttributeExpressions(flowFile).getValue();
    String flux = context.getProperty(QUERY).evaluateAttributeExpressions(flowFile).getValue();
    Dialect dialect = prepareDialect(context);
    // 
    // Records per Flowfile
    // 
    long recordsPerFlowFile = -1;
    if (context.getProperty(RECORDS_PER_FLOWFILE).isSet()) {
        recordsPerFlowFile = context.getProperty(RECORDS_PER_FLOWFILE).evaluateAttributeExpressions().asLong();
    }
    Query query = new Query().query(flux).dialect(dialect);
    try {
        QueryProcessor processor = new QueryProcessor(org, query, recordsPerFlowFile, flowFile, createdFlowFile, context, session);
        // CVS or Record based response?
        if (getSupportedPropertyDescriptors().contains(WRITER_FACTORY)) {
            processor.doQuery();
        } else {
            processor.doQueryRaw();
        }
    } catch (Exception e) {
        catchException(query, e, Collections.singletonList(flowFile), context, session);
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) Query(com.influxdb.client.domain.Query) Dialect(com.influxdb.client.domain.Dialect) InfluxException(com.influxdb.exceptions.InfluxException) ProcessException(org.apache.nifi.processor.exception.ProcessException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 3 with Dialect

use of com.influxdb.client.domain.Dialect in project nifi-influxdb-bundle by influxdata.

the class GetInfluxDatabase_2 method prepareDialect.

@Override
protected Dialect prepareDialect(final ProcessContext context) {
    boolean dialectHeader = context.getProperty(DIALECT_HEADER).asBoolean();
    String dialectDelimiter = context.getProperty(DIALECT_DELIMITER).getValue();
    String dialectCommentPrefix = context.getProperty(DIALECT_COMMENT_PREFIX).getValue();
    Dialect.DateTimeFormatEnum dialectTimeFormat = Dialect.DateTimeFormatEnum.fromValue(context.getProperty(DIALECT_DATE_TIME_FORMAT).getValue());
    List<Dialect.AnnotationsEnum> dialectAnnotations = new ArrayList<>();
    String dialectAnnotationsValue = context.getProperty(DIALECT_ANNOTATIONS).getValue();
    if (dialectAnnotationsValue != null && !dialectAnnotationsValue.isEmpty()) {
        Arrays.stream(dialectAnnotationsValue.split(",")).filter(annotation -> annotation != null && !annotation.trim().isEmpty()).map(String::trim).forEach(annotation -> dialectAnnotations.add(Dialect.AnnotationsEnum.fromValue(annotation.trim())));
    }
    return new Dialect().header(dialectHeader).delimiter(dialectDelimiter).commentPrefix(dialectCommentPrefix).dateTimeFormat(dialectTimeFormat).annotations(dialectAnnotations);
}
Also used : Dialect(com.influxdb.client.domain.Dialect) ArrayList(java.util.ArrayList)

Example 4 with Dialect

use of com.influxdb.client.domain.Dialect in project nifi-influxdb-bundle by influxdata.

the class TestGetInfluxDatabase_2 method queryValue.

@Test
public void queryValue() {
    runner.enqueue("");
    runner.run();
    Query query = new Query().query("from(bucket:\"my-bucket\") |> range(start: 0) |> last()").dialect(new Dialect().header(false).delimiter(",").commentPrefix("#").dateTimeFormat(Dialect.DateTimeFormatEnum.RFC3339));
    Mockito.verify(mockQueryApi, Mockito.only()).queryRaw(Mockito.eq(query), Mockito.eq("my-org"), Mockito.any(), Mockito.any(), Mockito.any());
}
Also used : Query(com.influxdb.client.domain.Query) Dialect(com.influxdb.client.domain.Dialect) Test(org.junit.Test)

Aggregations

Dialect (com.influxdb.client.domain.Dialect)4 Query (com.influxdb.client.domain.Query)3 Test (org.junit.Test)2 InfluxException (com.influxdb.exceptions.InfluxException)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1