2

orientdb has a seemingly 'non-standard' feature to be able to create specific classes of vertices and edges.

g.createVertex('class:person')

but it's unclear to me if/how i can qualify on that class via 'standard' gremlin?

i have seen a reference to a syntax like so:

g.V('@class','person')...

here, but then there was mention of this syntax skirting indices.

can anyone shed light on this topic?

Community
  • 1
  • 1
tony_k
  • 1,983
  • 2
  • 20
  • 27

1 Answers1

3

It seems that Gremlin doesn't adopt the Schema feature and not all of the graph databases support schemas, so I don't think that you can manipulate the OrientDB Schema directly with Gremlin.

Anyway, you can use the createVertexType() command to create classes inside OrientDB trhought Gremlin.

  1. Connection to ODB database:

    g = new OrientGraphNoTx('remote:localhost/GremlinDB')
    
    ==>orientgraphnotx[remote:localhost/GremlinDB]
    
  2. Create the Vertex class Person that extends V:

    g.createVertexType('Person','V')
    
    ==>Person
    

Now, if you look at the Schema in OrientDB Studio, you'll see the new class created:

enter image description here

EDITED

After having added two vertices

enter image description here

we can find the person with name = 'John'.

  1. Using has():

    g.V.has('@class','Person').has('name','John')
    
    ==>v(Person)[#12:0]
    
  2. Using has() + T operator:

    g.V.has('@class','Person').has('name',T.eq,'John')
    
    ==>v(Person)[#12:0]
    
  3. Using contains():

    g.V.has('@class','Person').filter{it.name.contains('John')}
    
    ==>v(Person)[#12:0]
    
  4. Using ==:

    g.V.has('@class','Person').filter{it.name == 'John'}
    
    ==>v(Person)[#12:0]
    

Hope it helps

LucaS
  • 1,418
  • 9
  • 12
  • thanks @LucaS, yes, i have already used `createVertexType` to create the subclass of V, but my question is around the idiomatic way to now search on that subclass in a gremlin query (e.g. find me all Persons whose first-name is 'lucas')... – tony_k Apr 14 '16 at 18:52
  • Hi @tony_k, I missed the query :). I'm editing my answer. – LucaS Apr 15 '16 at 04:12
  • Hi @tony_k, I posted some methods you can use to retrieve the results you're looking for. Hope it helps. – LucaS Apr 15 '16 at 04:39
  • Hi @tony_k, did you have a chance to try the queries ? – LucaS Apr 18 '16 at 20:28
  • 1
    thanks @LucaS, these queries look good, i will accept your answer. do you have any idea around "@class" and indexes? i.e. does "@class" have an implicit index on it and do these queries use it? – tony_k Apr 22 '16 at 03:17
  • Hi @tony_k, thanks for voting. At the moment I can't tell you much about the usage of the indexes in OrientDB - gremlin but I'll look for some useful information. In the meanwhile I found some indications in the [Gremlin official docs](http://gremlindocs.spmallette.documentup.com/#indexmapentry) about the indexes, but I have to test them. Glad to have been helpful. – LucaS Apr 22 '16 at 03:43