Given a set of nodes, I’d like to find the UID of the node with the maximum value in the set for a certain predicate. Is this possible?
For example, given the following nodes:
<0x1> <score> "1".
<0x2> <score> "2".
<0x3> <score> "3".
How would I return <0x3> (it’s got the highest score)?
Something like this
{
var(func: has(score)) {
S as score
}
var() {
M as max(val(S))
}
me(func: uid(M)) {
uid
score
}
}
Running into a problem—when I add the data exactly as above, and run the query, I get this error:
Message: : while reading posting list with key [[0 0 5 115 99 111 114 101 0 0 0 0 0 0 0 0 0]]: Invalid UID with value 0 for key: [0 0 5 115 99 111 114 101 0 0 0 0 0 0 0 0 0]
It seems like uid(M)
returns 0x0
.
I’m using version v20.11.3
MichelDiz
(Michel Diz)
May 27, 2021, 1:13pm
6
This is not a error. What else do you see? and what are the steps to reproduce? Even if it returns 0x0
would never return an error. As it is a valid UID.