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

Yuzhao Chen commented on CALCITE-2674:
--------------------------------------

[~julianhyde]  Now we parse escape character through JavaCC token manager, the 
only snippet we can have info about whether the identifier is escaped is in 
Parser.jj#Identifier(), this method is invoked by many parse logic.

If we do not add flag in the Parser.jj#Identifier() return type and just t 
return a string id, we will never know when and whether the identifier is 
escaped at all.

For Parser.jj#CompoundIdentifier() i add compound id list length check:
{code:java}
        if (list.size() == 1) {
            return new SqlIdentifier(list, null, pos, posList, p.right);
        } else {
            return new SqlIdentifier(list, null, pos, posList);
        }
{code}
If the list length is 1 (means that it is a simple identifier), we will mark 
the SqlIdentifier as if it is escaped, else we will force make the whole 
compound identifier as not escaped.

look forward to your suggestions, i will add the Oracle test cases to the UT.

> Column name with escape character should not be verified as a function when 
> the column name is same with it
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-2674
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2674
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.18.0
>            Reporter: Yuzhao Chen
>            Assignee: Julian Hyde
>            Priority: Major
>             Fix For: 1.18.0
>
>
> Now If user defines table as schema below:
> {code:java}
> create table tt(
> `current_time` int,
> b int);
> {code}
> Then start a query: 
> {code:java}
> select `current_time` from tt;
> {code}
> Calcite parser will parse the *current_time* as a normal *SqlIdentifier*, 
> then the SqlValidator will recognize it as a builtin function with below code 
> snippet:
> {code:java}
> public static SqlCall makeCall(
>     SqlOperatorTable opTab,
>     SqlIdentifier id) {
>   if (id.names.size() == 1) {
>     final List<SqlOperator> list = new ArrayList<>();
>     opTab.lookupOperatorOverloads(id, null, SqlSyntax.FUNCTION, list);
>     for (SqlOperator operator : list) {
>       if (operator.getSyntax() == SqlSyntax.FUNCTION_ID) {
>         // Even though this looks like an identifier, it is a
>         // actually a call to a function. Construct a fake
>         // call to this function, so we can use the regular
>         // operator validation.
>         return new SqlBasicCall(
>             operator,
>             SqlNode.EMPTY_ARRAY,
>             id.getParserPosition(),
>             true,
>             null);
>       }
>     }
>   }
>   return null;
> }{code}
> While i tried MYSQL and such query can work properly, so is this a bug ?
> Cause if the matched function's return type is same with the column, then the 
> query will output wrong results.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to