Home > Enterprise >  Java Gremlin union with project incompatible types error
Java Gremlin union with project incompatible types error

Time:05-17

I have such gremlin query which perfectly works in gremlin console:

g.V().has("Role", "id", "billing-admin").union(
    __.valueMap().by(__.unfold()),
    __.project("app").by(__.out("FOR").valueMap().by(__.unfold()))
);

However same query fails in gremlin for java org.apache.tinkerpop:gremlin-core with such error: Incompatible equality constraint: Map<String, Object> and Map<Object, Object>.

That is understandable because:

  • valueMap returns GraphTraversal<Element, Map<Object, Object>>
  • project returns GraphTraversal<Object, Map<String, Object>>
  • union expects traversals to operate over same type

Is there any built-in solution for this?

What I have for now is this but it doesn't look attractive:

g.V().has("Role", "id", "billing-admin").union(
    __.valueMap().by(__.unfold()),
    __.project("app").map(t -> Collections.<Object, Object>unmodifiableMap(t.get())).by(__.out("FOR").valueMap().by(__.unfold()))
);

CodePudding user response:

I'm not sure what kind of solution you're looking for but you don't need a lambda to solve this. You could just cast the second traversal:

g.V().has("Role", "id", "billing-admin").union(
        __.valueMap().by(__.unfold()),
        (GraphTraversal) __.project("app").by(__.out("FOR").valueMap().by(__.unfold()))
);
  • Related