lwtdev opened a new issue #7662:
URL: https://github.com/apache/shardingsphere/issues/7662


   ## Bug Report 
   
   Some SQL was executed incorrectly in 5.0.0-RC1, but executed successfully in 
4.1.1
   
   ### Which version of ShardingSphere did you use?
   
    5.0.0-RC1 
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-Proxy
   
   ### Expected behavior
   In 4.1.1
   
   ```sql
   ShardingProxy(4.1.1)2DB2Table
   insertValueWithExpr[hasShardingKey:All];      Support:true;  SQL: insert 
into customer (id, name, party_id) values (3, 'a', id + 1);
   ds_01|insert into customer_0003 (id, name, party_id) values (3, 'a', id+1)|
   
   
   ShardingProxy(4.1.1)2DB2Table
   createTableWithOnUpdate[hasShardingKey:none];         Support:true;  SQL: 
CREATE TABLE customer_email (   id bigint(20) NOT NULL COMMENT 'primary key',   
`gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,   `gmt_modified` datetime NOT 
NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,   PRIMARY KEY 
(`id`) );
   ds_00|CREATE TABLE customer_email_0000 (
     id bigint(20) NOT NULL COMMENT 'primary key',
     `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
     `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP,
     PRIMARY KEY (`id`)
   )|
   ds_00|CREATE TABLE customer_email_0001 (
     id bigint(20) NOT NULL COMMENT 'primary key',
     `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
     `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP,
     PRIMARY KEY (`id`)
   )|
   ds_01|CREATE TABLE customer_email_0002 (
     id bigint(20) NOT NULL COMMENT 'primary key',
     `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
     `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP,
     PRIMARY KEY (`id`)
   )|
   ds_01|CREATE TABLE customer_email_0003 (
     id bigint(20) NOT NULL COMMENT 'primary key',
     `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
     `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP,
     PRIMARY KEY (`id`)
   )|
   
   
   ShardingProxy(4.1.1)2DB2Table
   createTableWithMiddleInt[hasShardingKey:none];        Support:true;  SQL: 
CREATE TABLE full_table (  id bigint(15) not null primary key comment 'prmary 
key',     t_mi middleint(10)  );
   ds_00|CREATE TABLE full_table_0000
   (
        id bigint(15) not null primary key comment 'prmary key',
       t_mi middleint(10)
    )|
   ds_00|CREATE TABLE full_table_0001
   (
        id bigint(15) not null primary key comment 'prmary key',
       t_mi middleint(10)
    )|
   ds_01|CREATE TABLE full_table_0002
   (
        id bigint(15) not null primary key comment 'prmary key',
       t_mi middleint(10)
    )|
   ds_01|CREATE TABLE full_table_0003
   (
        id bigint(15) not null primary key comment 'prmary key',
       t_mi middleint(10)
    )|
   
   ```
   
   ### Actual behavior
   In 5.0.0-RC1
   
   ```sql
   ShardingProxy(5.0.0.RC1)2DB2Table
   insertValueWithExpr[hasShardingKey:All];      Support:false; SQL: insert 
into customer (id, name, party_id) values (3, 'a', id + 1);
   java.sql.SQLException: 2Unknown exception: 
[org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression
 cannot be cast to 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.ComplexExpressionSegment]
   
   ShardingProxy(5.0.0.RC1)2DB2Table
   createTableWithOnUpdate[hasShardingKey:none];         Support:false; SQL: 
CREATE TABLE customer_email (   id bigint(20) NOT NULL COMMENT 'primary key',   
`gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,   `gmt_modified` datetime NOT 
NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,   PRIMARY KEY 
(`id`) );
   com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: This version of 
ShardingProxy doesn't yet support this SQL. 'Unsupported SQL of `CREATE TABLE 
customer_email (
     id bigint(20) NOT NULL COMMENT 'primary key',
     `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
     `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP,
     PRIMARY KEY (`id`)
   )`'
   
   ShardingProxy(5.0.0.RC1)2DB2Table
   createTableWithMiddleInt[hasShardingKey:none];        Support:false; SQL: 
CREATE TABLE full_table (  id bigint(15) not null primary key comment 'prmary 
key',     t_mi middleint(10)  );
   com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: This version of 
ShardingProxy doesn't yet support this SQL. 'Unsupported SQL of `CREATE TABLE 
full_table
   (
        id bigint(15) not null primary key comment 'prmary key',
       t_mi middleint(10)
    )`'
   ```
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   - **Test sqls**
   Use `sctl:explain` run these sqls:
   ```sql
   -- @title:insertValueWithExpr,hasShardingKey:All
   insert into customer (id, name, party_id) values (3, 'a', id + 1);
   
   -- @title:createTableWithOnUpdate
   CREATE TABLE customer_email (
     id bigint(20) NOT NULL COMMENT 'primary key',
     `gmt_created` datetime DEFAULT CURRENT_TIMESTAMP,
     `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP,
     PRIMARY KEY (`id`)
   );
   
   -- @title:createTableWithMiddleInt
   CREATE TABLE full_table
   (
        id bigint(15) not null primary key comment 'prmary key',
       t_mi middleint(10)
    );
   ```
   
   - **Sharding config in 4.1.1**
   ```yaml
   shardingRule:
     tables:
       customer:
         actualDataNodes: ds_00.customer_000${0..1},ds_01.customer_000${2..3}
         databaseStrategy:
           inline:
             shardingColumn: id
             algorithmExpression: ds_0${(id % 4 ).intdiv(2)}
         tableStrategy:
           inline:
             shardingColumn: id
             algorithmExpression: customer_000${id % 4}
         keyGenerator:
           type: SNOWFLAKE
           column: id
       customer_email:
         actualDataNodes: 
ds_00.customer_email_000${0..1},ds_01.customer_email_000${2..3}
         databaseStrategy:
           inline:
             shardingColumn: id
             algorithmExpression: ds_0${(id % 4 ).intdiv(2)}
         tableStrategy:
           inline:
             shardingColumn: id
             algorithmExpression: customer_email_000${id % 4}
         keyGenerator:
           type: SNOWFLAKE
           column: id
       full_table:
         actualDataNodes: 
ds_00.full_table_000${0..1},ds_01.full_table_000${2..3}
         databaseStrategy:
           inline:
             shardingColumn: id
             algorithmExpression: ds_0${(id % 4 ).intdiv(2)}
         tableStrategy:
           inline:
             shardingColumn: id
             algorithmExpression: full_table_000${id % 4}
         keyGenerator:
           type: SNOWFLAKE
           column: id
     bindingTables:
       - customer,customer_email,full_table
     defaultDataSourceName: ds_00
     defaultDatabaseStrategy:
       none:
     defaultTableStrategy:
       none:
   ```
   - **Sharding config in 5.0.0-RC1**
   
   ```yaml
   #
   rules:
   - !SHARDING
     tables:
       customer:
         actualDataNodes: ds_00.customer_000${0..1},ds_01.customer_000${2..3}
         databaseStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: database_inline
         tableStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: customer_inline
         keyGenerateStrategy:
           column: id
           keyGeneratorName: snowflake
       customer_email:
         actualDataNodes: 
ds_00.customer_email_000${0..1},ds_01.customer_email_000${2..3}
         databaseStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: database_inline
         tableStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: customer_email_inline
         keyGenerateStrategy:
           column: id
           keyGeneratorName: snowflake
       full_table:
         actualDataNodes: 
ds_00.full_table_000${0..1},ds_01.full_table_000${2..3}
         databaseStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: database_inline
         tableStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: full_table_inline
         keyGenerateStrategy:
           column: id
           keyGeneratorName: snowflake
     bindingTables:
       - customer,customer_email,full_table
     defaultDatabaseStrategy:
       none:
     defaultTableStrategy:
       none:
   
     shardingAlgorithms:
       database_inline:
         type: INLINE
         props:
           algorithm-expression: ds_0${(id % 4 ).intdiv(2)}
       customer_inline:
         type: INLINE
         props:
           algorithm-expression: customer_000${id % 4}
       customer_email_inline:
         type: INLINE
         props:
           algorithm-expression: customer_email_000${id % 4}
       full_table_inline:
         type: INLINE
         props:
           algorithm-expression: full_table_000${id % 4}
   ```
   
   ### Example codes for reproduce this issue (such as a github link).
   


----------------------------------------------------------------
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:
[email protected]


Reply via email to