0

Can we use apache Gremlin Domain Specific Language (DSL) for mutations (CREATE, UPDATE & DELETE)?

Gremlin Java DSL

@GremlinDsl(traversalSource = "com.sample.dsl.EmpTraversalSourceDsl")
public interface EmpTraversalDsl<S, E> extends GraphTraversal.Admin<S, E> {
    
    public default Vertex create(Employee employee) {
        return addV("employee");
    }

}

Every time, when I invoke this method, it creates double of what is there in the database.

Ex:

if there is, 2 employee then it become 4. 4 become 8 & so...

dan1st
  • 12,568
  • 8
  • 34
  • 67
Thirumal
  • 8,280
  • 11
  • 53
  • 103
  • It sounds like your code is doing the equivalent of `g.V().addV()` and not `g.addV()` – Kelvin Lawrence Jul 31 '22 at 17:23
  • Correct. `coalesce(__.V().hasId(id), __.addV("employee").property("O", "K"));` working fine. Any idea on how to do without `coalesce` in dsl? – Thirumal Aug 01 '22 at 00:36
  • If you're attempting to do a conditional write or upsert, you'll need to following this pattern: https://kelvinlawrence.net/book/Gremlin-Graph-Guide.html#upsert – Taylor Riggan Aug 01 '22 at 11:38
  • Want to use just `addV()`, without any condition. I guess, inside `DSL`, by default it starts with `g.V()`. that's why, it;s duplicating the insertion as mentioned by @KelvinLawrence – Thirumal Aug 02 '22 at 10:56
  • Are you able to share more of the code, especially where you use the DSL? – Kelvin Lawrence Aug 03 '22 at 12:19
  • I am referring this github project https://github.com/datastax/graph-examples/blob/master/killrvideo/dsl/java/src/main/java/com/killrvideo/KillrVideoTraversalDsl.java Line number : 250 or 274 – Thirumal Aug 04 '22 at 08:11

1 Answers1

0

The problem was I tried to create the vertex using the EmpTraversalSourceDsl, so the query ultimately looks like

g.V().hasLabel('employee').addV('employee').property(T.id, 'T12321321R'))

Resolved using coalesce

Thirumal
  • 8,280
  • 11
  • 53
  • 103