[ 
https://issues.apache.org/jira/browse/CALCITE-5230?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17577804#comment-17577804
 ] 

Itiel Sadeh commented on CALCITE-5230:
--------------------------------------

Thanks for the review.
{quote}Should PERCENTILE_CONT be handled in a similar way?
{quote}
No, but it might be beneficial to make it available to change the return type 
for those who want it. If you disagree I will add a check for 
SqlKind.PERCENTILE_DISC. 
{quote}I don't like the idea of pretending that the ORDER BY expression is an 
argument. It might work for this piece of code, but confuse another. That's why 
I suggested a sub-class of SqlCallBinding to make the extra information 
available.
{quote}
I don't like it as well, I just wasn't sure what to do differently. Are you 
suggesting to create a named sub-class SqlPercentileBinding and a new 
SqlReturnTypeInference which would use the new binding class?
{quote}I saw a few copy-pasted methods in the anonymous class and wondered 
whether these could be inherited.
{quote}
The problem with it is that the methods in SqlCallBinding are not using the 
`operands` method to access the operands, but they are using the call directly. 
Look at `getOperandCount` for example:
{code:java}
 @Override public int getOperandCount() {
    return call.getOperandList().size();
}
{code}

> PERCENTILE_DISC return type derivation
> --------------------------------------
>
>                 Key: CALCITE-5230
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5230
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Itiel Sadeh
>            Assignee: Itiel Sadeh
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.32.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> In the following expression:
> {code:java}
> PERCENTILE_DISC ( numeric_literal ) WITHIN GROUP ( ORDER BY 
> order_by_expression) {code}
> the return type of `PERCENTILE_DISC` aggregate function is hard-coded as 
> `DOUBLE`, 
> while in Postgresql and MSSQL it is determined by the `order_by_expression` 
> type. 
> Currently there is no way to derive the correct type of `PERCENTILE_DISC` 
> function from the `order_by_expression` type, as this expression is not an 
> argument for the `PERCENTILE_DISC` function. 
> Calcite is creating the following tree from this expression:
> {code:java}
> SqlCall(operator: WITHING_GROUP, operands: [SqlCall( operator: 
> PERCENTILE_DISC, operands: [numeric_literal], order_by_expression]){code}
> for correct type derivation, the order_by_expression should be an operand of 
> the PERCENTILE_DISC call



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to