Please have a look in the SqlDialect class:

  /**
   * A dialect useful for generating SQL which can be parsed by the
   * Calcite parser, in particular quoting literals and identifiers. If you
   * want a dialect that knows the full capabilities of the database, create
   * one from a connection.
   */
  public static final SqlDialect CALCITE =
      DatabaseProduct.CALCITE.getDialect();

Just select the suitable Dialect from the DatabaseProduct enum.

Julian

Am 31.10.18, 12:28 schrieb "Shashwat Kumar" <[email protected]>:

    Hi Julian,
    
    I have been able to successfully implement your above suggestions and got
    properly modifed SqlNode in the end.
    Now I want to convert SqlNode to sqlquery which I want to pass to JDBC
    connection. Could you please help in that?
    
    sqlNode.toString() is not giving proper query.
    sqlNode.toSqlString(SqlDialect dialect) seems to be appropriate solution
    but what should I pass as dialect?
    
    On Wed, Oct 31, 2018 at 4:05 PM Julian Feinauer <
    [email protected]> wrote:
    
    > Hi Shashwat,
    >
    > the implementation to use should be SqlBasicCall.
    > And to achieve what you want to do I would use
    >
    > SqlParserPos pos = yourNode.getParserPosition();
    > SqlNode aliased = new SqlBasicCall(SqlStdOperatorTable.AS, new
    > SqlNode[]{yourNode, new SqlIdentifier(Collections.singletonList("v", pos),
    > pos)}
    >
    > Note, I did not check above lines so perhaps you have to modify it a bit
    > or play around, but this should be the general direction, I think.
    >
    > Julian
    >
    > Am 31.10.18, 11:28 schrieb "Shashwat Kumar" <[email protected]>:
    >
    >     Hi Julian,
    >
    >     Thank you for quick response.
    >     SqlCall is abstract class so I am not able to find which concrete
    > subclass
    >     of it I should instantiate. Could you please give some more hint or
    > code
    >     snippet to do it? Also how to modify the identifier name. Say I want 
to
    >     change value to _MAP['value'] e.g.
    >
    >     SELECT _MAP['value'] as v FROM Data
    >
    >     On Wed, Oct 31, 2018 at 3:42 PM Julian Feinauer <
    >     [email protected]> wrote:
    >
    >     > Hi Shashwat,
    >     >
    >     > Calcite does this by a Call to the "AS" Operator (basically value as
    > v is
    >     > just syntactic sugar for AS(value, v)).
    >     > So you need to create a call node (SqlCall) with the AS Operator
    >     > (SqlStdOperatorTable.AS) and as operands you node and an
    > SqlIdentifier for
    >     > the Alias.
    >     >
    >     > But your visitor should then return SqlNode not String, or?
    >     >
    >     I'll will change it to SqlNode.
    >
    >     >
    >     > Best
    >     > Julian
    >     >
    >     > Am 31.10.18, 11:07 schrieb "Shashwat Kumar" <
    > [email protected]>:
    >     >
    >     >     I want to modify select identifiers in sql statement. For 
example
    >     >     SELECT value FROM Data
    >     >     to
    >     >     SELECT value as v FROM Data
    >     >
    >     >     I am able to get SqlNode for select identifiers as follows.
    >     >
    >     >     public String visit(SqlCall sqlCall) {
    >     >
    >     >             SqlNodeList selectList = ((SqlSelect)
    > sqlCall).getSelectList();
    >     >             for (SqlNode sqlNode : selectList) {
    >     >                 *// do something with sqlNode*
    >     >             }
    >     >
    >     >     }
    >     >
    >     >     Now how to change sqlNode as per requirement?
    >     >
    >     >
    >     >     --
    >     >     Regards
    >     >     Shashwat Kumar
    >     >
    >     >
    >     >
    >
    >     --
    >     Regards
    >     Shashwat Kumar
    >
    >
    >
    
    -- 
    Regards
    Shashwat Kumar
    

Reply via email to