-
Notifications
You must be signed in to change notification settings - Fork 821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GremlinLang to Go driver #2965
Conversation
gremlin-go/driver/client.go
Outdated
// submitGremlinLang submits GremlinLang to the server to execute and returns a ResultSet. | ||
// TODO test and update when connection is set up | ||
func (client *Client) submitGremlinLang(gremlinLang *GremlinLang) (ResultSet, error) { | ||
client.logHandler.logf(Debug, submitStartedBytecode, *gremlinLang) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log message should be changed to gremlin lang
// TODO test and update when connection is set up | ||
func (driver *DriverRemoteConnection) submitGremlinLang(gremlinLang *GremlinLang) (ResultSet, error) { | ||
if driver.isClosed { | ||
return nil, newError(err0203SubmitBytecodeToClosedConnectionError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message should be updated to reference gremlin lang.
@@ -922,7 +925,6 @@ func (t *Transaction) Begin() (*GraphTraversalSource, error) { | |||
|
|||
gts := &GraphTraversalSource{ | |||
graph: t.g.graph, | |||
bytecode: t.g.bytecode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be replaced by gremlinLang: t.g.gremlinLang,
?
@@ -42,95 +42,88 @@ func NewGraphTraversalSource(graph *Graph, remoteConnection *DriverRemoteConnect | |||
convertedArgs := convertStrategyVarargs(traversalStrategies) | |||
bc := NewBytecode(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove bc
?
} | ||
} | ||
//TODO verify | ||
var optionsStrategy TraversalStrategy = gts.gremlinLang.optionsStrategies[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for optionStrategies
to be empty and produce out of bounds error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's part of next step, which is to revisit how options is applied in go.
) | ||
|
||
type GremlinLang struct { | ||
emptyArray []interface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be [0]interface{}
so that it cannot be mutated to be non-empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep this in mind and revisit. Current I've set it up where the method requires[]interface{}
to be returned.
gremlin-go/driver/gremlinlang.go
Outdated
|
||
func (gl *GremlinLang) addToGremlin(name string, args ...interface{}) { | ||
flattenedArgs := gl.flattenArguments(args...) | ||
//flattenedArgs := reflect.ValueOf(gl.flattenArguments(args...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove commented out code
gremlin-go/driver/gremlinlang.go
Outdated
gl.gremlin.WriteString("Cardinality.") | ||
//str0, _ := gl.argAsString(flattenedArgs.Index(0)) | ||
//str1, _ := gl.argAsString(flattenedArgs.Index(1)) | ||
str0, _ := gl.argAsString(flattenedArgs[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be error handling if the flattenedArgs are not an array of exactly 2 items as expected?
} | ||
} | ||
|
||
//var withOptionsMap map[any]string = map[any]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should delete commented out code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll be revisiting this. I'll add a TODO to remind me
gremlin-go/driver/gremlinlang.go
Outdated
switch v := arg.(type) { | ||
case string: | ||
// TODO check escaping & formatting | ||
return fmt.Sprintf("\"%s\"", html.EscapeString(v)), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about %q
instead of %s
+ html.EscapeString(v)
(since I don't think we want HTML syntax)?
https://pkg.go.dev/fmt#hdr-Printing
%q a double-quoted string safely escaped with Go syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a deeper dive is warranted here. The requirement is for it to be properly escaped according to gremlin-lang syntax (cannot close out the string literal and start writing subsequent steps). It's not immediately clear that Go or HTML escaping meets this requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think since we are concerned mainly with single and double quotes I'll just create a string replacer
return "null", nil | ||
} | ||
|
||
switch v := arg.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to worry about a few types not included in this switch statement such as complex64, complex128, uintptr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we consider them, but I'll keep track of this and will come back to visit this point
gremlin-go/driver/traversal.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the line t.Bytecode.AddStep("discard")
be converted to gremlin lang?
gremlin-go/driver/gremlinlang.go
Outdated
return fmt.Sprintf("%s.%s", strings.ToUpper(name[:1])+name[1:], v), nil | ||
case *Vertex: | ||
id, _ := gl.argAsString(v.Id) | ||
return fmt.Sprintf("new ReferenceVertex(%s,\"%s\")", id, v.Label), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be a need to escape the id and label here.
return paramName | ||
} | ||
|
||
func (gl *GremlinLang) GetGremlin(arg ...string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I wonder if we should limit using this vargargs pattern for psuedo-overloaded methods in favour of something more idiomatic in go. Feel free to ignore this request if you'd like as this pattern is already heavily used throughout gremlin-go.
VOTE +1 |
…tes will be needed when connection is set up.
21974c6
to
f06e6a0
Compare
VOTE +1 |
Merging to a feature branch instead. Will open PR to release branch for official review process once the go driver is fully complete. |
Base set of changes to add GremlinLang to Go driver, adapted from the originally translator. Datetime and strategies will be updated separately.
Additional clean-up and updates will be done once remote connection is fully set-up, tests will also remain disabled until then.