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: 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..fca1109ad8 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,7 +74,8 @@ 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" + ); InfluxQLQueryResult result = InfluxQLQueryApiImpl.readInfluxQLResult(reader, NO_CANCELLING, extractValues); @@ -171,4 +176,43 @@ void readInfluxQLResult() throws IOException { }); }); } + + @Test + public void readInfluxQLShowSeriesRequest() throws IOException { + + 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); + 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"); + }); + }); + }); + + } }