2

I am using influxdb-client-java to write and query data from influxdb 2.x. Wanted to write parameterized queries to fetch a list of FluxTable as follows based on sample code from here

String bucket = config.getDatabase().getBucket();

Map<String, Object> params = new HashMap<>();
params.put("bucketParam", bucket);
params.put("startParam", "-30d");
params.put("measurement", MEASUREMENT_NAME);
params.put("auth_id", userId);

String parametrizedQuery = "from(bucket: params.bucketParam) |> range(start: duration(v: params.startParam)) |> filter(fn: (r) => r._measurement == params.measurement and r.AUTH_ID == params.auth_id)";
Query query = new Query();
query.setParams(params);
query.setQuery(parametrizedQuery);
List<FluxTable> queryResults = influxQueryExecutor.executeQuery(query);
public List<FluxTable> executeQuery(Query query) {
    QueryApi queryApi = influxDBClient.getQueryApi();
    return queryApi.query(query);
}

However, I'm getting the following exception

com.influxdb.exceptions.BadRequestException: error @1:121-1:127: undefined identifier params

error @1:157-1:163: undefined identifier params

error @1:62-1:68: undefined identifier params

error @1:14-1:20: undefined identifier params

Not sure what I'm doing wrong, originally wrote pretty much the same code as the sample code but decided to modify it to pass in a Query so that I can use the setParams method. Any help is appreciated thanks!

1 Answers1

2

According to the official documentation, only InfluxDB Cloud supports parameterized queries.

Gugu
  • 21
  • 1