问题
I'm on the Gremlin console and connected to an AWS Neptune DB
g.V().hasLabel('Risk').toList()
provides the expected results, but when i try to assign the results to a variable
risks = g.V().hasLabel('Risk').toList()
I get the message below - the token recognition error is clearly throwing on the variable name because when i change the variable name the position and "at" part of the message changes.
{"requestId":"650d7c4b-44d1-43f8-b9a3-fbf085cc3ead","code":"MalformedQueryException","detailedMessage":"Query parsing failed at line 1, character position at 3, error message : token recognition error at: 'ks'"}
I tried the same thing on a Tinkerpop database and the variable assignment works. What am I missing?
回答1:
As you noticed, you cannot assign a variable when connected to Neptune with the console in :remote console
mode. One thing you can do is with the console in local mode but connected to the server, issue a query such as :> g.V().limit(1)
and the result of the query will be accessible via a special variable maintained by the console called result
. Here is a simple example:
gremlin> :> g.V().count()
==> 3653
gremlin> result
==> result{object=3653 class=java.lang.String}
gremlin println result['object']
[3653]
gremlin> r = result['object'][0]
gremlin> println r
3653
Here is an example with a list as the result.
gremlin> :> g.V('1','2').values('city').toList()
==>Atlanta
==>Anchorage
gremlin> result
==>result{object=Atlanta class=java.lang.String}
==>result{object=Anchorage class=java.lang.String}
gremlin> result.each {println "City was : " + it['object']}
City was : Atlanta
City was : Anchorage
I sometimes find this useful if you want to use Groovy to post process some results in the console when the ability to assign a variable is not available.
来源:https://stackoverflow.com/questions/59316233/variables-gremlin-on-neptune