hi , is there a way to set `count(a) / count(b)` ...
# general
w
hi , is there a way to set
count(a) / count(b)
to 0 when
count(b) = 0
instead of
NaN
or
Infinity
?
Nan
and
Infinity
isn’t really sort friendly.
m
You can try case when syntax ?
w
yea,that’s the first thing I tried, error says case when doesn’t support aggregate function
k
this is a post aggregate scalar function
Copy code
@ScalarFunction
  public static double divide(double a, double b) {
    return a / b;
  }
will adding an override function to return default value if denominator is 0 work
also, curious on what other databases do in this case
w
thanks Kishore , if there is an open issue/work item for this, it would be great if you can share the link here?
m
Will the post aggregation FILTER clause help here? cc: @Jackie
w
we dont want to filter those results out, this divide is usually a common use case of answering query for month over month change
ideally it would be great we can allow user to provide a default value
k
we dont have an open item, its a simple function to add.. you can try it out and contribute
w
sure, sounds good
j
Ideally this should be solved with the
case
function, which is not supported on post-aggregation yet
We need to add a scalar function version of
case
to support it
As a work around, we may add
divide(double a, double b, double default)
, then use
divide(count(a), count(b), 0)
in the query
w
thanks for reviewing and merging this pr ! Which release would this be included in ?
m
Afaik, 0.11 is already in progress, so the one after that.
w
around end of this year for 0.12?
m
Hopefully before that
l
hey friends kinda reviving this, we are in
0.11
and are facing this issue, what can we do to over come this? @Mayank @Jackie use DIVIDE() with denominator being 0.
oh never mind it turns out, this is actually in 0.11.0 🙂 never mind! and thank you for this!!!