Delete all syntax does not work in the java client

Posted by hherman1:

Currently the only way to issue deletes for triples like “uid * * .” is through the JSON syntax. If I try to use NQuads its first of all not clear whether I should be setting a target object id or string value, but either way it complains about using * as a target object id or target value. Or perhaps using it as a predicate was the problem. The exception is unclear.

gitlw commented :

@hherman1 Thanks for creating this issue. Can you please let me know which version of Dgraph you are using?

hherman1 commented :

@gitlw Sure! 1.0.16

gitlw commented :

@hherman1 It seems that the deletion in NQuads format works fine. Here is a simple example

  1. creating a simple schema
curl localhost:8180/alter -XPOST -d '
name: string @index(exact) .
friend: uid @reverse .
'
  1. Insert some data
curl 'localhost:8180/mutate' -H 'Content-Type:application/rdf' -H 'X-Dgraph-CommitNow: true' -XPOST -d '{
  set {
    _:alice <name> "Alice" .
    _:bob <name> "Bob" .
    _:alice <friend> _:bob .
  }
}'
  1. Query the data and verify that they have been successfully inserted
curl localhost:8180/query -XPOST -d '{
 run(func: eq(name, "Alice")) {
    uid
   name
    friend {
        uid
        name
    }
 }
}' | python -m json.tool

This will give a result like

{
    "data": {
        "run": [
            {
                "friend": [
                    {
                        "name": "Bob",
                        "uid": "0x2"
                    }
                ],
                "name": "Alice",
                "uid": "0x1"
            }
        ]
    },
    "extensions": {
        "server_latency": {
            "encoding_ns": 494108,
            "parsing_ns": 16501,
            "processing_ns": 407245183
        },
        "txn": {
            "start_ts": 4
        }
    }
}
  1. Now we can delete the node with uid 0x01 using deletion in NQuad format
 curl 'localhost:8180/mutate' -H 'X-Dgraph-CommitNow: true'  -H 'Content-Type:application/rdf' -XPOST -d '{
  delete {
    <0x01> * * .
  }
}'
  1. If we run the query above again, the node representing “Alice” will be gone.

Am I missing something? Thanks!

hherman1 commented :

Yes! I’m reporting this as a bug against the dgraph4j DSL not a bug with Dgraph itself. The problem is it appears you can’t specify the RDF deletion format from your step 4 in the DSL and actually execute it. Whether I tried specifying an objectId or a objectValue as * in both cases I got errors when trying to execute the query.

mangalaman93 commented :

@hherman1 We provide an API function Helpers.deleteEdges to delete predicates for a given uid (node). You could use that or do what it internally does, copying it here -

public static DgraphProto.Mutation deleteEdges(
      DgraphProto.Mutation mu, String uid, String... predicates) {
    DgraphProto.Mutation.Builder b = DgraphProto.Mutation.newBuilder(mu);
    for (String predicate : predicates) {
      b.addDel(
          DgraphProto.NQuad.newBuilder()
              .setSubject(uid)
              .setPredicate(predicate)
              .setObjectValue(DgraphProto.Value.newBuilder().setDefaultVal("_STAR_ALL").build())
              .build());
    }
    return b.build();
  }