Skip to content

Commit 643d3da

Browse files
authored
fix: parsing infinite numbers (#246)
1 parent 4cbe996 commit 643d3da

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 3.1.0 [unreleased]
2+
3+
### Bug Fixes
4+
1. [#246](https://github.com/influxdata/influxdb-client-java/pull/246): Parsing infinite numbers
5+
1. [#241](https://github.com/influxdata/influxdb-client-java/pull/241): Set default HTTP protocol to HTTP 1.1
6+
17
## 3.0.1 [2021-07-16]
28

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

5055
### Dependencies
5156
1. [#227](https://github.com/influxdata/influxdb-client-java/pull/227): Update dependencies:

client-core/src/main/java/com/influxdb/query/internal/FluxCsvParser.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,14 @@ private Object toValue(@Nullable final String strValue, final @Nonnull FluxColum
289289
case "long":
290290
return Long.parseLong(strValue);
291291
case "double":
292-
return Double.parseDouble(strValue);
292+
switch (strValue) {
293+
case "+Inf":
294+
return Double.POSITIVE_INFINITY;
295+
case "-Inf":
296+
return Double.NEGATIVE_INFINITY;
297+
default:
298+
return Double.parseDouble(strValue);
299+
}
293300
case "base64Binary":
294301
return Base64.getDecoder().decode(strValue);
295302
case "dateTime:RFC3339":

client-core/src/test/java/com/influxdb/query/internal/FluxCsvParserTest.java

+27
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,33 @@ public void parseExportFromUserInterface() throws IOException {
613613
Assertions.assertThat(tables.get(1).getRecords()).hasSize(1);
614614
}
615615

616+
@Test
617+
public void parseInf() throws IOException {
618+
String data = "#group,false,false,true,true,true,true,true,true,true,true,false,false\n"
619+
+ "#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,string,string,string,string,string,string,double,double\n"
620+
+ "#default,_result,,,,,,,,,,,\n"
621+
+ ",result,table,_start,_stop,_field,_measurement,language,license,name,owner,le,_value\n"
622+
+ ",,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"
623+
+ ",,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"
624+
+ ",,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"
625+
+ ",,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"
626+
+ ",,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"
627+
+ ",,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"
628+
+ ",,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"
629+
+ ",,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"
630+
+ ",,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"
631+
+ ",,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"
632+
+ ",,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"
633+
+ ",,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"
634+
+ "\n";
635+
636+
List<FluxTable> tables = parseFluxResponse(data);
637+
Assertions.assertThat(tables).hasSize(1);
638+
Assertions.assertThat(tables.get(0).getRecords()).hasSize(12);
639+
Assertions.assertThat(tables.get(0).getRecords().get(10).getValueByKey("le")).isEqualTo(Double.POSITIVE_INFINITY);
640+
Assertions.assertThat(tables.get(0).getRecords().get(11).getValueByKey("le")).isEqualTo(Double.NEGATIVE_INFINITY);
641+
}
642+
616643
@Nonnull
617644
private List<FluxTable> parseFluxResponse(@Nonnull final String data) throws IOException {
618645

0 commit comments

Comments
 (0)