How can I query by @RID using the Gremlin Shell?

143 views
Skip to first unread message

William Marshall

unread,
Apr 21, 2015, 7:32:54 PM4/21/15
to orient-...@googlegroups.com
I am attempting to use Gremlin (in this case I'm actually using the gremlin.bat file included with OrientDB 2.0.7) to return the values of Vertex #12:615.  Unfortunately, the syntax shown in the Retrieve a Vertex section of Gremlin API page of your documentation is not working for me.  I either get an error or a bunch of NULLs (see below).

The Vertex I am trying to access is #12:615, which is a Vertex of the Schema-Mixed Company class.  As per the documentation for ETL imports, it has both id and name properties in addition to a Company.id Index.

In this particular case, I expect to return the following values (Copied from OrientDB Studio results):
{
   
"result": [
       
{
           
"@type": "d",
           
"@rid": "#12:615",
           
"@version": 5,
           
"@class": "Company",
           
"id": 1044619,
           
"name": "Test Company 1",
           
"address1": "1234 Welcome St.",
           
"address2": null,
           
"city": "Starter City",
           
"state": "GA",
           
"postalCode": "31020",
           
"country": "US",
           
"latitude": 32.648320,
           
"longitude": -83.444530,
           
"stockSymbol": "NYSE:TC1",
           
"website": "www.company.test",
           
"yearEstablished": 2015,
           
"@fieldTypes": "latitude=d,longitude=d"
       
}
   
],
   
"notification": "Query executed in 0.096 sec. Returned 1 record(s)"
}

Results:
gremlin> g.v['12:615']
No such property: v for class: com.tinkerpop.blueprints.impls.orient.OrientGraph
Display stack trace? [yN] n
gremlin
> g.V['12:615']
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
==>null
gremlin
>

Any ideas?

Kyle

unread,
Apr 21, 2015, 8:10:59 PM4/21/15
to orient-...@googlegroups.com
 g.v['12:615']

should be

g.v('12:615')

note the lower case "v" and the () instead of []


 In 
g.V['12:615']


the 
g.V

is getting all vertices in g, then getting the property
 '12:615'
from them, since this does not exist you get nulls.

I would beware using g.V since it will return ALL vertices


Has some info that will be useful to you.

Say you have a class
MyV
with indices 

MyV.myid UNIQUE_HASH_INDEX STRING
MyV.kind NOTUNIQUE STRING

then
g.getVertices("MyV.kind", "baz")._()
will get you a gremlin pipe of everything in the index MyV.kind
getVertices  needs the  "._()" in order to turn the result into a gremlin pipeline. 

to get one vertex you can do 
g.getVertexByKey("MyV.myid", "foobar") 

or 
g.getVertices("MyV.myid", "foobar")._()[[0] //will error if doesn't exist

If you do 
g.getVertices("myid", "foobar")
orientdb should check if you have an index "V.myid" and use that if it exists.


It is kinda tricky telling if the indices are used sometimes.

Hope this helps!

William Marshall

unread,
Apr 22, 2015, 9:23:11 AM4/22/15
to orient-...@googlegroups.com
That helped quite a bit, thank you!
Reply all
Reply to author
Forward
0 new messages