Cole-Greer commented on code in PR #3427:
URL: https://github.com/apache/tinkerpop/pull/3427#discussion_r3277566878
##########
docs/src/reference/gremlin-variants.asciidoc:
##########
@@ -1671,6 +1671,7 @@ can be passed in the constructor of a new `Client` or
`DriverRemoteConnection` :
|options.traversalSource |String |The traversal source. |'g'
|options.headers |Object |Additional HTTP header key/values included with each
request. |undefined
|options.interceptors |RequestInterceptor/RequestInterceptor[] |One or more
functions that can modify the HTTP request before it is sent. |undefined
+|options.numberMode |String |Set to `'precise'` to wrap deserialized numbers
in typed wrappers that preserve the server's original type. |undefined
Review Comment:
+1 to something like `options.preciseNumbers` as a boolean which defaults to
false.
##########
docs/src/reference/gremlin-variants.asciidoc:
##########
@@ -1969,15 +1970,67 @@ g.V().hasLabel('person').groupCount().by('age')
Either of the above two options accomplishes the desired goal as both prevent
`groupCount()` from having to process
the possibility of `null`.
+[[gremlin-javascript-numeric-types]]
+=== Numeric Types
+
+JavaScript has a single `Number` type (IEEE 754 double) which cannot
distinguish between JVM numeric types. The driver
Review Comment:
Nit: I think it's better if we distance ourself from the JVM a bit and start
referring to these as gremlin types (even though they are implicitly aligned
with Java)
```suggestion
JavaScript has a single `Number` type (IEEE 754 double) which cannot
distinguish between gremlin numeric types. The driver
```
##########
docs/src/reference/gremlin-variants.asciidoc:
##########
@@ -1969,15 +1970,67 @@ g.V().hasLabel('person').groupCount().by('age')
Either of the above two options accomplishes the desired goal as both prevent
`groupCount()` from having to process
the possibility of `null`.
+[[gremlin-javascript-numeric-types]]
+=== Numeric Types
+
+JavaScript has a single `Number` type (IEEE 754 double) which cannot
distinguish between JVM numeric types. The driver
+provides typed wrapper classes and factory functions that give explicit
control over serialization and deserialization.
+
+==== Controlling Serialization
+
+Wrapping a value selects the GremlinLang type suffix and GraphBinary type code
sent to the server. Without wrappers the
+driver infers types automatically, so existing code is unaffected.
+
+[source,javascript]
+----
+const { toLong, toInt, toFloat, toDouble, toShort, toByte } =
gremlin.structure;
+
+g.V().has('age', toInt(29)).next();
+g.V().has('score', toFloat(3.14)).next();
+g.V().has('id', toLong('9007199254740993')).next();
+----
+
+`toLong()` accepts `number`, `string`, or `bigint`. String and bigint inputs
support the full signed 64-bit range;
+number inputs must be within the safe integer range.
Review Comment:
What happens to numbers which are outside of the safe integer range? Does it
throw an exception? This is sort of like an explicit case from double to long
in Java, I think it's fair to truncate to the nearest long, even if it is
inherently imprecise outside of the safe integer range.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]