I have an issue with setting value to UID predicate with NQuads using dgraph4j 20.03.0
Caused by: io.grpc.StatusRuntimeException: UNKNOWN: Input for predicate "Sector.parent" of type uid is scalar. Edge: entity:368 attr:"Sector.parent" value_type:STRING
Code that sets this field looks like this:
addSetNQuad(mutation, subject, "Sector.parent", true, uids.get(parentId));
private void addSetNQuad(Mutation.Builder mutation, String subject, String predicate, boolean isUid, Object... values) {
for (var value : values) {
var value_ = Value.newBuilder();
if (value == null) {
continue;
} else if (isUid) {
value_.setUidVal(Long.parseUnsignedLong(((String) value).substring(2), 16));
}
...
mutation.addSet(NQuad.newBuilder()
.setSubject(subject)
.setPredicate(predicate)
.setObjectValue(value_.build())
.build());
}
}
It looks like this happens due to mismatch in ValTypes enum in api.proto
between dgraph4j (build.gradle
fetches dgo’s file) dgo/api.proto at master · dgraph-io/dgo · GitHub and pb.proto
used by dgraph itself dgraph/pb.proto at master · dgraph-io/dgraph · GitHub
I’ve also tried to add this mutation using JSON format:
if (uids.containsKey(parentId)) {
String json = "{\"uid\": \"" + subject + "\", \"Sector.parent\": {\"uid\": \"" + uids.get(parentId) + "\"}}";
mutation.setSetJson(ByteString.copyFromUtf8(json));
}
And it works fine like that, but it’s rather inconvenient (and wouldn’t allow me to add multiple references since json is replaced each time method is called)