SQL-To-Gremlin?

396 views
Skip to first unread message

Marko Rodriguez

unread,
Jul 3, 2013, 2:26:24 PM7/3/13
to gremli...@googlegroups.com, aureliu...@googlegroups.com
Hi,

Over the years we have noted that many developers coming from relational database backgrounds are like "What the hell is this Gremlin stuff?" However, typically, once the mind shifts a bit, Gremlin becomes easy-peasy for most. In order to facilitate this transition from "what the hell?" to "easy breezy cover girl," Matthias had the nice idea of making an SQL-To-Gremlin website that shows an SQL query and then the corresponding Gremlin traversal. In a layout/manner similar to:


… this would be a campion page much like Stephen's http://gremlindocs.com .

Next, I would like to get Daniel Kuppitz contributing to this ogiven that he was originally an SQL guy and had the "what the hell?"-experience when seeing Gremlin originally. Interestingly enough, now he is one of Gremlin's most fluent users.

I was wondering people's thoughts on this so we can incorporate anything else people might want to see in such a site?

Thanks everyone,
Marko.

Pierre De Wilde

unread,
Jul 4, 2013, 12:01:57 PM7/4/13
to gremli...@googlegroups.com, aureliu...@googlegroups.com
Hi,

This is an excellent idea. Most (if not all) developers know SQL. Side-by-Side SQL-Gremlin statements may be one of the fastest way to learn Gremlin. Maybe it should also be included in the upcoming Gremlin book : http://www.tinkerpopbook.com/

Best,
Pierre

ecniv

unread,
Jul 5, 2013, 11:28:59 AM7/5/13
to gremli...@googlegroups.com, aureliu...@googlegroups.com
Great idea !! 


On Wednesday, July 3, 2013 8:26:24 PM UTC+2, Marko A. Rodriguez wrote:

daniel...@gmail.com

unread,
Jul 5, 2013, 9:27:51 PM7/5/13
to gremli...@googlegroups.com, gremli...@googlegroups.com, aureliu...@googlegroups.com
Agreed, also important is highlighting what gremlin can do that SQL can not

Sent from my iPhone
--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Marko Rodriguez

unread,
Jul 5, 2013, 9:59:38 PM7/5/13
to aureliu...@googlegroups.com, gremli...@googlegroups.com
Hey Daniel,

Check this out what Daniel Kuppitz did. This is Gremlin vs. SQL for a recommendation.

g.V('customerId','ALFKI').as('customer')
  .out('ordered').out('contains').out('is').as('products')
  .in('is').in('contains').in('ordered').except('customer')
  .out('ordered').out('contains').out('is').except('products')
  .groupCount().cap().orderMap(T.decr)[0..<5].productName

VS.

SELECT TOP (5) [t14].[ProductName]
  FROM (SELECT COUNT(*) AS [value],
               [t13].[ProductName]
          FROM [customers] AS [t0]
               CROSS APPLY (SELECT [t9].[ProductName]
                              FROM [orders] AS [t1]
                                   CROSS JOIN [order details] AS [t2]
                                   INNER JOIN [products] AS [t3]
                                           ON [t3].[ProductID] = [t2].[ProductID]
                                   CROSS JOIN [order details] AS [t4]
                                   INNER JOIN [orders] AS [t5]
                                           ON [t5].[OrderID] = [t4].[OrderID]
                                   LEFT OUTER JOIN [customers] AS [t6]
                                                ON [t6].[CustomerID] = [t5].[CustomerID]
                                   CROSS JOIN ([orders] AS [t7]
                                               CROSS JOIN [order details] AS [t8]
                                               INNER JOIN [products] AS [t9]
                                                       ON [t9].[ProductID] = [t8].[ProductID])
                             WHERE ( NOT ( EXISTS(SELECT NULL AS [EMPTY]
                                                    FROM [orders] AS [t10]
                                                         CROSS JOIN [order details] AS [t11]
                                                         INNER JOIN [products] AS [t12]
                                                                 ON [t12].[ProductID] = [t11].[ProductID]
                                                   WHERE ( [t9].[ProductID] = [t12].[ProductID] )
                                                         AND ( [t10].[CustomerID] = [t0].[CustomerID] )
                                                         AND ( [t11].[OrderID] = [t10].[OrderID] )) ) )
                                   AND ( NOT ( [t6].[CustomerID] = [t0].[CustomerID] ) )
                                   AND ( [t1].[CustomerID] = [t0].[CustomerID] )
                                   AND ( [t2].[OrderID] = [t1].[OrderID] )
                                   AND ( [t4].[ProductID] = [t3].[ProductID] )
                                   AND ( [t7].[CustomerID] = [t6].[CustomerID] )
                                   AND ( [t8].[OrderID] = [t7].[OrderID] )) AS [t13]
         WHERE [t0].[CustomerID] = N'ALFKI'
         GROUP BY [t13].[ProductName]) AS [t14]
 ORDER BY [t14].[value] DESC 

Marko.
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.

Daniel Quest

unread,
Jul 7, 2013, 10:41:45 PM7/7/13
to gremli...@googlegroups.com
Very cool!

Conciseness is one parameter, others that come to mind: capabilities of the language, ability to implement algorithms, speed, maintenance costs, ability to handle change, familiarity by developers, ability to conform to sound software engineering principles, overall project simplicity, ...

Gremlin is great on many of there counts.  Examples like this one are great because it allows developers to evaluate these parameters for themselves.  I have always found this page persuasive: https://github.com/tinkerpop/gremlin/wiki/SPARQL-vs.-Gremlin

And this

One thing I would like to know is why did you, Marko, design Gremlin rather than going with a more traditional approach like that taken by cypher or sparql?  I think developers would find information like that helpful when deciding if they are going to learn it.

Dan

Sent from my iPad

On Jul 5, 2013, at 8:59 PM, Marko Rodriguez <okram...@gmail.com> wrote:

Hey Daniel,

Check this out what Daniel Kuppitz did. This is Gremlin vs. SQL for a recommendation.

g.V('customerId','ALFKI').as('customer')
  .out('ordered').out('contains').out('is').as('products')
  .in('is').in('contains').in('ordered').except('customer')
  .out('ordered').out('contains').out('is').except('product
  .groupCount().cap().orderMap(T.decr)[0..<5].productName

Marko Rodriguez

unread,
Jul 8, 2013, 5:07:14 PM7/8/13
to gremli...@googlegroups.com
Yo Johnny Quest,

Conciseness is one parameter, others that come to mind: capabilities of the language, ability to implement algorithms, speed, maintenance costs, ability to handle change, familiarity by developers, ability to conform to sound software engineering principles, overall project simplicity, ...

Gremlin is great on many of there counts.  Examples like this one are great because it allows developers to evaluate these parameters for themselves.  I have always found this page persuasive: https://github.com/tinkerpop/gremlin/wiki/SPARQL-vs.-Gremlin

Nice.

One thing I would like to know is why did you, Marko, design Gremlin rather than going with a more traditional approach like that taken by cypher or sparql?  I think developers would find information like that helpful when deciding if they are going to learn it.

I did not come from an SQL background, but from a graph theory/network science background. SQL is not a "graph language" in the slightest. The reason being is the ability to arbitrarily union any two relations via an equijoin in SQL. In a graph, the join is already explicit and thus, concepts such as JOIN are not needed. Next, Derrick Wiebe of Pacer said to Pavel and I long ago: "Why build your own language compiler? Its called meta-programming in dynamic languages. Look it up retard." From there, Gremlin/Groovy. No ANTLR needed -- no need for test cases like "Does 1+2 really equal 3?" I remember early on, Pavel and I had a bug in our for-loop. So lame and pointless… Why create from scratch when you can build on the smarts of others. Gremlin provides sophisticated graph traversals with a minimal code base and we can focus on things like query optimization as opposed to language parsing. Moreover, and best of all, I don't need to write a "sum(int, int)"-type functions --- Java provides that. With Gremlin/Groovy the full Java API is at your fingertips. Imagine writing date tools, math operations, for-loops, etc. etc… a complete waste of effort.

Finally, we have taken this philosophy to heart in Aurelius. When I met Matthias and he explained how Titan worked over Cassandra, I was like "exactly." Imagine writing your own gossip protocol? Imagine writing your own B-Tree? Imagine writing your own HA system? Imagine writing your own geo search, text search? Imagine writing you own elastic scalability engine? Imagine writing your own……….its endless how complex distributed systems get…………. its I-N-S-A-N-E. Apache2 has opened up software such that any one can create the next generation technology without needing venture funding, a large developer pool, so on… 

The future is yours Johnny,
Marko.





Daniel Kuppitz

unread,
Jul 11, 2013, 4:07:28 PM7/11/13
to gremli...@googlegroups.com, aureliu...@googlegroups.com

Feel free to spam the issue tracker with ideas for uncovered SQL query patterns.

Cheers,
Daniel

Bryn Cooke

unread,
Jul 11, 2013, 5:13:43 PM7/11/13
to gremli...@googlegroups.com, aureliu...@googlegroups.com
This is a really great page. Now I can point SQL developers to this instead of trying to explain things myself.

Cheers,

Bryn

Mike Bryant

unread,
Jul 11, 2013, 6:21:48 PM7/11/13
to gremli...@googlegroups.com, aureliu...@googlegroups.com
Wow, fantastic reference! I for one will definitely refer to this in future.  In particular, it really shows of Gremlin's strengths where it comes to hierarchical and/or recursive queries (which is a big use-case for us.)

Just an idea: perhaps it would be possible to include the equivalent Java code for the certain operations where appropriate? I think that would help de-mystify some of the Gremlin/Groovy magic and show people what actually happens under the hood, as well as providing a really useful source of information for people like, say, me, who've struggled with Groovy-to-Java conversions on occasion.

Excellent work folks,
~Mike

On Thursday, 11 July 2013 21:07:28 UTC+1, Daniel Kuppitz wrote:

Pierre De Wilde

unread,
Jul 12, 2013, 3:36:43 AM7/12/13
to gremli...@googlegroups.com, aureliu...@googlegroups.com
Hi,

This great doc work from Daniel perfectly complements the excellent doc work from Stephen (http://gremlindocs.com). Thanks, guys.

Part of my mind was focused on the colors used in the wonderful Ketrina's logo: http://sql2gremlin.com/assets/sql2gremlin.png

SQL is turquoise (blue-green) and Gremlin is green. 
So, Gremlin is made by removing SQL blues.

Careful observers may objected that the distilled Gremlin color is purple, not green. It's a desperate attempt of SQL to stop Gremlin. But it can't. When the lights will change from red to green, blues will disappear.

Thanks, Ketrina. You really enjoy my day.

Pierre



--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/xndHcjfhxP8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages