Skip to content

Commit fbedbd8

Browse files
authored
fix: Fix support for InfluxDB 1.8.x in InfluxQLQueryAPI (#459)
* fix: Fix support for InfluxDB 1.x in InfluxQLQueryAPI (#458) InfluxQL queries will be sent as a urlencoded form-body as 1.8.x does not support use of the `application/vnd.influxql` mime-type * chore: Update changelog * chore: add test Adds test for InfluxQL queries against a 1.8 instance. Credit to @bednar
1 parent f137cd9 commit fbedbd8

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
1. [#439](https://github.com/influxdata/influxdb-client-java/pull/439): Add `FluxRecord.getRow()` which stores response data in a list
55
1. [#457](https://github.com/influxdata/influxdb-client-java/pull/457): Add possibility to use `AuthorizationPostRequest` and `AuthorizationUpdateRequest` in `AuthorizationApi`
66

7+
### Bug Fixes
8+
1. [#459](https://github.com/influxdata/influxdb-client-java/pull/459): Fix support for InfluxDB 1.8.x in InfluxQLQueryAPI
9+
710
### Dependencies
811

912
1. [#446](https://github.com/influxdata/influxdb-client-java/pull/446): Remove `gson-fire`

client/src/generated/java/com/influxdb/client/service/InfluxQLQueryService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ public interface InfluxQLQueryService {
1515
* @param zapTraceSpan OpenTracing span context (optional)
1616
* @return response in csv format
1717
*/
18-
@Headers({"Accept:application/csv", "Content-Type:application/vnd.influxql"})
18+
@Headers({"Accept:application/csv", "Content-Type:application/x-www-form-urlencoded"})
19+
@FormUrlEncoded
1920
@POST("query")
2021
Call<ResponseBody> query(
21-
@Body String query,
22+
@Field("q") String query,
2223
@Nonnull @Query("db") String db,
2324
@Query("rp") String retentionPolicy,
2425
@Query("epoch") String epoch,
2526
@Header("Zap-Trace-Span") String zapTraceSpan
2627
);
27-
}
28+
}

client/src/test/java/com/influxdb/client/ITInfluxQLQueryApi.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,29 @@ void testSelectAll() {
133133
});
134134
}
135135

136+
@Test
137+
void testInfluxDB18() {
138+
// create database
139+
String db = "testing_database";
140+
influxDBQuery("CREATE DATABASE " + db, db);
141+
142+
// connect to InfluxDB 1.8
143+
influxDBClient.close();
144+
influxDBClient = InfluxDBClientFactory.createV1(getInfluxDbUrl(), "username", "password".toCharArray(),
145+
db, "autogen");
146+
influxQLQueryApi = influxDBClient.getInfluxQLQueryApi();
147+
148+
// test query to InfluxDB 1.8
149+
InfluxQLQueryResult result = influxQLQueryApi.query(new InfluxQLQuery("SHOW DATABASES", db));
150+
assertSingleSeriesRecords(result)
151+
.map(record -> record.getValueByKey("name"))
152+
.contains(db);
153+
154+
155+
// drop database
156+
influxDBQuery("DROP DATABASE " + db, db);
157+
}
158+
136159
private ListAssert<InfluxQLQueryResult.Series.Record> assertSingleSeriesRecords(InfluxQLQueryResult result) {
137160
return Assertions.assertThat(result)
138161
.extracting(InfluxQLQueryResult::getResults, list(InfluxQLQueryResult.Result.class))

0 commit comments

Comments
 (0)