sandynz commented on issue #6942:
URL: https://github.com/apache/shardingsphere/issues/6942#issuecomment-677351537


   > 
   > 
   > @sandynz Hi, Can you provide your table schema and sharding configuration? 
I have used the master branch to test, the `INSERT INTO ... ON DUPLICATE KEY 
UPDATE ...` statement can be executed normally.
   
   
   Hi @strongduanmu , I tested it on lastest master branch again, commit: 
bfb1486549e9908f8784210fe2100f1c5fdd212d (2020-08-19), run 
`org.apache.shardingsphere.proxy.Bootstrap`, it doesn't work.
   
   My config-sharding.yaml
   ```
   schemaName: sharding_db
   
   dataSourceCommon:
     username: root
     password: test
     connectionTimeoutMilliseconds: 30000
     idleTimeoutMilliseconds: 60000
     maxLifetimeMilliseconds: 1800000
     maxPoolSize: 50
     minPoolSize: 1
     maintenanceIntervalMilliseconds: 30000
   
   dataSources:
     ds:
       url: 
jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
   
   rules:
     - !SHARDING
       tables:
         t_order:
           actualDataNodes: ds.t_order_${0..1}
           tableStrategy:
             standard:
               shardingColumn: order_id
               shardingAlgorithmName: t_order_inline
           keyGenerateStrategy:
             column: order_id
             keyGeneratorName: snowflake
         t_order_item:
           actualDataNodes: ds.t_order_item_${0..1}
           tableStrategy:
             standard:
               shardingColumn: order_id
               shardingAlgorithmName: t_order_item_inline
           keyGenerateStrategy:
             column: order_item_id
             keyGeneratorName: snowflake
       bindingTables:
         - t_order,t_order_item
       broadcastTables:
         - t_address
   
       shardingAlgorithms:
         t_order_inline:
           type: INLINE
           props:
             algorithm.expression: t_order_${order_id % 2}
         t_order_item_inline:
           type: INLINE
           props:
             algorithm.expression: t_order_item_${order_id % 2}
   
       keyGenerators:
         snowflake:
           type: SNOWFLAKE
           props:
             worker.id: 123
   ```
   
   My database:
   ```
   mysql> use demo_ds_1
   Database changed
   
   CREATE TABLE IF NOT EXISTS t_address (address_id BIGINT NOT NULL, 
address_name VARCHAR(100) NOT NULL, PRIMARY KEY (address_id));
   CREATE TABLE IF NOT EXISTS `t_order_0` (`order_id` INT NOT NULL, `user_id` 
INT NOT NULL, `status` VARCHAR(45) NULL, PRIMARY KEY (`order_id`));
   CREATE TABLE IF NOT EXISTS `t_order_1` (`order_id` INT NOT NULL, `user_id` 
INT NOT NULL, `status` VARCHAR(45) NULL, PRIMARY KEY (`order_id`));
   CREATE TABLE IF NOT EXISTS `t_order_item_0` (`order_item_id` INT NOT NULL, 
`order_id` INT NOT NULL, `user_id` INT NOT NULL, `status` VARCHAR(45) NULL, 
PRIMARY KEY (`order_item_id`));
   CREATE TABLE IF NOT EXISTS `t_order_item_1` (`order_item_id` INT NOT NULL, 
`order_id` INT NOT NULL, `user_id` INT NOT NULL, `status` VARCHAR(45) NULL, 
PRIMARY KEY (`order_item_id`));
   
   mysql> show tables;
   +---------------------+
   | Tables_in_demo_ds_1 |
   +---------------------+
   | t_address           |
   | t_order_0           |
   | t_order_1           |
   | t_order_item_0      |
   | t_order_item_1      |
   +---------------------+
   5 rows in set (0.00 sec)
   ```
   
   My client test code snippet:
   ```
   public static void main(String[] args) throws Exception {
        final boolean useServerPrepStmts = true;
        try (Connection connection = 
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3307/sharding_db?serverTimezone=UTC&useSSL=false"
 + (useServerPrepStmts ? "&useServerPrepStmts=true&cachePrepStmts=true" : ""), 
"root", "root")) {
                int orderId = 1, userId = 2;
                String status = "PAID";
                try (PreparedStatement statement = 
connection.prepareStatement("insert into t_order (order_id, user_id, status) 
values (?, ?, ?) ON DUPLICATE KEY UPDATE status = ?")) {
                        statement.setInt(1, orderId);
                        statement.setInt(2, userId);
                        statement.setString(3, status);
                        statement.setString(4, "DUPLICATED");
                        statement.executeUpdate();
                }
        }
   }
   ```
   
   


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