strongduanmu opened a new issue #12528:
URL: https://github.com/apache/shardingsphere/issues/12528


   ### Which version of ShardingSphere did you use?
   
   master branch
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   proxy or jdbc
   
   ### Expected behavior
   
   execute successfully
   
   ### Actual behavior
   
   Throw exception because wrong sql rewrite and user does not config 
KeyGenerateStrategy.
   
   
![image](https://user-images.githubusercontent.com/10829171/133775543-984b984a-2dd9-4183-a72e-eb2486c41085.png)
   
   ### Reason analyze (If you can)
   
   Because DialectTableMetaDataLoader loaded the original information of the 
table, and did not process the generated attribute, a logical error occurred 
when judging whether to generate a distributed primary key.
   
   ```java
   /**
    * Generated key insert column token generator.
    */
   public final class GeneratedKeyInsertColumnTokenGenerator extends 
BaseGeneratedKeyTokenGenerator {
       
       @Override
       protected boolean isGenerateSQLToken(final InsertStatementContext 
insertStatementContext) {
           Optional<InsertColumnsSegment> sqlSegment = 
insertStatementContext.getSqlStatement().getInsertColumns();
           return sqlSegment.isPresent() && 
!sqlSegment.get().getColumns().isEmpty()
                   && 
insertStatementContext.getGeneratedKeyContext().isPresent()
                   && 
!insertStatementContext.getGeneratedKeyContext().get().getGeneratedValues().isEmpty();
       }
   ...
   }
   ```
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to