Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
});
});
});

}
}