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

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

When wrote the code, I also wondered what the relationship between rewriting 
and validating should be. I found the comment of 
[SqlOperator#rewriteCall|https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/SqlOperator.java#L359-L362],
 it says: 
{quote}we do this before the call is validated (so the trivial operator doesn't 
need its own implementation of type derivation methods).{quote}
Then I chose to just validate the length in 
{{SqlDatePartFunction#rewriteCall}}, and leave the other validating work to the 
rewritten {{SqlCall}}


> 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