Hi,

Matt Frantz had this idea the other day:
        https://issues.apache.org/jira/browse/TINKERPOP3-652

I was anti it at first cause then match() looks like this:

        g.V.match(…).select(local,'a','b')

Gross… However, it makes sense as select() was too overloaded with both global 
analysis (Path) and local analysis (Map<String,Object>). To rectify the 
ugliness of select(local,'a','b'), I made an interface called Scoping which 
allows a step to recommend a Scope. Thus, MatchStep's recommend scope is 
Scope.local. There is a ScopingStrategy that then uses scope recommendations.

        
https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/ScopingStrategy.java

So, now we are back to:

        g.V.match(…).select('a','b')

So thats good. However, check out what you can do now that both select() and 
where() can be scoped.

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> // no except() needed any more! thats huge. i have always hated 
except/retain and now they can go away.
gremlin> 
g.V(1).as('a').out('created').in('created').as('b').where('a',neq('b')).values('name')
==>josh
==>peter
gremlin> 
g.V(1).as('a').out('created').in('created').as('b').where('a',neq('b')).select().by('name')
==>[a:marko, b:josh]
==>[a:marko, b:peter]
gremlin> 
g.V(1).as('a').out('created').in('created').as('b').select().by('name').where('a',neq('b'))
==>[a:marko, b:josh]
==>[a:marko, b:peter]

…where() can operate on current object Maps or it can operate on global Paths 
(similar to select()). The last two examples are crazy cause of ScopeStrategy. 
Check the toString():

gremlin> 
g.V(1).as('a').out('created').in('created').as('b').where('a',neq('b')).select().by('name').iterate().toString()
==>[TinkerGraphStep([1],vertex)@[a], VertexStep(OUT,[created],vertex), 
VertexStep(IN,[created],vertex)@[b], WhereStep(global,a,neq,b), 
SelectStep(global,[value(name)])]
gremlin> 
g.V(1).as('a').out('created').in('created').as('b').select().by('name').where('a',neq('b')).iterate().toString()
==>[TinkerGraphStep([1],vertex)@[a], VertexStep(OUT,[created],vertex), 
VertexStep(IN,[created],vertex)@[b], SelectStep(global,[value(name)]), 
WhereStep(local,a,neq,b)]

Notice in the second example how the WhereStep uses local. Why? Cause 
SelectStep projects down to a Map. No need to do double path analysis. Neato.

Enjoy,
Marko.

http://markorodriguez.com

Reply via email to