Use @groupby, @normalize as a source for a variable

I tried to assign a node which is modified by a @groupby or @normalize directive as the source to store into a variable.

I did not have success to re-use these variables, yet Ratel / DGraph did not complain.

What type is a variable where I assigned the “result” of an aggregate or a normalize? Will it generate a query variable or a value variable?

How can I access the nodes stored in such a variable?

can you share some examples?

If you store nodes in variables, you’re really storing a uid list (of one type). This means you cannot get any changes, that get @normalized. Normalize is just post processing.

Thank you for your reply, I already assumed that it’s like that. So I suggest

  • to update the documentation; and /or
  • that variables at such a place result in an error.

Out of curiosity I looked at the docs and it states that the variable type is uid https://dgraph.io/docs/query-language/query-variables/

You can still use @normalize and @cascade for ranging, for example when you need only nodes(uids) with all fields - so that’s useful in that case.

Still, an example would be nice as MichelDiz said, coz you can use variables+aggregation on values as well, so it may be possible to do what you want.

I was hopping to be able to save the result of an aggregation into a variable and use that later somehow together with count(uid(variable)) to get the cardinality of the “buckets” of an @orderby.

Like in

{
  var(func:type(Office))  {
    officename: Office.bezeichnung
		CNT as Office.jobs @groupby(Job.employees)
  }
 q(func: uid(CNT))  {
    total: count(val(OJ))
  }
}

I know this query is invalid, but I am interested in the number of buckets the @groupby results in and fr this to be effective I think I should be able to assign variables at the @groupby-level.

Btw, this question really is a “generalisation” of my example in Unique count of edges

1 Like