krlawrence / graph

Practical Gremlin - An Apache TinkerPop Tutorial
Apache License 2.0
830 stars 251 forks source link

Add example showing how `not(eq)` and `neq` can differ #253

Closed krlawrence closed 7 months ago

krlawrence commented 1 year ago

Two queries that look the same but are different

While helping someone with a Gremlin query this week, I was reminded that Gremlin semantics can be a little subtle at times. I used the example below to show a case where two queries at first may look like they will generate the same results but in fact do not. This would be a nice example to add somewhere in the text.

// Total node count
gremlin> g.V().count()
==>3747

// How many nodes have a city?
gremlin> g.V().has('city').count()
==>3502 

// The property must exist to be considered
gremlin> g.V().has('city',neq('I-do-not-exist')).count()
==>3502

// The property does not have to exist
gremlin> g.V().not(has('city',eq('I-do-not-exist'))).count()
==>3747