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

Mihai Budiu commented on CALCITE-7035:
--------------------------------------

This is the functions we had to implement (but there may be more we may not be 
testing):
- NULLIF
- Many DATE functions (or DATE_PART), like EPOCH, MILLENIUM which are 
translated to EXTRACT
- COALESCE

You can see what classes override SqlOperator.rewriteCall:

SqlBasicFunction.java
SqlCoalesceFunction.java
SqlDatePartFunction.java
SqlJdbcFunctionCall.java
SqlNewOperator.java
SqlNullifFunction.java
SqlProcedureCallOperator.java

Some of these delegate the rewrite further: 

SqlBasicFunction:

  @Override public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
    return operandHandler.rewriteCall(validator, call);
  }

OperandHandler only has two overrides:
Anonymous in of()
TimeFrameOperandHandler

A rewrite is probably safe if it does not "copy" any of its arguments.
This makes me think that only Coalesce and Nullif are actually unsafe.
So we can probably take a modified solution based on [~jensen]'s PR, if we add 
NULLIF to it.
But NULLIF also does not have an implementor, so that one needs to be built

The solution proposed in [CALCITE-7012] is to implement the same rewrites at 
the level of Rex nodes.
We can probably use a mix, where we keep some rewrites on SqlNode and implement 
the remaining ones using RexNodes - in particular, COALESCE and NULLIF.

For now we can revert the original fix.





> SQL calls without an implementor or convertlet (NULLIF, YEAR, ...) throw an 
> error when having a subquery as parameter
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7035
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7035
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.40.0
>            Reporter: Aleksey Plekhanov
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.40.0
>
>
> After CALCITE-6978 {{SqlCall}}'s with subqueries are not rewritten during 
> validation even when {{withCallRewrite(true)}} property is set in the 
> configuration.
> Functions like {{NULLIF}}, {{YEAR}}, {{MONTH}}, etc don't have implementor or 
> convertlet, so, when used with subqueries, throw an error: Unable to 
> implement.
> Examples of problematic queries:
> {noformat}
> select nullif((select max(emps.age) from emps), 0);
> select year(select max(joinedat) from emps);
> {noformat}



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

Reply via email to