Adam Dyga
Adam Dyga

Reputation: 8926

How should hasNot() work in Gremlin?

If a given vertex doesn't have a particular property, what should be the result of g.V.hasNot('non-existent-property', 'value') query? Should the vertex be emitted by such query?

I get contradictory results when using TinkerPop and Titan's in-memory graph:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.V.hasNot("abcd", true)
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]

The above is fine to me - the vertices do not have the specified property (set to true) so all are returned. But if I do sth similar in Titan's in-memory graph:

gremlin> g2 = TitanFactory.open(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.buildConfiguration().set(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND, "inmemory"))
==>titangraph[inmemory:[127.0.0.1]]
gremlin> g2.addVertex(null)
==>v[256]
gremlin> g2.V.hasNot("abcd", true)

it returns no result. Which one is right?

Upvotes: 3

Views: 5882

Answers (2)

Steffi Keran Rani J
Steffi Keran Rani J

Reputation: 4113

A solution that worked for me in this scenario :

g2.V.not(has("abcd", true))

Upvotes: 0

stephen mallette
stephen mallette

Reputation: 46226

Just to close the loop on this here in SO - a GitHub issue has been created for this problem (TinkerGraph does show the correct behavior):

https://github.com/thinkaurelius/titan/issues/868

Please follow the resolution there.

Upvotes: 5

Related Questions