0

I have a graph in janusgrah that has two point,

order:id,channel,order_time  
shipments:id,channel,ship_time  

how can I realize sql like this using Gremlin grammar?

select channel,avg (ship_time - order_time)  from order join shipments 
using(id) group by channel 

I try to write as

g.V().has('Type', 
textContains('order').as('a').out('shipment').as('b').math('a'- 
'b').by('???').groupCount().by('channel')

and I don't know how to write the parameter in math().by("???") when the column name is different.

1 Answers1

1

You just use 2 by() modulators.

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().hasLabel('person').as('a').
           outE().as('b').
           math('a*b').
             by('age').
             by('weight')
==>11.600000000000001
==>14.5
==>29.0
==>32.0
==>12.8
==>7.0
Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34
  • thank you .now I meet another problem,order_time and ship_time are both String type.so it throws the exception as, " java.lang.String cannot be cast to java.lang.Number". how can I cast order_time and ship_time to int when using by('order_time').by('ship_time')? – chuanhua zhan Jul 24 '19 at 11:02
  • Casting can only be done using lambdas, which is one reason why you should store the properties as numbers in the first place. The other reason is, obviously, the performance impact. However, if it's just for a quick test, you can do `...by {Long.parseLong(it.value('order_time))}` (or whatever is needed to convert these strings into numbers, e.g. parse them as date and return the epoch seconds; it all depends on which format you're using). – Daniel Kuppitz Jul 24 '19 at 15:22