You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/05 06:25:27 UTC

[GitHub] [shardingsphere] stephen-gao opened a new issue #6633: execute “replact into xxx” throw “InsertStatement cannot be cast to ReplaceStatement” exception.

stephen-gao opened a new issue #6633:
URL: https://github.com/apache/shardingsphere/issues/6633


   ## Bug Report
   
   version: 4.1.1
   project: ShardingSphere-JDBC
   sql: REPLACE INTO test(id, user_key, username)VALUES(#{id,jdbcType=VARCHAR}, #{userKey,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR});
   properties:
   > spring.shardingsphere.datasource.names=ds0
   spring.shardingsphere.datasource.ds0.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver
   spring.shardingsphere.datasource.ds0.url=jdbc:mysql://xxxxxx
   spring.shardingsphere.datasource.ds0.username=root
   spring.shardingsphere.datasource.ds0.password=
   spring.shardingsphere.sharding.binding-tables=test
   spring.shardingsphere.sharding.tables.test.actual-data-nodes=ds0.test_$->{0..7}
   spring.shardingsphere.sharding.tables.test.table-strategy.standard.sharding-column= user_key
   spring.shardingsphere.sharding.tables.test.table-strategy.standard.precise-algorithm-class-name=
   
   当我执行插入时抛出异常:`java.lang.ClassCastException: org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement cannot be cast to org.apache.shardingsphere.sql.parser.sql.statement.dml.ReplaceStatement`
   
   异常定位到代码:`org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitReplace()` :
   > public ASTNode visitReplace(final ReplaceContext ctx) {
           // TODO :FIXME, since there is no segment for insertValuesClause, InsertStatement is created by sub rule.
           ReplaceStatement result;
           if (null != ctx.insertValuesClause()) {
               result = (ReplaceStatement) visit(ctx.insertValuesClause());
           } else {
               result = new ReplaceStatement();
               result.setSetAssignment((SetAssignmentSegment) visit(ctx.setAssignmentsClause()));
           }
           result.setTable((SimpleTableSegment) visit(ctx.tableName()));
           result.setParameterCount(getCurrentParameterIndex());
           return result;
       }
   
   在`(ReplaceStatement) visit(ctx.insertValuesClause());`强制转化类型的时候报错。
   我使用spi,重写了这个方法,如下:
   > public ASTNode visitReplace(final MySQLStatementParser.ReplaceContext ctx) {
           InsertStatement result;
           if (null != ctx.insertValuesClause()) {
               result = (InsertStatement) visit(ctx.insertValuesClause());
           } else {
               result = new InsertStatement();
               result.setSetAssignment((SetAssignmentSegment) visit(ctx.setAssignmentsClause()));
           }
           result.setTable((SimpleTableSegment) visit(ctx.tableName()));
           result.setParameterCount(getCurrentParameterIndex());
           return result;
       }
   
   replace仍然使用`(InsertStatement) visit(ctx.insertValuesClause());` ,暂时将这个问题解决了。
   但这里可能是一个BUG。
   当然也可能是我使用方式有误,如果是我的配置有问题,请告知一下。
   谢谢!
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on issue #6633: execute “replact into xxx” throw “InsertStatement cannot be cast to ReplaceStatement” exception.

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #6633:
URL: https://github.com/apache/shardingsphere/issues/6633#issuecomment-669013657


   **For English only**, other languages will not accept.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu closed issue #6633: execute “replact into xxx” throw “InsertStatement cannot be cast to ReplaceStatement” exception.

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #6633:
URL: https://github.com/apache/shardingsphere/issues/6633


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org