From 50741f15728a04f3f31985750c408894cbb1e3ed Mon Sep 17 00:00:00 2001 From: karel rehor Date: Wed, 17 Apr 2024 16:59:17 +0200 Subject: [PATCH 1/3] fix: issue #684 - SHOW SERIES and other results with empty name or tags fields --- .../client/internal/InfluxQLQueryApiImpl.java | 2 +- .../internal/InfluxQLQueryApiImplTest.java | 39 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/client/src/main/java/com/influxdb/client/internal/InfluxQLQueryApiImpl.java b/client/src/main/java/com/influxdb/client/internal/InfluxQLQueryApiImpl.java index f02f6d97e9..255ae17a1e 100644 --- a/client/src/main/java/com/influxdb/client/internal/InfluxQLQueryApiImpl.java +++ b/client/src/main/java/com/influxdb/client/internal/InfluxQLQueryApiImpl.java @@ -126,7 +126,7 @@ static InfluxQLQueryResult readInfluxQLResult( break; } int resultIndex = results.size(); - if (csvRecord.size() == 1 || csvRecord.get(0).equals("")) { + if (csvRecord.size() == 1 && csvRecord.get(0).equals("")) { if (series != null) { InfluxQLQueryResult.Result result = new InfluxQLQueryResult.Result( resultIndex, diff --git a/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java b/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java index 0f7f94bf1a..108f005625 100644 --- a/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java +++ b/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java @@ -25,9 +25,13 @@ import java.io.StringReader; import java.time.Instant; import java.util.List; +import java.util.Map; import com.influxdb.Cancellable; import com.influxdb.query.InfluxQLQueryResult; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -70,12 +74,19 @@ void readInfluxQLResult() throws IOException { "name,tags,time,usage_user,usage_system\n" + "cpu,\"region=us-east-1,host=server1\",1483225200,13.57,1.4\n" + "cpu,\"region=us-east-1,host=server1\",1483225201,14.06,1.7\n" + - "cpu,\"region=us-east-1,host=server2\",1483225200,67.91,1.3\n"); + "cpu,\"region=us-east-1,host=server2\",1483225200,67.91,1.3\n" + + "\n" + + "name,tags,key\n" + //emulate SHOW SERIES response + ",,temperature\n" + + ",,\"pressure\"\n" + + ",,humid\n" + + ",,\"temperature,locale=nw002,device=rpi5_88e1\"" + ); InfluxQLQueryResult result = InfluxQLQueryApiImpl.readInfluxQLResult(reader, NO_CANCELLING, extractValues); List results = result.getResults(); - Assertions.assertThat(results).hasSize(4); + Assertions.assertThat(results).hasSize(5); Assertions.assertThat(results.get(0)) .extracting(InfluxQLQueryResult.Result::getSeries) .satisfies(series -> { @@ -170,5 +181,29 @@ void readInfluxQLResult() throws IOException { .isEqualTo("1.3"); }); }); + + Assertions.assertThat(results.get(4)) + .extracting(InfluxQLQueryResult.Result::getSeries) + .satisfies(series -> { + Assertions.assertThat(series).hasSize(1); + Assertions.assertThat(series.get(0)) + .satisfies(series1 -> { + Assertions.assertThat(series1.getName()).isEmpty(); + Assertions.assertThat(series1.getTags()).isEmpty(); + Assertions.assertThat(series1.getValues()).hasSize(4); + Assertions.assertThat(series1.getValues()) + .satisfies(records -> { + Assertions.assertThat(records.size()).isEqualTo(4); + Assertions.assertThat(records.get(0).getValueByKey("key")) + .isEqualTo("temperature"); + Assertions.assertThat(records.get(1).getValueByKey("key")) + .isEqualTo("pressure"); + Assertions.assertThat(records.get(2).getValueByKey("key")) + .isEqualTo("humid"); + Assertions.assertThat(records.get(3).getValueByKey("key")) + .isEqualTo("temperature,locale=nw002,device=rpi5_88e1"); + }); + }); + }); } } From d2ee9d54dd99fb862a682480440125dfa48ef1bb Mon Sep 17 00:00:00 2001 From: karel rehor Date: Thu, 18 Apr 2024 13:53:47 +0200 Subject: [PATCH 2/3] doc: update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b59a2b843e..e648ed0452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## 7.1.0 [unreleased] +### Bug Fixes + +1, [#684](https://github.com/influxdata/influxdb-client-java/issues/684): Fix checking for CSV end of table marker when parsing CSV stream to InfluxQLQueryResult, needed for example when parsing the results of a query like "SHOW SERIES". + ### Dependencies Update dependencies: From 7092ea4b8625361f1e03293167ffe035e98695a8 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Fri, 19 Apr 2024 10:31:50 +0200 Subject: [PATCH 3/3] test: separate SHOW SERIES data into targeted test --- .../internal/InfluxQLQueryApiImplTest.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java b/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java index 108f005625..fca1109ad8 100644 --- a/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java +++ b/client/src/test/java/com/influxdb/client/internal/InfluxQLQueryApiImplTest.java @@ -74,19 +74,13 @@ void readInfluxQLResult() throws IOException { "name,tags,time,usage_user,usage_system\n" + "cpu,\"region=us-east-1,host=server1\",1483225200,13.57,1.4\n" + "cpu,\"region=us-east-1,host=server1\",1483225201,14.06,1.7\n" + - "cpu,\"region=us-east-1,host=server2\",1483225200,67.91,1.3\n" + - "\n" + - "name,tags,key\n" + //emulate SHOW SERIES response - ",,temperature\n" + - ",,\"pressure\"\n" + - ",,humid\n" + - ",,\"temperature,locale=nw002,device=rpi5_88e1\"" - ); + "cpu,\"region=us-east-1,host=server2\",1483225200,67.91,1.3\n" + ); InfluxQLQueryResult result = InfluxQLQueryApiImpl.readInfluxQLResult(reader, NO_CANCELLING, extractValues); List results = result.getResults(); - Assertions.assertThat(results).hasSize(5); + Assertions.assertThat(results).hasSize(4); Assertions.assertThat(results.get(0)) .extracting(InfluxQLQueryResult.Result::getSeries) .satisfies(series -> { @@ -181,8 +175,22 @@ void readInfluxQLResult() throws IOException { .isEqualTo("1.3"); }); }); + } + + @Test + public void readInfluxQLShowSeriesRequest() throws IOException { - Assertions.assertThat(results.get(4)) + StringReader reader = new StringReader("name,tags,key\n" + //emulate SHOW SERIES response + ",,temperature\n" + + ",,\"pressure\"\n" + + ",,humid\n" + + ",,\"temperature,locale=nw002,device=rpi5_88e1\"" + ); + + InfluxQLQueryResult result = InfluxQLQueryApiImpl.readInfluxQLResult(reader, NO_CANCELLING, + (columnName, rawValue, resultIndex, seriesName) -> { return rawValue;}); + + Assertions.assertThat(result.getResults().get(0)) .extracting(InfluxQLQueryResult.Result::getSeries) .satisfies(series -> { Assertions.assertThat(series).hasSize(1); @@ -205,5 +213,6 @@ void readInfluxQLResult() throws IOException { }); }); }); + } }