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 2022/07/28 07:19:13 UTC

[GitHub] [shardingsphere] linghengqian opened a new issue, #19636: IntervalShardingAlgorithm will throw ClassCastException when shard key is String in `MM` date format

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

   ## Bug Report
   
   **For English only**, other languages will not accept.
   
   Before report a bug, make sure you have:
   
   - 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**.
   
   Please answer these questions before submitting your issue. Thanks!
   
   ### Which version of ShardingSphere did you use?
   
   https://github.com/apache/shardingsphere/commit/7ee0d0baa3143ae35807733e9359567e2cacbd93
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-JDBC
   
   ### Expected behavior
   
   In `org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithmTest` , the unit test modified as follows should execute normally.
   
   ```
   @Test
       public void assertIntegerInJDBCType() {
           Collection<String> actualAsYear = shardingAlgorithmByYear.doSharding(availableTablesForYearDataSources,
                   new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed(Year.of(2001), Year.of(2013))));
           assertThat(actualAsYear.size(), is(7));
           Collection<String> actualAsYearMonth = shardingAlgorithmByYearMonth.doSharding(availableTablesForYearMonthDataSources,
                   new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed(YearMonth.of(2016, 1), YearMonth.of(2020, 1))));
           assertThat(actualAsYearMonth.size(), is(3));
           Collection<String> actualAsMonth = shardingAlgorithmByMonthInJSR310.doSharding(availableTablesForMonthInJSR310DataSources,
                   new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed(Month.of(4), Month.of(10))));
           assertThat(actualAsMonth.size(), is(4));
           Collection<String> actualAsMonthString = shardingAlgorithmByMonthInJSR310.doSharding(availableTablesForMonthInJSR310DataSources,
                   new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed("04", "10")));
           assertThat(actualAsMonthString.size(), is(4));
       }
   ```
   
   ### Actual behavior
   
   - Throw an exception.
   ```
   java.lang.ClassCastException: java.lang.String cannot be cast to java.time.Month
   
   	at org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm.parseMonth(IntervalShardingAlgorithm.java:320)
   	at org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm.hasIntersection(IntervalShardingAlgorithm.java:286)
   	at org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm.doShardingInMonth(IntervalShardingAlgorithm.java:227)
   	at org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm.doSharding(IntervalShardingAlgorithm.java:156)
   	at org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm.doSharding(IntervalShardingAlgorithm.java:140)
   	at org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithmTest.assertIntegerInJDBCType(IntervalShardingAlgorithmTest.java:447)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
   	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
   	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
   	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
   	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
   	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
   	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
   	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
   	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
   	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
   	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
   	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
   	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
   	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
   	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
   	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
   	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
   	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
   	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
   	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
   	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
   ```
   
   ### Reason analyze (If you can)
   
   - In https://github.com/apache/shardingsphere/pull/19139, `parseMonth()` does not take strings into account.
   - This is because JDK 8 does not have the `java.time.Month#parse` method.
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   ### 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.

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

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


[GitHub] [shardingsphere] linghengqian commented on issue #19636: IntervalShardingAlgorithm will throw ClassCastException when shard key is String in `MM` date format

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

   I am working on 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.

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

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


[GitHub] [shardingsphere] terrymanu closed issue #19636: IntervalShardingAlgorithm will throw ClassCastException when shard key is String in `MM` date format

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #19636: IntervalShardingAlgorithm will throw ClassCastException when shard key is String in `MM` date format
URL: https://github.com/apache/shardingsphere/issues/19636


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