问题
I'm writing gremlin query with 'match()' traversal. It seems some pattern matching behaves differently than other pattern languages.
- How input traverser values are bound by pattern variables.
g.V('A', 'B').match(__.as('x'), __.as('y')).project('x', 'y')
==>[x:v[A],y:v[A]]
==>[x:v[B],y:v[B]]
I think pattern variable x
and y
have no constraints and result will be
==>[x:v[A],y:v[A]]
==>[x:v[A],y:v[B]]
==>[x:v[B],y:v[A]]
==>[x:v[B],y:v[B]]
It seems a constraint x = y
is added implicitly.
- When pattern variables are bound to values not listed in input traverser.
Sometimes, pattern variable are bound to values not listed in input:
g.V('A', 'B').match(__.as('x').out().as('y'), __.as('y'))
==>[x:v[A],y:v[B]]
==>[x:v[B],y:v[C]]
==>[x:v[B],y:v[D]]
In this query, we have more constraints than previous query. So, less results are expected, but results increase by capturing vertices not in input traversers.
Is there a clear documentation when pattern variables can capture such vertices.
- "The provided match pattern is unsolvable"
Similar query:
g.V('A', 'B').match(__.as('x').out().as('y'), __.as('z'))
The provided match pattern is unsolvable: [[MatchStartStep(z), MatchEndStep], [MatchStartStep(x), VertexStep(OUT,vertex), MatchEndStep(y)]]
Type ':help' or ':h' for help.
Display stack trace? [yN]y
java.lang.IllegalStateException: The provided match pattern is unsolvable: [[MatchStartStep(z), MatchEndStep], [MatchStartStep(x), VertexStep(OUT,vertex), MatchEndStep(y)]]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep$MatchAlgorithm.lambda$static$0(MatchStep.java:690)
at org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep$CountMatchAlgorithm.apply(MatchStep.java:757)
at org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep$CountMatchAlgorithm.apply(MatchStep.java:723)
at org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep.standardAlgorithm(MatchStep.java:398)
This has less constraints than previous one. What this error means.
来源:https://stackoverflow.com/questions/55609832/is-there-a-document-about-how-gremlin-match-works