Cast certain traversal step inputs as int32 for serialization in Gremlin-Go#1743
Conversation
xiazcy
left a comment
There was a problem hiding this comment.
Now, there are other steps which also need int32 casting if the user enters int (examples can be found in gremlin.go by searching int32(), given we are updating this one, should we look into the others and address the same way?
|
@simonz-bq @xiazcy would it be an option to deal with this kind of type conversions inside the function makeBytecodeRequest?
I'm asking because it seems that the root cause of the problem is dealing with this inside the step itself which cannot return an error. |
@jroimartin That may work, and I suppose it would involve checking within a range of bytecode steps that needs casting and perform the cast? Although in that case would we want to add this extra check for every bytecode request we make? |
That's what I had in mind.
I guess it's a trade-off:
Besides that, it is also true that |
Yeah, while it is unlikely for users to enter very large numbers, we probably should handle the case, and I don't see how we can do that here when we can't return errors in a traversal step.
I would agree this may be the most ideal if we can minimize the overhead, to make it more natural for users without the need to cast. |
jroimartin
left a comment
There was a problem hiding this comment.
@simonz-bq so the idea with a0a6db8 is to convert to int32 only if possible and allow the server to fail otherwise, right?
I think it is a good approach. It fulfills all the mentioned requirements: it covers the most common use cases, it does not truncate the user data and it does not add unnecessary overhead on every request.
The only thing I see is that we could fail faster because at the time of the conversion check we already know that the server will fail, but I guess it is not a big deal?
Codecov Report
@@ Coverage Diff @@
## 3.5-dev #1743 +/- ##
===========================================
- Coverage 63.51% 63.21% -0.30%
===========================================
Files 23 23
Lines 3601 3626 +25
===========================================
+ Hits 2287 2292 +5
- Misses 1136 1156 +20
Partials 178 178
Continue to review full report at Codecov.
|
|
LGTM. Although, given my little knowledge of the project, mine are mostly suggestions and a way of learning more about the internals 🙂 |
Certain traversal steps in Gremlin Server only take in
intas arguments, and by default numbers passed through in Go, and therefore by extension Gremlin-Go, are passed in asint, which in Go are a larger data type and is different fromint32, which is what matches Java'sint. The default serialization for such numbers ends up being along, which causes the server to return a failure due to a type mismatch.This change makes it so that when a user uses Gremlin-Go, they no longer have to enter numbers in certain steps as
Times(int32(10))and instead can now just simply doTimes(10). It will now cast the input asint32which will then be serialized to a Javaint, if the number itself is valid to fit in anint32. Otherwise, it will be rejected by the server, as expected.