Upsert with val() not working

This approach will not work because val(CLASS_1_LABEL) is evaluated from a map and using the uid(NODE_1): there is no value associated with the uid for CLASS_1_LABEL.

If I understand correctly you are looking for children of a give nodes that have a relation to a class and want to set the value predicate of those node to the label of the class.

I would do something like this in the query

var(func:uid($0)) @cascade {
   # parent node
   ~parents {
     # child node
      class @filter(eq(slud,$1))  {
         CLASS_LABEL as label
       }
   # aggregate the class label at the node level
   NODE_LABEL as max(val(CLASS_LABEL))
   }
}

# now use uid(NODE_LABEL) and val(NODE_LABEL) for the mutation.

Thinking in terms of graph is not an easy task and there are usually different ways to see the same problem. @cascade is an interesting feature to do “graph pattern matching”. Then var is a good way to extract some node in the path. The aggregation (max in this case) is a way to aggregate (propagate) some values to the upper level in the path.

In this approach @cascade is used to query only the node that can reach the class.
The max(val()) is used to ‘propagate’ the value at the level of the node ( a node has only one class so the max is the val but we need an aggregation function).
Now your NODE_LABEL is a correct map between the node uid and the value of the label you need.
I’m also using ~parents: you may have to index your predicate to use the reverse edge!

Can’t test the query without your data, but I hope it gives you enough insight to make it work. Let me know.

1 Like