Skip to content

Commit

Permalink
fix: parsing infinite numbers (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Jul 22, 2021
1 parent 4cbe996 commit 643d3da
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.1.0 [unreleased]

### Bug Fixes
1. [#246](https://github.com/influxdata/influxdb-client-java/pull/246): Parsing infinite numbers
1. [#241](https://github.com/influxdata/influxdb-client-java/pull/241): Set default HTTP protocol to HTTP 1.1

## 3.0.1 [2021-07-16]

### Features
Expand Down Expand Up @@ -45,7 +51,6 @@ The `shift()` function renamed to `timeShift()`.
### Bug Fixes
1. [#227](https://github.com/influxdata/influxdb-client-java/pull/227): Connection URL with custom base path
1. [#236](https://github.com/influxdata/influxdb-client-java/pull/236): Rename `shift()` to `timeShift()` [FluxDSL]
1. [#241](https://github.com/influxdata/influxdb-client-java/pull/241): Set default HTTP protocol to HTTP 1.1

### Dependencies
1. [#227](https://github.com/influxdata/influxdb-client-java/pull/227): Update dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,14 @@ private Object toValue(@Nullable final String strValue, final @Nonnull FluxColum
case "long":
return Long.parseLong(strValue);
case "double":
return Double.parseDouble(strValue);
switch (strValue) {
case "+Inf":
return Double.POSITIVE_INFINITY;
case "-Inf":
return Double.NEGATIVE_INFINITY;
default:
return Double.parseDouble(strValue);
}
case "base64Binary":
return Base64.getDecoder().decode(strValue);
case "dateTime:RFC3339":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,33 @@ public void parseExportFromUserInterface() throws IOException {
Assertions.assertThat(tables.get(1).getRecords()).hasSize(1);
}

@Test
public void parseInf() throws IOException {
String data = "#group,false,false,true,true,true,true,true,true,true,true,false,false\n"
+ "#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,string,string,string,string,string,string,double,double\n"
+ "#default,_result,,,,,,,,,,,\n"
+ ",result,table,_start,_stop,_field,_measurement,language,license,name,owner,le,_value\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,0,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,10,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,20,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,30,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,40,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,50,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,60,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,70,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,80,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,90,0\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,+Inf,15\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,stars,github_repository,C#,MIT License,influxdb-client-csharp,influxdata,-Inf,15\n"
+ "\n";

List<FluxTable> tables = parseFluxResponse(data);
Assertions.assertThat(tables).hasSize(1);
Assertions.assertThat(tables.get(0).getRecords()).hasSize(12);
Assertions.assertThat(tables.get(0).getRecords().get(10).getValueByKey("le")).isEqualTo(Double.POSITIVE_INFINITY);
Assertions.assertThat(tables.get(0).getRecords().get(11).getValueByKey("le")).isEqualTo(Double.NEGATIVE_INFINITY);
}

@Nonnull
private List<FluxTable> parseFluxResponse(@Nonnull final String data) throws IOException {

Expand Down

0 comments on commit 643d3da

Please sign in to comment.