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

Danny Chen commented on CALCITE-4022:
-------------------------------------

It seems that you want the SqlNode that has been visited by the SqlShuttle can 
still be unparsed correctly. But i don't think the fix the right. For these 
reasons:

SqlShuttle is a tool class, there is no guarantee that the node before & after 
visited should be strictly the same
The original SqlSyntax.SPECIAL did the right thing, it throws exception to let 
the SqlOperator customize the unparse intentially
If you did want to fix the unparse, in SqlInsert, override its 
SqlInsert#OPERATOR#createCall, like this


{code:java}
new SqlSpecialOperator("INSERT", SqlKind.INSERT) {
        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos 
pos, SqlNode... operands) {
          return new SqlInsert(
              pos,
              (SqlNodeList) operands[0],
              operands[1],
              operands[2],
              (SqlNodeList) operands[3]);
        }
      };
{code}



> Support unparse special syntax when operator is INSERT
> ------------------------------------------------------
>
>                 Key: CALCITE-4022
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4022
>             Project: Calcite
>          Issue Type: Wish
>            Reporter: xzh_dz
>            Assignee: Wang Yanlin
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: image-2020-05-25-17-38-36-009.png
>
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> This exception can be reproduced as below:
> SqlParserTest:
> {code:java}
>  @Test void test() throws Exception {
>     final String sql = "insert into emps select * from emps";
>     final SqlNode sqlNode = getSqlParser(sql).parseStmt();
>     final SqlNode sqlNodeVisited = sqlNode.accept(new SqlShuttle() {
>       @Override public SqlNode visit(SqlIdentifier identifier) {
>         return new SqlIdentifier(identifier.names,
>             identifier.getParserPosition());
>       }
>     });
>     System.out.println(sqlNodeVisited.toString());
>   }
> {code}
>  !image-2020-05-25-17-38-36-009.png! 
> Method threw 'java.lang.UnsupportedOperationException' exception. Cannot 
> evaluate org.apache.calcite.sql.SqlBasicCall.toString()
> SqlInsert is a SqlSpecialOperator, when `toString` method is called, this 
> problem is shown.We can see that `SqlSyntax#SPECIAL#unparse()` hasn't been 
> implemented yet.
> exception :
> java.lang.UnsupportedOperationException: class 
> org.apache.calcite.sql.SqlSyntax$6: SPECIAL
>       at org.apache.calcite.util.Util.needToImplement(Util.java:967)
>       at org.apache.calcite.sql.SqlSyntax$6.unparse(SqlSyntax.java:116)
>       at org.apache.calcite.sql.SqlOperator.unparse(SqlOperator.java:333)
>       at org.apache.calcite.sql.SqlDialect.unparseCall(SqlDialect.java:462)
>       at org.apache.calcite.sql.SqlCall.unparse(SqlCall.java:104)
>       at org.apache.calcite.sql.SqlNode.toSqlString(SqlNode.java:151)
>       at org.apache.calcite.sql.SqlNode.toString(SqlNode.java:126)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to