JanusGraph / janusgraph

JanusGraph: an open-source, distributed graph database

Home Page:https://janusgraph.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error about a complex gremlin query

ljhhuxiaoba opened this issue · comments

I execute a query on my empty JanusGraph database ,and an error occurs.

JanusGraph version: 1.0.0
operating system: windows 10

query:
g.inject(' cypher.start').union(.V().as('n0').barrier().sideEffect(.select('n0').aggregate(' cypher.delete.detach')).sideEffect(.limit(0).aggregate(' cypher.delete.once')).barrier().sideEffect(.coalesce(.cap(' cypher.delete.once').unfold(), .constant(true).aggregate(' cypher.delete.once').cap(' cypher.delete.detach').unfold().dedup().is(neq(' cypher.null')).drop().cap(' cypher.delete').unfold().dedup().is(neq(' cypher.null')).sideEffect(.bothE().path().from('Cannot delete node, because it still has relationships. To delete this node, you must first delete its relationships.')).drop())).project('a1').by(.constant(1)), .choose(.V().as('n1').has('id', eq(1)), .V().as('n1').has('id', eq(1)), .identity().addV().as('n1').property(single, 'id', 1)).barrier().sideEffect(.select('n1').aggregate(' cypher.delete.detach')).sideEffect(.limit(0).aggregate(' cypher.delete.once')).barrier().sideEffect(.coalesce(.cap(' cypher.delete.once').unfold(), .constant(true).aggregate(' cypher.delete.once').cap(' cypher.delete.detach').unfold().dedup().is(neq(' cypher.null')).drop().cap(' cypher.delete').unfold().dedup().is(neq(' cypher.null')).sideEffect(.bothE().path().from('Cannot delete node, because it still has relationships. To delete this node, you must first delete its relationships.')).drop())).project('a1').by(__.constant(1))).dedup()

error messgae:
The side-effect key does not exist in the side-effects: cypher.delete

But I think this gremlin query is semantically correct and should be executed correctly.

Indented this traversal looks like this:

g.inject(' cypher.start').
  union(
    V().as('n0').
    barrier().
    sideEffect(select('n0').aggregate(' cypher.delete.detach')).
    sideEffect(limit(0).aggregate(' cypher.delete.once')).
    barrier().
    sideEffect(
      coalesce(
        cap(' cypher.delete.once').unfold(),
        constant(true).
        aggregate(' cypher.delete.once').
        cap(' cypher.delete.detach').
        unfold().
        dedup().
        is(neq(' cypher.null')).
        drop().
        cap(' cypher.delete').
        unfold().
        dedup().
        is(neq(' cypher.null')).
        sideEffect(
          bothE().
          path().
            from(
              'Cannot delete node, because it still has relationships. To delete this node, you must first delete its relationships.')).
        drop())).
    project('a1').by(constant(1)),
    choose(
      V().as('n1').has('id', eq(1)),
      V().as('n1').has('id', eq(1)),
      identity().addV().as('n1').property(single, 'id', 1)).
    barrier().
    sideEffect(select('n1').aggregate(' cypher.delete.detach')).
    sideEffect(limit(0).aggregate(' cypher.delete.once')).
    barrier().
    sideEffect(
      coalesce(
        cap(' cypher.delete.once').unfold(),
        constant(true).
        aggregate(' cypher.delete.once').
        cap(' cypher.delete.detach').
        unfold().
        dedup().
        is(neq(' cypher.null')).
        drop().
        cap(' cypher.delete').
        unfold().
        dedup().
        is(neq(' cypher.null')).
        sideEffect(
          bothE().
          path().
            from(
              'Cannot delete node, because it still has relationships. To delete this node, you must first delete its relationships.')).
        drop())).
    project('a1').by(__.constant(1))).
  dedup()

The error you are getting suggests that the traversal is trying to access a side-effect which isn't present. The side effect key is cypher.delete. This is used in the traversal only in a cap() step which explains why you are getting the error since cap() only emits the sideEffect referenced by the provided key and that key isn't found.

So, again, the issue isn't about a bug in JanusGraph but in the Gremlin traversal created by the Cypher plugin.