From f1e2a8f827f203983b5782b84cbbb43f4407a5f9 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Mon, 5 Dec 2022 11:28:05 -0700 Subject: [PATCH 1/5] fix: Use G17 format for doubles fixes: #408 --- CHANGELOG.md | 17 ++++++++++------- Client.Test/PointDataTest.cs | 19 ++++++++++++++++++- Client/Writes/PointData.cs | 9 +++++++-- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b421420ef..d8c82e14e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 4.9.0 [unreleased] +### Bug Fixes +1. [#408](https://github.com/influxdata/influxdb-client-csharp/issues/408): Conversion of double to string can result in a loss of precision + ### Others 1. [#433](https://github.com/influxdata/influxdb-client-csharp/pull/433): Add `.NET 7.0` to supported `.NET` versions @@ -712,7 +715,7 @@ This release also uses new version of InfluxDB OSS API definitions - [oss.yml](h ### Dependencies [#283](https://github.com/influxdata/influxdb-client-csharp/pull/283): Update dependencies: - + #### Build: - RestSharp to 107.3.0 - CsvHelper to 27.2.1 @@ -811,7 +814,7 @@ This release introduces a support for new InfluxDB OSS API definitions - [oss.ym - `Check` <- `CheckDiscriminator` <- `CheckBase` - `NotificationEndpoint` <- `NotificationEndpointDiscriminator` <- `NotificationEndpointBase` - `NotificationRule` <- `NotificationRuleDiscriminator` <- `NNotificationRuleBase` -- Flux AST literals extends the AST `Expression` object +- Flux AST literals extends the AST `Expression` object ### Deprecates - `AuthorizationsApi.CreateAuthorizationAsync(Authorization)`: instead use `AuthorizationsApi.CreateAuthorizationAsync(AuthorizationPostRequest)` @@ -831,7 +834,7 @@ This release introduces a support for new InfluxDB OSS API definitions - [oss.ym - Microsoft.Extensions.ObjectPool to 5.0.7 ### Documentation -1. [#213](https://github.com/influxdata/influxdb-client-csharp/pull/213): API documentation is deploy to [GitHub Pages](https://influxdata.github.io/influxdb-client-csharp/api/InfluxDB.Client.html) +1. [#213](https://github.com/influxdata/influxdb-client-csharp/pull/213): API documentation is deploy to [GitHub Pages](https://influxdata.github.io/influxdb-client-csharp/api/InfluxDB.Client.html) ## 1.19.0 [2021-06-04] @@ -951,7 +954,7 @@ This release introduces a support for new InfluxDB OSS API definitions - [oss.ym 1. [#102](https://github.com/influxdata/influxdb-client-csharp/pull/102): Added WriteApiAsync for asynchronous write without batching ### Bug Fixes -1. [#106](https://github.com/influxdata/influxdb-client-csharp/pull/106): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol, `=` is valid sign for measurement name +1. [#106](https://github.com/influxdata/influxdb-client-csharp/pull/106): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol, `=` is valid sign for measurement name 1. [#108](https://github.com/influxdata/influxdb-client-csharp/issues/108): Replaced useless .ContinueWith in Api by direct call ## 1.9.0 [2020-06-19] @@ -967,8 +970,8 @@ This release introduces a support for new InfluxDB OSS API definitions - [oss.ym 1. [#104](https://github.com/influxdata/influxdb-client-csharp/pull/104): Upgraded InfluxDB 1.7 to 1.8 ### Bug Fixes -1. [#100](https://github.com/influxdata/influxdb-client-csharp/pull/100): Thread-safety disposing of clients -1. [#101](https://github.com/influxdata/influxdb-client-csharp/pull/101/): Use Trace output when disposing WriteApi +1. [#100](https://github.com/influxdata/influxdb-client-csharp/pull/100): Thread-safety disposing of clients +1. [#101](https://github.com/influxdata/influxdb-client-csharp/pull/101/): Use Trace output when disposing WriteApi ## 1.8.0 [2020-05-15] @@ -1064,7 +1067,7 @@ This release introduces a support for new InfluxDB OSS API definitions - [oss.ym ## 1.0.0 [2019-08-23] ### Features -1. [#29](https://github.com/influxdata/influxdb-client-csharp/issues/29): Added support for gzip compression of query response and write body +1. [#29](https://github.com/influxdata/influxdb-client-csharp/issues/29): Added support for gzip compression of query response and write body ### Bug Fixes 1. [#27](https://github.com/influxdata/influxdb-client-csharp/issues/27): The org parameter takes either the ID or Name interchangeably diff --git a/Client.Test/PointDataTest.cs b/Client.Test/PointDataTest.cs index 9223e4751..da965bd30 100644 --- a/Client.Test/PointDataTest.cs +++ b/Client.Test/PointDataTest.cs @@ -154,6 +154,23 @@ public void FieldTypes() Assert.AreEqual(expected, point.ToLineProtocol()); } + [Test] + public void DoubleFormat() + { + var point = PointData.Measurement("sensor") + .Field("double", 250.69D) + .Field("double15", 15.333333333333333D) + .Field("double16", 16.3333333333333333D) + .Field("double17", 17.33333333333333333D) + .Field("example", 459.29587181322927); + + var expected = + "sensor double=250.69,double15=15.33333333333332,double16=16.33333333333332," + + "double17=17.33333333333332,example=459.29587181322927"; + + Assert.AreEqual(expected, point.ToLineProtocol()); + } + [Test] public void FieldNullValue() { @@ -440,4 +457,4 @@ public override string ToString() return $"{Value1}-{Value2}"; } } -} \ No newline at end of file +} diff --git a/Client/Writes/PointData.cs b/Client/Writes/PointData.cs index 86b971c57..9236dbbbf 100644 --- a/Client/Writes/PointData.cs +++ b/Client/Writes/PointData.cs @@ -470,10 +470,15 @@ private bool AppendFields(StringBuilder sb) EscapeKey(sb, key); sb.Append('='); - if (value is double || value is float) + if (value is float) { sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture)); } + else if (value is double) + { + var valueStr = ((double)value).ToString("G17", CultureInfo.InvariantCulture); + sb.Append((IConvertible)valueStr); + } else if (value is uint || value is ulong || value is ushort) { sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture)); @@ -713,4 +718,4 @@ public override int GetHashCode() return !(left == right); } } -} \ No newline at end of file +} From 32170d1aeb3a43440e7cabcc96c07a00d894cea3 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Tue, 6 Dec 2022 07:44:50 -0700 Subject: [PATCH 2/5] remove newline per tests --- Client/Writes/PointData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Writes/PointData.cs b/Client/Writes/PointData.cs index 9236dbbbf..ebabc8597 100644 --- a/Client/Writes/PointData.cs +++ b/Client/Writes/PointData.cs @@ -718,4 +718,4 @@ public override int GetHashCode() return !(left == right); } } -} +} \ No newline at end of file From 4bd513267e61de78f011a357b5c1727ef1d4f087 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Tue, 6 Dec 2022 07:48:50 -0700 Subject: [PATCH 3/5] test updates --- Client.Test/MeasurementMapperTest.cs | 4 ++-- Client.Test/PointDataTest.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Client.Test/MeasurementMapperTest.cs b/Client.Test/MeasurementMapperTest.cs index cfa9b9381..09b750fbe 100644 --- a/Client.Test/MeasurementMapperTest.cs +++ b/Client.Test/MeasurementMapperTest.cs @@ -57,7 +57,7 @@ public void ColumnWithoutName() var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol(); - Assert.AreEqual("poco,tag=tag\\ val value=15.444,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", + Assert.AreEqual("poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", lineProtocol); } @@ -111,7 +111,7 @@ public void MeasurementProperty() var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol(); - Assert.AreEqual("poco,tag=tag\\ val value=15.444,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", + Assert.AreEqual("poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", lineProtocol); } diff --git a/Client.Test/PointDataTest.cs b/Client.Test/PointDataTest.cs index da965bd30..5aa1a2868 100644 --- a/Client.Test/PointDataTest.cs +++ b/Client.Test/PointDataTest.cs @@ -149,7 +149,7 @@ public void FieldTypes() var expected = "h2o,location=europe boolean=false,byte=9i,decimal=25.6,double=250.69,float=35,integer=7i,long=1i," + - "point=13.3,sbyte=12i,short=8i,string=\"string value\",uint=11u,ulong=10u,ushort=13u"; + "point=13.300000000000001,sbyte=12i,short=8i,string=\"string value\",uint=11u,ulong=10u,ushort=13u"; Assert.AreEqual(expected, point.ToLineProtocol()); } @@ -165,7 +165,7 @@ public void DoubleFormat() .Field("example", 459.29587181322927); var expected = - "sensor double=250.69,double15=15.33333333333332,double16=16.33333333333332," + + "sensor double=250.69,double15=15.333333333333332,double16=16.33333333333332," + "double17=17.33333333333332,example=459.29587181322927"; Assert.AreEqual(expected, point.ToLineProtocol()); From d8fdec429a500cfaea472ef34b1d88971e6cfadd Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Tue, 6 Dec 2022 07:53:31 -0700 Subject: [PATCH 4/5] test fixes --- Client.Test/PointDataTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client.Test/PointDataTest.cs b/Client.Test/PointDataTest.cs index 5aa1a2868..0a1932a37 100644 --- a/Client.Test/PointDataTest.cs +++ b/Client.Test/PointDataTest.cs @@ -165,8 +165,8 @@ public void DoubleFormat() .Field("example", 459.29587181322927); var expected = - "sensor double=250.69,double15=15.333333333333332,double16=16.33333333333332," + - "double17=17.33333333333332,example=459.29587181322927"; + "sensor double=250.69,double15=15.333333333333332,double16=16.333333333333332," + + "double17=17.333333333333332,example=459.29587181322927"; Assert.AreEqual(expected, point.ToLineProtocol()); } From 5695d4ad13b0386030150c724b8d8202b7060986 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Tue, 6 Dec 2022 07:57:33 -0700 Subject: [PATCH 5/5] fix formatting per tests --- Client.Test/MeasurementMapperTest.cs | 6 ++++-- Client.Test/PointDataTest.cs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Client.Test/MeasurementMapperTest.cs b/Client.Test/MeasurementMapperTest.cs index 09b750fbe..8875449c4 100644 --- a/Client.Test/MeasurementMapperTest.cs +++ b/Client.Test/MeasurementMapperTest.cs @@ -57,7 +57,8 @@ public void ColumnWithoutName() var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol(); - Assert.AreEqual("poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", + Assert.AreEqual( + "poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", lineProtocol); } @@ -111,7 +112,8 @@ public void MeasurementProperty() var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol(); - Assert.AreEqual("poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", + Assert.AreEqual( + "poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000", lineProtocol); } diff --git a/Client.Test/PointDataTest.cs b/Client.Test/PointDataTest.cs index 0a1932a37..3cc8ca87e 100644 --- a/Client.Test/PointDataTest.cs +++ b/Client.Test/PointDataTest.cs @@ -457,4 +457,4 @@ public override string ToString() return $"{Value1}-{Value2}"; } } -} +} \ No newline at end of file