Can I use an aggregation result as argument to a U...
# general
t
Can I use an aggregation result as argument to a UDF during query?
x
I think only having clause is supported, udf on aggregation results is not supported afaik
t
The problem is we have sum(a)/sum(b) doing some rate calculation, but sum(b) can be 0, then the result will be NaN, when doing an order by, NaN will be ranked first, I want to fill NaN to 0 in this case.
j
Can you try adding
having sum(b) != 0
and see if it solves the problem?
t
adding having will filter the result, I actually want to fill NaN with 0.
j
You can also plug in your own UDF to replace
NaN
with
0
. Udf on aggregation results is supported (post-aggregation), e.g.
sum(a)/sum(b)
Basically you need
replaceNaN(sum(a)/sum(b))
and plug in
replaceNaN(double value)
t
So a scalar UDF will work on post-aggregation, but groovy UDF will not work on post-aggregation?
I see, I will try implement a scalar UDF.
Thanks
j
Yes, groovy can only be used for record transform, but not post-aggregation as of now
Can you please file an issue about this? It should not be too hard to add a scalar function for groovy. Contributions are very welcome
t
OK, I will file an issue for this.