orientdb-gremlin icon indicating copy to clipboard operation
orientdb-gremlin copied to clipboard

Get vertex by class

Open Krever opened this issue 8 years ago • 5 comments

Hi, is it possible to make a query that gives back all vertices of specified class?

There is a graph.getVerticesOfClass("xxx") method availible in current orientd graph api but not in this backend. Also I have found following snippets:

graph.V.has("@class","xxx")
graph.V.hasLabel("class:xxx")

but they're not working either.

Thanks for help :)

Edit: Now i see, that I can use hasLabel stripping first two characters of my class, because of prefixes used by you(V_, E_). Is there any way of configuration, so I can disable these prefixes?

Moreover such call rise a warning

WARNING: scanning through all vertices without using an index for Traversal [OrientGraphStep(vertex,[~label.eq(x)])]

graph.getVerticesOfClass("xxx") doesn't have such problem. Should I add some index manually?

Krever avatar Dec 26 '15 18:12 Krever

Sorry for the late reply, I'm only just back from holidays.

You can configure this behaviour (prefixing V_ and E_) on OrientGraphFactory.setLabelAsClassName(boolean)

Are you using an existing orientdb that was not created with this driver?

mpollmeier avatar Jan 10 '16 21:01 mpollmeier

No problem, I hope you've had happy holidays.

Yes, I'm using existing DB. I prefer to create a schema by script rather than by code.

Thanks for your help :)

Krever avatar Jan 11 '16 06:01 Krever

Hi,

Why I have to query like this to get vertices by class? graph.V.has("@class","xxx") graph.V.hasLabel("class:xxx")

not like this? (by greamlin-scala syntax) graph.V.has("xxx")

Is this difference come from nature of orientDB..?

...anyway, thx to your contributions very much!

wildroco avatar May 13 '16 07:05 wildroco

has(String) always checks for property values, not class names, this is true for all gremlin variants and databases. not sure if I understood you correctly...?

mpollmeier avatar May 15 '16 06:05 mpollmeier

Oh, sorry.

I mean: hasLabel(string)

And I found it works fine after some test.

Anyway, I queried my class "A" using g. V. hasLabel("A")

and it seems works below too. g. V. hasLabel("class:A")

Is there any difference or better way between them?

wildroco avatar May 15 '16 10:05 wildroco