Skip to content

Commit d7eb6e1

Browse files
russcamMpdreamz
authored andcommitted
Add important admonition about using System.Decimal POCO property types (#2495)
Bump AsciiDoctNet to support additional asciidoc syntax Closes #2463
1 parent 0638e9f commit d7eb6e1

File tree

10 files changed

+57
-14
lines changed

10 files changed

+57
-14
lines changed

docs/aggregations/writing-aggregations.asciidoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ return s => s
144144
);
145145
----
146146
<1> a list of aggregation functions to apply
147-
148147
<2> Using LINQ's `Aggregate()` function to accumulate/apply all of the aggregation functions
149148

150149
Combining multipe `AggregationDescriptor`'s is also possible using the bitwise `&` operator
@@ -212,6 +211,5 @@ var maxPerChild = childAggregation.Max("max_per_child");
212211
maxPerChild.Should().NotBeNull(); <2>
213212
----
214213
<1> Do something with the average per child. Here we just assert it's not null
215-
216214
<2> Do something with the max per child. Here we just assert it's not null
217215

docs/client-concepts/high-level/mapping/auto-map.asciidoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,29 @@ var expected = new
249249
Expect(expected).WhenSerializing((ICreateIndexRequest)descriptor);
250250
----
251251

252+
[IMPORTANT]
253+
====
254+
Some .NET types do not have direct equivalent Elasticsearch types. For example, `System.Decimal` is a type
255+
commonly used to express currencies and other financial calculations that require large numbers of significant
256+
integral and fractional digits and no round-off errors. There is no equivalent type in Elasticsearch, and the
257+
nearest type is {ref_current}/number.html[``double``], a double-precision 64-bit IEEE 754 floating point.
258+
259+
When a POCO has a `System.Decimal` property, it is automapped to the Elasticsearch `double` type. With the caveat
260+
of a potential loss of precision, this is generally acceptable for a lot of use cases, but it can however cause
261+
problems in _some_ edge cases.
262+
263+
As the https://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/csharp%20language%20specification.doc[C# Specification states],
264+
265+
[quote, C# Specification section 6.2.1]
266+
For a conversion from `decimal` to `float` or `double`, the `decimal` value is rounded to the nearest `double` or `float` value.
267+
While this conversion may lose precision, it never causes an exception to be thrown.
268+
269+
This conversion causes an exception to be thrown at deserialization time for `Decimal.MinValue` and `Decimal.MaxValue` because, at
270+
serialization time, the nearest `double` value that is converted to is outside of the bounds of `Decimal.MinValue` or `Decimal.MaxValue`,
271+
respectively. In these cases, it is advisable to use `double` as the POCO property type.
272+
273+
====
274+
252275
[[auto-mapping-with-overrides]]
253276
[float]
254277
== Auto mapping with overrides

docs/high-level.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ please modify the original csharp file found at the link and submit the PR with
1414
[partintro]
1515
--
1616
The high level client, `ElasticClient`, provides a strongly typed query DSL that maps one-to-one with the Elasticsearch query DSL.
17+
1718
It can be installed from the Package Manager Console inside Visual Studio using
1819

1920
[source,shell]
@@ -22,8 +23,10 @@ Install-Package NEST
2223
----
2324

2425
Or by searching for https://www.nuget.org/packages/NEST[NEST] in the Package Manager GUI.
26+
2527
NEST internally uses and still exposes the low level client, `ElasticLowLevelClient`, from <<elasticsearch-net,Elasticsearch.Net>> via
2628
the `.LowLevel` property on `ElasticClient`.
29+
2730
There are a number of conventions that NEST uses for inference of
2831

2932
* <<index-name-inference, Index Names>>

docs/low-level.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ please modify the original csharp file found at the link and submit the PR with
1515
--
1616
The low level client, `ElasticLowLevelClient`, is a low level, dependency free client that has no
1717
opinions about how you build and represent your requests and responses.
18+
1819
It can be installed from the Package Manager Console inside Visual Studio using
1920

2021
[source,shell]

paket.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
NUGET
22
remote: https://www.nuget.org/api/v2
3-
AsciiDocNet (1.0.0-alpha3)
3+
AsciiDocNet (1.0.0-alpha5)
44
Bogus (7.1.6)
55
NETStandard.Library (>= 1.6) - framework: >= netstandard13
66
Newtonsoft.Json (>= 9.0.1) - framework: >= net40, >= netstandard13

src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public override void Visit(SectionTitle sectionTitle)
265265
var builder = new StringBuilder();
266266
using (var writer = new AsciiDocVisitor(new StringWriter(builder)))
267267
{
268-
writer.Visit(sectionTitle.Elements);
268+
writer.Visit((InlineContainer)sectionTitle);
269269
}
270270

271271
var title = builder.ToString().PascalToHyphen();
@@ -301,7 +301,7 @@ private bool LastSectionTitleMatches(Func<string, bool> predicate)
301301
var builder = new StringBuilder();
302302
using (var visitor = new AsciiDocVisitor(new StringWriter(builder)))
303303
{
304-
visitor.Visit(lastSectionTitle.Elements);
304+
visitor.Visit((InlineContainer)lastSectionTitle);
305305
}
306306

307307
return predicate(builder.ToString());

src/CodeGeneration/DocGenerator/Documentation/Files/CSharpDocumentationFile.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ private void CleanDocumentAndWriteToFile(string body, FileInfo destination)
199199
{
200200
document.Accept(new AsciiDocVisitor(file));
201201
}
202-
203202
}
204203
}
205204
}

src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.IO;
4-
using System.Reflection.Emit;
53
using System.Text.RegularExpressions;
6-
using DocGenerator;
74

85
namespace DocGenerator.Documentation.Files
96
{

src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public override void SaveToDocumentationFolder()
1111
{
1212
var docFileName = this.CreateDocumentationLocation();
1313

14-
// copy for asciidoc to work (path is relative to file)
14+
// copy for asciidoc to work when viewing a single asciidoc in the browser (path is relative to file)
1515
this.FileLocation.CopyTo(docFileName.FullName, true);
1616

1717
// copy to the root as well, for the doc generation process (path is relative to root)

src/Tests/ClientConcepts/HighLevel/Mapping/AutoMap.doc.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,36 @@ public void UsingAutoMap()
235235
};
236236

237237
Expect(expected).WhenSerializing((ICreateIndexRequest)descriptor);
238-
}
239-
238+
}
239+
/**[IMPORTANT]
240+
* ====
241+
* Some .NET types do not have direct equivalent Elasticsearch types. For example, `System.Decimal` is a type
242+
* commonly used to express currencies and other financial calculations that require large numbers of significant
243+
* integral and fractional digits and no round-off errors. There is no equivalent type in Elasticsearch, and the
244+
* nearest type is {ref_current}/number.html[``double``], a double-precision 64-bit IEEE 754 floating point.
245+
*
246+
* When a POCO has a `System.Decimal` property, it is automapped to the Elasticsearch `double` type. With the caveat
247+
* of a potential loss of precision, this is generally acceptable for a lot of use cases, but it can however cause
248+
* problems in _some_ edge cases.
249+
*
250+
* As the https://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/csharp%20language%20specification.doc[C# Specification states],
251+
*
252+
* [quote, C# Specification section 6.2.1]
253+
* For a conversion from `decimal` to `float` or `double`, the `decimal` value is rounded to the nearest `double` or `float` value.
254+
* While this conversion may lose precision, it never causes an exception to be thrown.
255+
*
256+
* This conversion causes an exception to be thrown at deserialization time for `Decimal.MinValue` and `Decimal.MaxValue` because, at
257+
* serialization time, the nearest `double` value that is converted to is outside of the bounds of `Decimal.MinValue` or `Decimal.MaxValue`,
258+
* respectively. In these cases, it is advisable to use `double` as the POCO property type.
259+
* ====
260+
*/
261+
240262
/**[float]
241263
* == Auto mapping with overrides
242264
* In most cases, you'll want to map more than just the vanilla datatypes and also provide
243265
* various options for your properties (analyzer to use, whether to enable doc_values, etc...).
244266
* In that case, it's possible to use `.AutoMap()` in conjunction with explicitly mapped properties.
245-
*/
267+
*/
246268
[U]
247269
public void OverridingAutoMappedProperties()
248270
{
@@ -882,7 +904,7 @@ public void PutMappingAlsoAdheresToMaxRecursion()
882904
//endhide
883905

884906
/**[float]
885-
* == Applying conventions through the Visitor pattern
907+
* == Applying conventions through the Visitor pattern
886908
* It is also possible to apply a transformation on all or specific properties.
887909
*
888910
* `.AutoMap()` internally implements the https://en.wikipedia.org/wiki/Visitor_pattern[visitor pattern]. The default visitor, `NoopPropertyVisitor`,

0 commit comments

Comments
 (0)