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 2021/10/12 23:25:40 UTC

[GitHub] [shardingsphere] linghengqian opened a new issue #13009: Some questions about AUTO_INTERVAL for Autotable

linghengqian opened a new issue #13009:
URL: https://github.com/apache/shardingsphere/issues/13009


   ## Question
   
   **For English only**, other languages will not accept.
   
   Before asking a question, make sure you have:
   
   - Googled your question.
   - Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more details. 
   If no response anymore and we cannot reproduce it on current information, we will **close it**.
   
   After reading the article https://mp.weixin.qq.com/s/fDYqW-yJIVpkcUDNT-gsuA, I put forward some question of AUTO_INTERVAL.
   In shardingsphere-jdbc-core-spring-boot-starter:5.0.0 beta,  AutoIntervalShardingAlgorithm class
   , public Collection doSharding(final Collection availableTargetNames, final RangeShardingValue >> shardingValue) , among the use of "each endswith ()". 
   ```java
   @Override
   public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Comparable<?>> shardingValue)
   @Override
   public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Comparable<?>> shardingValue)
   ```
   If there are more than 100 partitions and the sharding table result of the SQL matches the third real table, that's when each.endswith (3),what suffixes must the pre-created table have to ensure that the result returned only gets the third real table and not the extra 53rd real table? In my scenario, if the table is "T_order_ $->{1.. 160} "In this format, there should be no escape from the question, right?
   
   ```java
   @Override
       public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Comparable<?>> shardingValue) {
           for (String each : availableTargetNames) {
               if (each.endsWith(String.valueOf(doSharding(parseDate(shardingValue.getValue()))))) {
                   return each;
               }
           }
           return null;
       }
   
   @Override
       public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Comparable<?>> shardingValue) {
           Collection<String> result = new LinkedHashSet<>(availableTargetNames.size());
           int firstPartition = getFirstPartition(shardingValue.getValueRange());
           int lastPartition = getLastPartition(shardingValue.getValueRange());
           for (int i = firstPartition; i <= lastPartition; i++) {
               for (String each : availableTargetNames) {
                   if (each.endsWith(String.valueOf(i))) {
                       result.add(each);
                   }
                   if (result.size() == availableTargetNames.size()) {
                       return result;
                   }
               }
           }
           return result;
       }
   ```
   
   And AutoIntervalShardingAlgorithm class, its getAllPropertyKeys () function is used for what?
   ```java
   @Override
       public Collection<String> getAllPropertyKeys() {
           return Arrays.asList(DATE_TIME_LOWER_KEY, DATE_TIME_UPPER_KEY, SHARDING_SECONDS_KEY);
       }
   ```
   
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] sandynz commented on issue #13009: Some questions about AUTO_INTERVAL for Autotable

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


   Hi @linghengqian , thanks for your feedback.
   
   ```
           for (int i = firstPartition; i <= lastPartition; i++) {
               for (String each : availableTargetNames) {
                   if (each.endsWith(String.valueOf(i))) {
                       result.add(each);
                   }
   ```
   looks `each.endsWith(String.valueOf(i))` might cause issue.
   
   I changed `AutoIntervalShardingAlgorithmTest.java` to do a test:
   ```
       @Before
       public void setup() {
           shardingAlgorithm = new AutoIntervalShardingAlgorithm();
           shardingAlgorithm.getProps().setProperty("datetime-lower", "2020-01-01 00:00:00");
           shardingAlgorithm.getProps().setProperty("datetime-upper", "2020-01-01 00:00:24");
           shardingAlgorithm.getProps().setProperty("sharding-seconds", "2");
           shardingAlgorithm.init();
       }
   
       
       @Test
       public void assertRangeDoShardingWithPartRange() {
           List<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4");
           availableTargetNames = new ArrayList<>();
           for (int i = 0; i <= 12; i++) {
               availableTargetNames.add("t_order_" + i);
           }
           Collection<String> actual = shardingAlgorithm.doSharding(availableTargetNames, new RangeShardingValue<>("t_order", "create_time", Range.closed("2020-01-01 00:00:00", "2020-01-01 00:00:10")));
           ...
       }
   ```
   
   `actual`.size() should be `6`, but it's `9`. `actual` content is:
   ```
   0 = "t_order_0"
   1 = "t_order_10"
   2 = "t_order_1"
   3 = "t_order_11"
   4 = "t_order_2"
   5 = "t_order_12"
   6 = "t_order_3"
   7 = "t_order_4"
   8 = "t_order_5"
   ```
   `t_order_10`, `t_order_11`, `t_order_12` should not be included.
   
   Hi @strongduanmu Would you help to verify 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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] linghengqian commented on issue #13009: Some questions about AUTO_INTERVAL for Autotable

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


   In my opinion, it is not appropriate to rely only on the unfixed number of digits at the end of the real table to judge the incoming real table. 
   Set the prefix to the logical table, which is an easy solution I experimented with locally.
   Is there any plan for datetime-upper and datetime-lower to be adapted to yyyy-MM-dd HH:mm:ss.SSS in subsequent versions?


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] sandynz commented on issue #13009: Some questions about AUTO_INTERVAL for Autotable

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


   Hi @linghengqian , thanks for your feedback.
   
   ```
           for (int i = firstPartition; i <= lastPartition; i++) {
               for (String each : availableTargetNames) {
                   if (each.endsWith(String.valueOf(i))) {
                       result.add(each);
                   }
   ```
   looks `each.endsWith(String.valueOf(i))` might cause issue.
   
   I changed `AutoIntervalShardingAlgorithmTest.java` to do a test:
   ```
       @Before
       public void setup() {
           shardingAlgorithm = new AutoIntervalShardingAlgorithm();
           shardingAlgorithm.getProps().setProperty("datetime-lower", "2020-01-01 00:00:00");
           shardingAlgorithm.getProps().setProperty("datetime-upper", "2020-01-01 00:00:24");
           shardingAlgorithm.getProps().setProperty("sharding-seconds", "2");
           shardingAlgorithm.init();
       }
   
       
       @Test
       public void assertRangeDoShardingWithPartRange() {
           List<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4");
           availableTargetNames = new ArrayList<>();
           for (int i = 0; i <= 12; i++) {
               availableTargetNames.add("t_order_" + i);
           }
           Collection<String> actual = shardingAlgorithm.doSharding(availableTargetNames, new RangeShardingValue<>("t_order", "create_time", Range.closed("2020-01-01 00:00:00", "2020-01-01 00:00:10")));
           ...
       }
   ```
   
   `actual`.size() should be `6`, but it's `9`. `actual` content is:
   ```
   0 = "t_order_0"
   1 = "t_order_10"
   2 = "t_order_1"
   3 = "t_order_11"
   4 = "t_order_2"
   5 = "t_order_12"
   6 = "t_order_3"
   7 = "t_order_4"
   8 = "t_order_5"
   ```
   `t_order_10`, `t_order_11`, `t_order_12` should not be included.
   
   Hi @strongduanmu Would you help to verify 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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] sandynz commented on issue #13009: Some questions about AUTO_INTERVAL for Autotable

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


   @tuichenchuxin will invetigate 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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] strongduanmu commented on issue #13009: Some questions about AUTO_INTERVAL for Autotable

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


   @linghengqian Thank you for your feedback, @tuichenchuxin will track 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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] linghengqian commented on issue #13009: Some questions about AUTO_INTERVAL for Autotable

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


   In my opinion, it is not appropriate to rely only on the unfixed number of digits at the end of the real table to judge the incoming real table. 
   Set the prefix to the logical table, which is an easy solution I experimented with locally.
   Is there any plan for datetime-upper and datetime-lower to be adapted to yyyy-MM-dd HH:mm:ss.SSS in subsequent versions?


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] strongduanmu closed issue #13009: Some questions about AUTO_INTERVAL for Autotable

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


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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