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/05/07 02:23:48 UTC

[GitHub] [shardingsphere] luoyihang opened a new issue #5451: sharding value is camelCase in select sql, but lowercase in insert sql

luoyihang opened a new issue #5451:
URL: https://github.com/apache/shardingsphere/issues/5451


   ### Which version of ShardingSphere did you use?
   4.1.0
   ### Which project did you use? Sharding-JDBC or Sharding-Proxy?
   Sharding-JDBC
   ### Expected behavior
   I used a ComplexKeysShardingAlgorithm,and use `complexKeysShardingValue.getColumnNameAndShardingValuesMap().get(myShardingKeyValue)` to get `sharding value`.
   Both `select sql` and `insert sql` can get the `sharding value`.
   ### Actual behavior
   I can get the `sharding value` in `select sql`,but cannot get `sharding value` in `insert sql`.
   
   Because in `select sql`, the `HashMap's key` of  `complexKeysShardingValue.getColumnNameAndShardingValuesMap()` is camelCase, but in `insert sql`, the `HashMap's key` is lowercase
   ### Reason analyze (If you can)
   `WhereClauseShardingConditionEngine` use `sql statment's offset`,so it's camelCase.
   `InsertStatementContext' columnNames` is lowerCase,because `TableMetaData#TableMetaData` convert the column names to lowercase.
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   sharding rule
   ```yaml
   tables:
     t_person:
       actualDataNodes: ds.t_person
       tableStrategy:
         complex:
           shardingColumns: userName
           algorithmClassName: com.xxx.PersonShardingAlgorithm
   ```
   sql 
   ```mysql
   CREATE TABLE `t_person_0` (
     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
     `userName` varchar(50) DEFAULT NULL COMMENT 'userName',
     PRIMARY KEY (`id`),
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
   
   CREATE TABLE `t_person_1` (
     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
     `userName` varchar(50) DEFAULT NULL COMMENT 'userName',
     PRIMARY KEY (`id`),
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
   ```
   `select sql` and `insert sql`
   ```
   select userName from t_person where userName = #{userName};
   insert into t_person(userName) values(#{param.userName});
   ```
   
   PersonShardingAlgorithm
   ```java
   public class PersonShardingAlgorithm implements ComplexKeysShardingAlgorithm<String> {
   
       private static final String SHARDING_KEY = "userName";
   
       @Override
       public Collection<String> doSharding(Collection<String> collection, ComplexKeysShardingValue<String> complexKeysShardingValue) {
           List<String> retVal = new ArrayList<>();
           retVal.add("t_person" + complexKeysShardingValue.getColumnNameAndShardingValuesMap().get(SHARDING_KEY).hashCode() % 2);
           return retVal;
       }
   }
   ```
   
   ### 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:
users@infra.apache.org



[GitHub] [shardingsphere] luoyihang commented on issue #5451: sharding value is camelCase in select sql, but lowercase in insert sql

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


   ok


----------------------------------------------------------------
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] kimmking edited a comment on issue #5451: sharding value is camelCase in select sql, but lowercase in insert sql

Posted by GitBox <gi...@apache.org>.
kimmking edited a comment on issue #5451:
URL: https://github.com/apache/shardingsphere/issues/5451#issuecomment-625024115


   IMO, all these should be lowercase.
   We will check it.
   
   And now, you can config all of them in lowercase to avoid this issue.


----------------------------------------------------------------
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] kimmking commented on issue #5451: sharding value is camelCase in select sql, but lowercase in insert sql

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


   IMO, all these should be lowercase.
   We will check it.


----------------------------------------------------------------
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] kimmking commented on issue #5451: sharding value is camelCase in select sql, but lowercase in insert sql

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


   Hello, according to the principle:
   1. metadata is controlled by framework, so it's uniformed to lower case.
   2. rules and sql is controlled by users, so framework keep it original case.
   
   And then, you should use lower case in all of your codes.


----------------------------------------------------------------
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] kimmking closed issue #5451: sharding value is camelCase in select sql, but lowercase in insert sql

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


   


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