Skip to content

Commit

Permalink
Merge pull request #347 from influxdata/fix/parsing-inf
Browse files Browse the repository at this point in the history
fix: parsing infinite numbers
  • Loading branch information
sranka authored Aug 2, 2021
2 parents 7f81752 + b17a142 commit de05939
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

1. [#346](https://github.com/influxdata/influxdb-client-js/pull/346): Make QueryApi compatible with rxjs7.

### Bug Fixes

1. [#347](https://github.com/influxdata/influxdb-client-js/pull/347): Parsing infinite numbers

## 1.15.0 [2021-07-09]

### Features
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/results/FluxTableMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ export const typeSerializers: Record<ColumnType, (val: string) => any> = {
boolean: (x: string): any => x === 'true',
unsignedLong: (x: string): any => (x === '' ? null : +x),
long: (x: string): any => (x === '' ? null : +x),
double: (x: string): any => (x === '' ? null : +x),
double(x: string): any {
switch (x) {
case '':
return null
case '+Inf':
return Number.POSITIVE_INFINITY
case '-Inf':
return Number.NEGATIVE_INFINITY
default:
return +x
}
},
string: identity,
base64Binary: identity,
duration: (x: string): any => (x === '' ? null : x),
Expand Down
6 changes: 5 additions & 1 deletion packages/core/test/unit/results/FluxTableMetaData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ describe('FluxTableMetaData', () => {
['long', '', null],
['double', '1', 1],
['double', '', null],
['double', '+Inf', Number.POSITIVE_INFINITY],
['double', '-Inf', -Number.POSITIVE_INFINITY],
['string', '1', '1'],
['base64Binary', '1', '1'],
['dateTime', '1', '1'],
Expand All @@ -75,7 +77,9 @@ describe('FluxTableMetaData', () => {
}),
]
const subject = createFluxTableMetaData(columns)
expect(subject.toObject([entry[1]])).to.deep.equal({a: entry[2]})
const val = subject.toObject([entry[1]])
const entryElement = entry[2]
expect(val).to.deep.equal({a: entryElement})
})
}
describe('custom serialization', () => {
Expand Down

0 comments on commit de05939

Please sign in to comment.