Over the years of working with Gremlin I have foudn the match() step is
difficult to create traversals with and even more difficult to make it work
efficently.  While the imperative style of programming in Gremlin provides
a powerful path finding mechanism it really lacks an easy way to perform
pattern matching queries.  It would be great if we could simplify the
match() step to enable users to easily generate these pattern matching
traversals.

To accomplish this I was wondering what adding support for a subset of
motif/ascii art patterns to the match step might look like.  These types of
patterns are very easy for people to understand and I think the ability to
combine these pattern matching syntax with the powerful path finding and
formatting features of Gremlin would make a powerful combination.

To accomplish this I am suggesting supporting a subset of potential
patterns.  The two most common examples of this sort of pattern out there
are the openCypher type style and the style used by GraphX.  I have
provided a few examples below of what this syntax might look like:

e.g. openCypher style

Find me everything within one hop
g.V().match("()-[]->()")

Find me everything within one hop of a Person vertex
g.V().match("(p:Person)-[]->()")

Find me all Companies within one hop of a Person vertex
g.V().match("(p:Person)-[]->(c:Company)")

Find me all Companies within one hop of a Person vertex with an Employed_at
edge
g.V().match("(p:Person)-[e:employed_at]->(c:Company)")


The other option would be to take more of a hybrid approach and use only
the basic art/motifs like GraphX and apply the additional filtering in a
hybrid type of mode like this:

Find me all Companies within one hop of a Person vertex with an Employed_at
edge
g.V().match("(p)-[e]->(c)",
__.as('p').hasLabel('Person'),
__.as('e').hasLabel('employed_at'),
__.as('c').hasLabel('Company'),
)

This also has the potential to enable some significantly more complex
patterns like "Find me all Companies within one hop of a Person vertex with
an Employed_at edge who also worked at Foo"
g.V().match("(p)-[e]->(c)",
__.as('p').hasLabel('Person').out('employed_at').has('Company', 'name',
'Foo'),
__.as('e').hasLabel('employed_at'),
__.as('c').hasLabel('Company'),
)

Thoughts?

Dave

Reply via email to