I'd like to perform specific queries on my Titan/ES setup, and that would mean defining my own methods in the groovy console.
My question is thus : how would I go about implementing my own steps ?
Do I need to fork everything, or maybe extend class GraphTraversal ? I'm not sure where to start.
Any advice ?
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/d2b31f3d-bf9f-4475-9fd6-573b2b81350c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
But I would need these custom steps to be fully implemented and not just available through the console.
I'm using gremlin-server and performing remote requests, for example.
I've had a look at the code and it appears I could extend some of the dsl.graph classes, but it seems there are some private methods and attributes that will make the job quite difficult...
As I said, I'm not sure what's the best way to do this. I figured you might have an idea...
Thanks for any suggestions.
DefaultGraphTraversal.metaClass.myStep = {a,b,c,d -> return delegate.addStep(new MyStep(delegate, a, b, c, d));}
gremlin> g = TinkerFactory.createModern().traversal()==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]gremlin> import org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectStepgremlin> DefaultGraphTraversal.metaClass.myStep = { a,b ->gremlin> return delegate.addStep(new SelectStep(delegate,Pop.all,a,b))gremlin> }==>groovysh_evaluate$_run_closure1@2472c7d8gremlin>gremlin>gremlin> g.V().myStep("a","b").toString()==>[GraphStep(vertex,[]), SelectStep(all,[a, b])]gremlin>
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/0dfede41-c64c-4283-a8e7-dfa46e4f1d7d%40googlegroups.com.
gremlin> g = TinkerFactory.createModern().traversal()==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> myStep1 = {it.get().value('name').length() > 4}==>groovysh_evaluate$_run_closure1@18ca3c62gremlin> myStep2 = {(25..it.get().value('age')).iterator()}==>groovysh_evaluate$_run_closure1@5c09d180gremlin>gremlin>gremlin> g.V().hasLabel('person').filter(myStep1).values('name')==>marko==>vadas==>petergremlin> g.V().hasLabel('person').flatMap(myStep2)==>25==>26==>27==>28==>29==>25==>26==>27==>25==>26==>27==>28==>29==>30==>31==>32==>25==>26==>27==>28==>29==>30==>31==>32==>33==>34==>35gremlin>
On Jun 27, 2016, at 3:10 PM, ern...@rocketjourney.com wrote:
Hi Marko, just one question. What class from what package do I have to extend to implement a step? are there any examples? tinkerpop3 I stopped following the project at version 2, I really liked Gremlin.defineStep... Would be cool if you point us on the right direction, I spent my weekend doing some TDD with tinkerpop3.
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/88cc994d-4351-4a13-8607-5bc006f1a4f9%40googlegroups.com.
gremlin> GraphTraversalSource.metaClass.findOrCreate = { id, key, value ->gremlin> return delegate.V(id).hasNext() ? delegate.V(id) : delegate.addV('person').property(T.id,id).property(key,value)gremlin> }==>groovysh_evaluate$_run_closure1@4a8a60bcgremlin>gremlin> DefaultGraphTraversal.metaClass.teams = {gremlin> return delegate.out('created').values('name')gremlin> }==>groovysh_evaluate$_run_closure1@7bb3a9fegremlin>
gremlin> g = TinkerFactory.createModern().traversal()==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]gremlin>
gremlin> g.findOrCreate(1,'gender','male').teams()==>lopgremlin> g.findOrCreate(45,'gender','male').teams()gremlin> g.V(45)==>v[45]gremlin> g.V(45).valueMap()==>[gender:[male]]gremlin>
g = graph.traversal(FacebookTraversalSource.class)g.findOrCrete(…).teams()
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/5723ca3b-0afb-4d94-bc87-d7eeb7c1f9bb%40googlegroups.com.
I'll definitely give meta-programing a go, at least as a temporary solution.
But I'm also interested in some examples of files implementing TraversalSource, to make my steps fully implemented.
I think that's what the other person meant as well.
That way, I wouldn't have to copy all the code and update my class everytime a new version of gremlin is released.
The problem is that the constructor and other important methods are "private"... Any chance you might change these to "protected" in the next version ?
Also, I might not have been very clear: I don't really want to implement "TraversalSource", I'd much rather extend "GraphTraversalSource”.
public class MyTraversal<S,E> implements Traversal.Admin<S,E> {private GraphTraversal.Admin<S,E > rawTraversal;public MyTraversal<S,Vertex> find(Map<String,Object> properties) {rawTraversal.V();for(Entry entry : properties) {rawTraversal.has(entry.key(), entry.value())}return this;}public MyTraversal<S,Vertex> friends(float minStars) {rawTraversal.outE(“knows”).has(“stars”,gt(minStars));return this;}public E next() {return this.rawTraversal.next();}...}
static interface Admin <S, E> extends org.apache.tinkerpop.gremlin.process.traversal.Traversal<S,E> {
default void addStarts(java.util.Iterator<org.apache.tinkerpop.gremlin.process.traversal.Traverser.Admin<S>> starts) { /* compiled code */ }
default void addStart(org.apache.tinkerpop.gremlin.process.traversal.Traverser.Admin<S> start) { /* compiled code */ }
java.util.List<org.apache.tinkerpop.gremlin.process.traversal.Step> getSteps();
default <E2> org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<S,E2> addStep(org.apache.tinkerpop.gremlin.process.traversal.Step<?,E2> step) throws java.lang.IllegalStateException { /* compiled code */ }
<S2, E2> org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<S2,E2> addStep(int i, org.apache.tinkerpop.gremlin.process.traversal.Step<?,?> step) throws java.lang.IllegalStateException;
default <S2, E2> org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<S2,E2> removeStep(org.apache.tinkerpop.gremlin.process.traversal.Step<?,?> step) throws java.lang.IllegalStateException { /* compiled code */ }
<S2, E2> org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<S2,E2> removeStep(int i) throws java.lang.IllegalStateException;
default org.apache.tinkerpop.gremlin.process.traversal.Step<S,?> getStartStep() { /* compiled code */ }
default org.apache.tinkerpop.gremlin.process.traversal.Step<?,E> getEndStep() { /* compiled code */ }
void applyStrategies() throws java.lang.IllegalStateException;
org.apache.tinkerpop.gremlin.process.traversal.TraverserGenerator getTraverserGenerator();
java.util.Set<org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement> getTraverserRequirements();
default void reset() { /* compiled code */ }
void setSideEffects(org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects traversalSideEffects);
org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects getSideEffects();
void setStrategies(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies traversalStrategies);
org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies getStrategies();
void setParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent traversalParent);
org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent getParent();
org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<S,E> clone();
boolean isLocked();
java.util.Optional<org.apache.tinkerpop.gremlin.structure.Graph> getGraph();
void setGraph(org.apache.tinkerpop.gremlin.structure.Graph graph);
default boolean equals(org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<S,E> other) { /* compiled code */ }
}
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/89272f26-3b1b-4248-882f-0f3d40222aae%40googlegroups.com.
I feel like it would be easier if some of the classes could be extended. I only need to route a step or two for specific index queries.
I don't really want to reimplement the whole dsl. I'd rather rely on the original clean Tinkerpop3 classes and methods, as much as possible.
I'll try to make it work with your example.
@TraversalDSL
public interface SocialDSL<S,E> extends GraphTraversal<S,E> {
/* Use this if you need an anonymous instance of this traversal DSL; can't just use __ because it doesn't exist yet */
public default <A> SocialDSL<A, A> __();
public default GraphTraversal<S, Vertex> know(final String personName) {
return out("knows").hasLabel("person").has("name", personName);
}
/* ... */
}
public interface SocialTraversal<S, E> extends SocialDSL<S,E> {
@Deprecated
public default <A> SocialDSL<A, A> __() { return __.start(); }
public SocialTraversal<S, Vertex> know(final String personName) {
return (SocialTraversal<S, Vertex>)SocialTraversal.super.know(personName);
}
/* ... */
public SocialTraversal<S, Vertex> out(final String... edgeLabels) {
return (SocialTraversal<S, Vertex>)GraphTraversal.super.out(edgeLabels);
}
/* ... */
}
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/1fd6295d-8088-4b9e-a657-ad7cc17fcc5d%40googlegroups.com.