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

Benchao Li commented on CALCITE-5118:
-------------------------------------

I kind of agree with [~julianhyde], {{rewriteCall}} mechanism is not friendly 
for validation errors.
Although one of its purposes is to simplify the the implementation of type 
derivation, we still added the correct type derivation methods for these 
SqlOperators because we have a config to disable the rewriting in 
{{SqlValidator#Config#callRewrite}}. Actually it does not save the effort in 
validation.

One possible way to get rid of the validation problem is to define a 
{{originalOperator}} in {{SqlOperator}}, and use it to prompt the correct 
validation error message. However, this way does not solve all issues, e.g. 
{{NULLIF}} is rewritten to {{CASE WHEN}}, which is a SqlCall tree, and the 
error maybe lies in the sub tree.

The other way is to do the rewriting in {{StandardConvertletTable}} like Julian 
said. This way can make the validation error more friendly. I personally favor 
this way.

If you all agree with this, I think we can do the following tasks for the first 
step:
1. deprecate {{SqlOperator#rewriteCall}}, {{SqlValidator#Config#callRewrite}}
2. change {{SqlValidator#Config#callRewrite}} default to false
3. move the rewriting logic for all {{SqlOperator}}s which override the 
{{rewriteCall}} to {{StandardConvertletTable}}

> SqlDatePartFunction#rewriteCall should check operands length
> ------------------------------------------------------------
>
>                 Key: CALCITE-5118
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5118
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.30.0
>            Reporter: Benchao Li
>            Assignee: Benchao Li
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.31.0
>
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> {{SqlDatePartFunction#rewriteCall}} does not check operands length for now, 
> and it will be rewrite to {{EXTRACT}} unconditionally before validation.
> E.g.
> {code:sql}
> select week(); -- will throw ArrayIndexOutOfBoundsException
> select week(date '2022-04-27', 1); -- will just ignore second param
> {code}
> However, these cases should throw validation exceptions, because {{week}} 
> actually only accept 1 operand.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to