Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2674

SqlIdentifier same name with built-in function but with escape character should be still resolved as an identifier

    XMLWordPrintableJSON

Details

    Description

      Now If user defines table as schema below:

      create table tt(
      `current_time` int,
      b int);
      

      Then start a query: 

      select `current_time` from tt;
      

      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:

      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;
      }

      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.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              danny0405 Danny Chen
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2.5h
                  2.5h