You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Shashwat Kumar <sh...@gmail.com> on 2018/11/11 14:20:50 UTC

Avoid SqlParser.toSqlString() adding double quotes to select identifiers

I am trying to modify a SQL statement using SQL Parser and implementing
SQLVisitor interface to modify select column variables.
However after modification when I am trying to convert back to sql
statement, I am getting double quotes in identifiers which is causing sql
to break on Elastic Search.

My input query is as follows:
    SELECT user FROM logs;

I want to change it to
    SELECT _MAP['user'] as "user" FROM "logs";

toSqlString(SqlDialect.DatabaseProduct.CALCITE.getDialect()) is returning

  SELECT "_MAP['user']" AS "user" FROM "logs"


How should I do this? Thank you in advance for any suggestions.

-- 
Regards
Shashwat Kumar

Re: Avoid SqlParser.toSqlString() adding double quotes to select identifiers

Posted by Michael Mior <mm...@apache.org>.
Have you tried using MysqlSqlDialect instead?

On Sun, Nov 11, 2018, 09:21 Shashwat Kumar <shashwatkmr.001@gmail.com wrote:

> I am trying to modify a SQL statement using SQL Parser and implementing
> SQLVisitor interface to modify select column variables.
> However after modification when I am trying to convert back to sql
> statement, I am getting double quotes in identifiers which is causing sql
> to break on Elastic Search.
>
> My input query is as follows:
>     SELECT user FROM logs;
>
> I want to change it to
>     SELECT _MAP['user'] as "user" FROM "logs";
>
> toSqlString(SqlDialect.DatabaseProduct.CALCITE.getDialect()) is returning
>
>   SELECT "_MAP['user']" AS "user" FROM "logs"
>
>
> How should I do this? Thank you in advance for any suggestions.
>
> --
> Regards
> Shashwat Kumar
>