Question on macth step
I am wondering why the following queries return the different results:
gremlin> graph = TinkerFactory.createModern() gremlin> g=traversal().withEmbedded(graph) gremlin> g.V().match(.as("a").both().as("b").both().as("c")).count() ==>30 gremlin> g.V().match(.as("a").both().as("b").both().as("c"), __.as("a").both().as("b").both().as("c")).count() ==>48I must admit that I have not understood the "match" step, thus I am not sure whether it is a expected behavior or an issue. It would be highly appreaciated if somebody could help me investigate on
4 Replies
In cases like this the
match
step is not buying you much. For example, these two are equivalent:
To better see what is happening, perhaps replace the count
step with a path
step or add a .profile()
to the end of the query.
If you change the second query to not reuse all the same labels, it will perhaps make more sense.
Because (in your original second query) you are reusing the labels from the first line of the match
in the second line, Gremlin is trying to honor that pattern. Note that only the start and end labels on each line really affect the results. For example:
By profiling the query that yields 48 as the count, we can see what is happening.
Many thanks for your help! It looks like it is a little difference between Gremlin's pattern matching and Cypher's. So it seems that only the labels at the start and end will take effect permanently, right? 🥰
That's right. In general I don't use the
match
step in its current form. Earlier in Gremlin's evolution it supported queries that were harder to express in other gremlin steps. Over time, the where
step has become very flexible and things that needed a match
step can now be written other ways. For example, these two queries are equivalent
and
I find the where
form much simpler to work with.I get it! Many thanks for your help and examples provided that easy to understand!🥰
Actually I am trying to test GDBMS that adopt Gremlin as query language, especially for some functions of pattern matching. Your explanation about "match" clause and other ways to express the pattern matching undoubtedly help me a lot!