I have a query question. I’m trying to run a query using an aggregation of uids uid(a, b, c...)
and figure out a way of returning only if each set in the aggregation (a
, b
, c
, etc.) is non-empty.
This is basically do an all-or-nothing query on uid aggregation. Is this possible? I’m having a hard time figuring out how it could be done.
I’ve tried exploring sum()
and count()
to achieve this because I know the expected size of the total uid set, but I’m running into several errors.
{
var(func: has(a), first: 1) {
a_count as count(foo)
}
var(func: has(b), first: 10) {
b_count as count(foo)
}
# The below is a hack because you can't do "c as count(uid)" in the above
var() {
b_sum as sum(val(b_count))
a_sum as sum(val(a_count))
}
var() {
total_sum as math(a_sum + b_sum)
}
c(func: eq(val(total_sum), 11)) {
# Running the expand below produces "Wrong variable type encountered for var(total_sum) 3."
expand(val(total_sum))
}
}
The above is my current tinkering, but even something like this has its own errors:
{
a as var(func: has(a), first: 1) { }
b as var(func: has(b), first: 10) { }
c(func: eq(count(val(a), val(b)), 11)) {
_predicate_
}
}
That returns Multiple functions as arguments not allowed
I’ve also tried using the @groupby
directive:
{
a as var(func: has(a), first: 1) { }
b as var(func: has(b), first: 10) { }
var(func: uid(a, b)) @groupby(type) {
c as count(uid)
}
d(func: eq(val(c), 11)) {
_predicate_
}
}
Only to get this response: Vars can be assigned only when grouped by UID attribute
Is there any way to ensure I only get a query result when all uid aggregates have their own non-empty results?