Conversation
Codecov Report
@@ Coverage Diff @@
## master #286 +/- ##
============================================
- Coverage 89.71% 88.85% -0.86%
Complexity 473 473
============================================
Files 149 149
Lines 5913 5987 +74
Branches 283 289 +6
============================================
+ Hits 5305 5320 +15
- Misses 524 581 +57
- Partials 84 86 +2
Continue to review full report at Codecov.
|
bednar
left a comment
There was a problem hiding this comment.
Thanks for your PR 👍. There are a few requirements that must be be satisfy before we accept the PR:
- Add note to the following APIs how to use query parameters in
Queryobject:com.influxdb.client.scala.QueryScalaApicom.influxdb.client.kotlin.QueryKotlinApi
- Add possibility to use
Queryobject incom.influxdb.client.reactive.QueryReactiveApi
and also:
| package example; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.Period; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import com.influxdb.client.InfluxDBClient; | ||
| import com.influxdb.client.InfluxDBClientFactory; | ||
| import com.influxdb.client.QueryApi; | ||
| import com.influxdb.client.WriteApi; | ||
| import com.influxdb.client.domain.WritePrecision; | ||
| import com.influxdb.client.write.Point; | ||
| import com.influxdb.query.FluxTable; | ||
|
|
||
| public class ParameterizedQuery { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| String url = System.getenv("INFLUX_URL"); | ||
| String token = System.getenv("INFLUX_TOKEN"); | ||
| String org = System.getenv("INFLUX_ORG"); | ||
| String bucket = System.getenv("INFLUX_BUCKET"); | ||
|
|
||
| InfluxDBClient client = InfluxDBClientFactory.create(url, | ||
| token.toCharArray(), | ||
| org, bucket); | ||
|
|
||
| WriteApi writeApi = client.makeWriteApi(); | ||
|
|
||
| Instant yesterday = Instant.now().minus(Period.ofDays(1)); | ||
|
|
||
| Point p = Point.measurement("temperature") | ||
| .addTag("location", "north") | ||
| .addField("value", 60.0) | ||
| .time(yesterday, WritePrecision.NS); | ||
|
|
||
| writeApi.writePoint(p); | ||
|
|
||
| writeApi.close(); | ||
|
|
||
| // | ||
| // Query range start parameter using Instant | ||
| // | ||
| QueryApi queryApi = client.getQueryApi(); | ||
| Map<String, Object> params = new HashMap<>(); | ||
| params.put("bucketParam", bucket); | ||
| params.put("startParam", yesterday.toString()); | ||
|
|
||
| String parametrizedQuery = "from(bucket: params.bucketParam) |> range(start: time(v: params.startParam))"; | ||
| List<FluxTable> query = queryApi.query(parametrizedQuery, org, params); | ||
| query.forEach(fluxTable -> fluxTable.getRecords() | ||
| .forEach(r -> System.out.println(r.getTime() + ": " + r.getValueByKey("_value")))); | ||
|
|
||
| // | ||
| // Query range start parameter using duration | ||
| // | ||
| params = new HashMap<>(); | ||
| params.put("bucketParam", bucket); | ||
| params.put("startParam", "-1d10s"); | ||
| parametrizedQuery = "from(bucket: params.bucketParam) |> range(start: duration(v: params.startParam))"; | ||
| query = queryApi.query(parametrizedQuery, org, params); | ||
| query.forEach(fluxTable -> fluxTable.getRecords() | ||
| .forEach(r -> System.out.println(r.getTime() + ": " + r.getValueByKey("_value")))); | ||
|
|
||
| client.close(); | ||
|
|
||
| } | ||
| } |
There was a problem hiding this comment.
Add link to this example into examples/README.md.
| <M> void query(@Nonnull final String query, | ||
| @Nonnull final String org, | ||
| @Nonnull final Class<M> measurementType, | ||
| @Nonnull final BiConsumer<Cancellable, M> onNext, | ||
| @Nonnull final Consumer<? super Throwable> onError, | ||
| @Nonnull final Runnable onComplete, | ||
| @Nullable final Map<String, Object> params); |
| @Override | ||
|
|
||
| @Override |
| query.forEach(fluxTable -> fluxTable.getRecords() | ||
| .forEach(r -> System.out.println(r.getTime() + ": " + r.getValueByKey("_value")))); | ||
|
|
||
| client.close(); |
There was a problem hiding this comment.
Use try-catch instead of close().
| String url = System.getenv("INFLUX_URL"); | ||
| String token = System.getenv("INFLUX_TOKEN"); | ||
| String org = System.getenv("INFLUX_ORG"); | ||
| String bucket = System.getenv("INFLUX_BUCKET"); |
There was a problem hiding this comment.
Use default credentials: "http://localhost:8086", "my-token", ...
| String url = System.getenv("INFLUX_URL"); | ||
| String token = System.getenv("INFLUX_TOKEN"); | ||
| String org = System.getenv("INFLUX_ORG"); | ||
| String bucket = System.getenv("INFLUX_BUCKET"); |
There was a problem hiding this comment.
Use default credentials: "http://localhost:8086", "my-token", ...
bednar
left a comment
There was a problem hiding this comment.
Add possibility to use Query object in com.influxdb.client.reactive.QueryReactiveApi.
Proposed Changes
This PR implements support for Parameterized Queries for InfluxDB Cloud.
https://docs.influxdata.com/influxdb/cloud/query-data/parameterized-queries
Checklist
mvn testcompletes successfully