Feature request: math function abs

Experience Report for Feature Request

I regularly need an absloute value function in dgraph queries.

Would it be possible to add abs( <exp> ) ?

What you wanted to do

Compute the absolute value of a number.

What you actually did

I tried:


math(cond(var<0, -var, var))

But when var is empty, it crashes with: Expected a value variable in cond but missing

So I ended up doing:


math(max(var, 0)-min(var, 0))

which doesn’t care if var is empty.

Why that wasn’t great, with examples

Current workaround is too verbose, variables have to be repeated and performances might not be optimal.

Any external references to support your case