You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2022/08/08 05:56:00 UTC

[jira] [Commented] (CALCITE-5230) PERCENTILE_DISC return type derivation

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

Julian Hyde commented on CALCITE-5230:
--------------------------------------

I ran {{SqlValidatorTest.testPercentile}} in the debugger. I see that {{ExplicitTypeInference.inferReturnType}} is being called with the {{opBinding}} argument being a {{SqlCallBinding}} with {{call}} = "PERCENTILE_DISC(0.25)".

The solution would be to ensure the {{call}} points to the enclosing call "PERCENTILE_DISC(0.25) WITHIN GROUP (ORDER BY `EMP`.`SAL`)".

If you look up the stack, there is a call to {{SqlWithinGroupOperator.deriveType}}. The trick is probably to make the whole call, including {{WITHIN GROUP}}, available to {{PERCENTILE_DISC}}. Perhaps using a new sub-type of {{SqlCallBinding}}.

> 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
>            Priority: Major
>
> 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)