Search code examples
gremlinamazon-neptune

Gremlin: Rollback the query if an exception occurs


I am trying to submit a batch like operation for creating multiple vertices and edges in the same query.

g.addV('os').property('name', 'linux').as('linux').
  addV('os').property('name', 'windows').as('windows').
  addV('os').property('name', 'mac').as('mac').
  addE('competitor').from('linux').to('UNEXISTING OS').      # fail here
  addE('competitor').from('linux').to('windows').
  addE('competitor').from('windows').to('mac').
  addE('competitor').from('linux').to('mac').
  iterate()

The query is constructed to intentionally fail, however all vertices before the failing line are being created.
Is it possible to achieve a kind of transaction for the whole query? So that if one subquery fails, it should rollback the ones that were previously executed.

Thanks!


Solution

  • The query could not be executed in the Gremlin Console using TinkerGraph, as per TinkerPop documentation, there isn't support for transactions for built-in TinkerGraph object.

    But, as cygri pointed out, AWS Neptune offers support for transactions (see here), that can be executed under the form of original query from OP or by separating queries by a semicolon (;) or a newline character (\n)

    g.addV('os').property('name', 'linux').next();
    g.addV('os').property('name', 'windows').next();
    g.addE('competitor').from('1101').to('1102')