Gremlin DSL's for non-host embedded languages.

131 views
Skip to first unread message

Marko Rodriguez

unread,
Jan 11, 2017, 12:42:47 PM1/11/17
to gremli...@googlegroups.com
Hi,

I just had an idea.

So, in Gremlin, you can build a custom DSL by defining your own TraversalSource and Traversals. For instance:

social = graph.traversal(SocialTraversalSource.class);
social.person(“marko”).knows(well).inGroup(“YMCA”)

Now, this works great for DSL’s that are embedded in the developer’s native language — i.e. monoids through fluent composition. However, lets say you want to have SPARQL support.  Well, there are two ways to do this where the second is “better,” but requires the first.

1. Develop a SPARQL parser that generates Gremlin bytecode and generate the GraphTraversal from the bytecode.
2. Create a SPARQLTraversalSource and SPARQLTraversal. 
- This is the new idea.

sparql = graph.traversal(SPARQLTraversalSource.class);
sparql.query(“SELECT ?x from ?x knows ?y”)

Now query(String) would parse the SPARQL statement and generate Gremlin bytecode (#1 above) and insert the bytecode into the SPARQLTraversal. With this model, the native language of the developer doesn’t need to parse SPARQL. You can have Jena (lets say) on the server side doing all the SPARQL->GremlinBytecode translation. Thus, in Gremlin-Python, the user would simply do:

sparql = graph.traversal(SparqlTraversalSource)
sparql.query(“SELECT ?x WHERE { ?x knows ?y }”)

Tada! Language agnostic SPARQL.

And best of all, if SPARQLTraversal extends GraphTraversal, you can then do:

sparql = graph.traversal(SparqlTraversalSource.class)
sparql.query(“SELECT ?x WHERE { ?x knows ?y }”).out(“wrote”).count()

Marko.

Stephen Mallette

unread,
Jan 11, 2017, 1:38:44 PM1/11/17
to Gremlin-users
We could demonstrate this idea in neo4j-gremlin with CypherTraversalSource.class, right?

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CB8650A5-2904-4134-99DE-81C8F918E135%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Marko Rodriguez

unread,
Jan 11, 2017, 1:55:44 PM1/11/17
to gremli...@googlegroups.com
Yes. I was going to add that, but decided not to complicate the email. So yes — we currently have Neo4j.cypher(), but we should make a CypherTraversalSource which extends GraphTraversal.

Marko.
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/CAA-H439643B9W75%2Bm83B19dNSYN27q_mW55FzTUWgF82GQ0wFA%40mail.gmail.com.

NAGARAJA UPADYAYA

unread,
Mar 17, 2017, 8:14:54 AM3/17/17
to Gremlin-users
Hi Marko,

Please share any references or samples for registering custom traversal or user defined step created in Groovy or Java.  Most of the posts related to DSL or user defined step refer to gremlin-console.  But I have a requirement to make user defined step or DSL written Groovy or Java, accessible from any where ie., from Orient DB Studio, Gremlin console or Java application which will send Gremlin query as string to Orient DB Server for executing the query and return the results.

Thank you in advance :)

Best Regards,
Nagaraj

Stephen Mallette

unread,
Mar 20, 2017, 8:05:29 AM3/20/17
to Gremlin-users
Whether you are in the console, your Java application or want your DSL in Gremlin Server, etc. the only thing you have to do is make your DSL jar file (and any related dependencies) available on the classpath of the application that needs to use it. That's the basic theory. Whether that theory fully applies to OrientDB Server is another question. I'm not familiar with it enough to say, but if you can initialize your TraversalSource in the method mentioned in this thread, I don't see why it wouldn't work.

--
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-users+unsubscribe@googlegroups.com.

NAGARAJA UPADYAYA

unread,
Mar 24, 2017, 2:39:22 AM3/24/17
to gremli...@googlegroups.com
Thank for the response Stephen :) 

It gives confidence that it is possible, Please confirm if it is enough to create Java or Groovy class with user defined steps, bundle it into a Jar and copy it into plugin's folder or any specific configuration required to make the DSL accessible in gremlin query ? If possible, please share any samples, references or links wrt any Gremlin server. 

Thank you in advance :)

Stephen Mallette

unread,
Mar 24, 2017, 7:01:34 AM3/24/17
to Gremlin-users
That's pretty much it. Make a jar and copy it to the path of the application. There's not much to share in the way of resources, because it's generally that simple. I again can't speak to what happens with OrientDB Server but with Gremlin Server you can use:

gremlin-server.sh -i

described here:


to help you auto-install jars/dependencies into Gremlin Server's path. But once the jar is there, all the public classes are available to the scripts you send to it.

Reply all
Reply to author
Forward
0 new messages