Hi Julian, thanks for your email.

I don't think those tickets will solve the problem as from what I
understand, they are referring to the input types, while my issue is with
the return type (although it might have the same root cause).

As you can see in the code
<https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java#L2304>,
right now the return type is hard coded as DOUBLE. The problem is that in
the following query:

> select percentile_disc(0.12) within group(order by x) from t;

The PERCENTILE_DISC argument will be only 0.12, and the argument "x" will
be outside of it (in the WITHIN_GROUP call). so the return type inference
cannot use the type of the column "x" when it's inferring the return type.

Itiel

On Thu, Aug 4, 2022 at 9:43 PM Julian Hyde <[email protected]> wrote:

> I believer that PERCENTILE_DISC was implemented in
> https://issues.apache.org/jira/browse/CALCITE-4644 <
> https://issues.apache.org/jira/browse/CALCITE-4644>. There are open
> issues to support any sortable type [
> https://issues.apache.org/jira/browse/CALCITE-4670 <
> https://issues.apache.org/jira/browse/CALCITE-4670> ] and also to change
> the implementation strategy [
> https://issues.apache.org/jira/browse/CALCITE-4666 <
> https://issues.apache.org/jira/browse/CALCITE-4666> ].
>
> Does your case map onto any of those?
>
> Is PERCENTILE_DISC able to deduce return types from its arguments today?
> If so, how does it do it?
>
> Julian
>
>
> > On Aug 3, 2022, at 1:40 PM, Itiel Sadeh <[email protected]>
> wrote:
> >
> > Hello,
> >
> > First of all I just wanted to thank all of you for the work you are doing
> > on Calcite.
> >
> > We want to add support for the percentile_disc aggregate function, but we
> > encounter a problem.
> > Our percentile_disc return type is dependent on the column of the "order
> > by" clause (just like postgresql
> > <https://www.postgresql.org/docs/current/functions-aggregate.html>).
> > However, I don't see how to achieve that on calcite. The issue is that
> the
> > sort column argument is not passed to the percentile_disc function,
> Rather,
> > it is stored outside of it as a collation. Therefore, I cannot use the
> > SqlReturnTypeInference mechanism.
> >
> > If someone has an idea on how to achieve this it would be very much
> > appreciated.
> > Thank you,
> >
> > Itiel
>
>

Reply via email to