I am using a graph database for my project, Neptune by AWS. Neptune uses gremlin syntax for graph queries. I was trying to execute a scenario where I have to filter the outgoing edges from a vertex on the basis of property on the edge. Let's call that property 'x'. The value of this property 'x' is of the form 'abc::xyz::ref'. This is to store multiple values on the edge, as Neptune does not allow multi values on edges. I have to do a contains check with three combinations and an exact match :-
- 'abc::'
- '::abc'
- '::abc::'
- Exact match with 'abc'
I was trying to use filter command in the gremlin in my java code. The below code works fine with TinkerGraph in-memory, but when I connect it with Neptune and run the same query it throws some parsing exception.
String valueToCheck = "abc";
List<String> listOfValuesToCheck = new ArrayList<>();
listOfValuesToCheck.add("::abc");
listOfValuesToCheck.add("abc::");
listOfValuesToCheck.add("::abc::");
GraphTraversal<Vertex, Map<Object, Object>> gt24 = g.V().outE().has("x").filter(it -> {
String value = String.valueOf(it.get().value("x"));
if(value.equals(valueToCheck)){
return true;
}else {
for(String s: listOfValuesToCheck){
if(value.contains(s){
return true;
}
}
}
}).valueMap().with(WithOptions.tokens);
while (gt24.hasNext()) {
System.out.println(gt24.next());
}
Does someone know, why this is happening with Neptune? And is there a better way to do it that works with Neptune.
I have seen one more instance where Neptune did not throw an error but also gave back no results but the same work with TinkerGraph.
y - property on Edge
z - property on Vertex
GraphTraversal<Vertex, Map<String, Object>> gt13 = g.V(1, 2).project("id", "summary").by(T.id)
.by(__.outE().has("y", "e").inV().group().by("z"));