0
votes

Consider the following schema for in JanusGraph.

g.addV('node1').next()
g.addV('node2').next()
g.addV('node3').next()

g.V().hasLabel('node1').as('fromV').V().hasLabel('node2').as('toV').addE('rel').from('fromV').to('toV').property('property1',1).iterate()

g.V().hasLabel('node1').as('fromV').V().hasLabel('node3').as('toV').addE('rel1').from('fromV').to('toV').property('property2',2).iterate()

3 nodes: node1,node2 and node3 2 relations: node1->rel->node2 and node1->rel1->node3

I want the property2 for the rel1 relationship to be dependent on the property1 of rel relationship with formula 2*property1. Example: If property1=4 then property2=2 * 4=8

Is it possible to update the property2 automatically when the property1 is updated and how? If not possible automatically, how to update using queries?

1

1 Answers

0
votes

You would have to build that functionality yourself as part of your application as there is nothing in TinkerPop or JanusGraph that allows you to specify such a rule. There are things that might help you build such functionality though:

  • EventStrategy - you could try to listen for mutation events on edge properties and then trigger your change.
  • JanusGraph Transaction Log - perhaps you could listen to JanusGraph's transaction log directly and then trigger your change.
  • Gremlin DSLs - maybe you could build your logic into custom DSL steps so that when you note calls to property('property1', <value>) you could inject additional Gremlin steps to update the other edge property.
  • If you don't need the data in real-time you could obviously use batch jobs to update the property2 value. If you have a really large graph then you will want to look into using something like Spark to execute such a job in parallel.