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/05/17 14:36:55 UTC

[GitHub] [shardingsphere] linghengqian opened a new issue, #17752: IntervalShardingAlgorithm needs to support more JSR-310

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

   ## Feature Request
   
   **For English only**, other languages will not accept.
   
   Please pay attention on issues you submitted, because we maybe need more details. 
   If no response anymore and we cannot make decision by current information, we will **close it**.
   
   Please answer these questions before submitting your issue. Thanks!
   
   ### Is your feature request related to a problem?
   No, but related to https://github.com/apache/shardingsphere/pull/16740 .
   ### Describe the feature you would like.
   
   - The current `IntervalShardingAlgorithm` does not support `java.time.Instant` and more about  JSR-310, which will cause trouble to the use of `Mybatis`.
   
   - because for Mybatis `3.5.9`, the built-in typeHandlers in the typeHandlers that can convert the `JDBC type` of `TIMESTAMP` can be converted to `java.util.Date`, `java.sql.Timestamp`, `java.time.Instant`, `java.time.LocalDateTime`, `java.time.OffsetDateTime`, `java.time.ZonedDateTime` . 
   
   - Refer to https://mybatis.org/mybatis-3/zh/configuration.html#typeHandlers.
   


-- 
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] complone commented on issue #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

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

   > * My intuitive understanding is that once we decide to introduce a class like `java.time.LocalDate` in `IntervalShardingAlgorithm`, the corresponding `JDBC Type` is not a `Timestamp` class, then `LocalDateTime` should not be forced to be defined in `IntervalShardingAlgorithm`, but with the help of Its superclass or specific interface to help us deal with incoming classes, which more needs to take into account the ` private static final String DATE_TIME_PATTERN_KEY = "datetime-pattern";` in the configuration.
   > * update: It seems that [Support for advanced IntervalShardingAlgorithm #17814](https://github.com/apache/shardingsphere/issues/17814) is trying to do string matching on the datetime-pattern or actualdatanodes of IntervalShardingAlgorithm, I would like to see his approach first and then deal with the string matching problem of this issue.
   
   @linghengqian
   By reading the issue, I sorted out some key information
   For example, there are some new APIs in Java8, LocalDate, LocalTime, LocalDateTime
   But by default, the time and date of java8 is not supported in mybatis
   
   The general approach is based on the different typehandlers provided by mybatis based on the package mybatis-typehandlers-jsr310
   Complete the conversion of various java types to mysql types, but the principle of typehandler is
   Based on a registered factory for the TypeHandlerRegistry class, the commonly used converters are initialized by default in this class,
   There are the following two Maps in the member variables, among which JDBC_TYPE_HANDLER_MAP This map is for the conversion of jdbc to Java class,
   
   
   After looking around I think LocalDateTime is a superior abstraction of LocalDate
    There is an intermediary between ChronoLocalDateTime and ChronoLocalDateLocalTime to query the specific time point
    Termquery is a functional interface annotated with @FunctionalInterface
   Queries are key tools for extracting information from temporal objects. According to the strategy design pattern,
   The purpose is to externalize the query process, allowing different methods to be used
   Termquery: https://docs.oracle.com/javase/9/docs/api/java/time/temporal/TemporalQuery.html
   
   In order to mask the underlying details as much as possible, I found a solution based on java api Termquery.
   
   Here is an example of time transformation in graphsql: https://github.com/smallrye/smallrye-graphql/blob/main/server/implementation/src/main/java/io/smallrye/graphql/transformation/LegacyDateTransformer. java
   
   Hope it helps your work
   
   


-- 
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 #17752: IntervalShardingAlgorithm needs to support more JSR-310

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

   @linghengqian Great suggestion, I also had the problem that the INTERVAL algorithm doesn't support LocalDate. 


-- 
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 #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm
URL: https://github.com/apache/shardingsphere/issues/17752


-- 
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] complone commented on issue #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

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

   Support for localdatetime, lcaldate and Localtime
   
   Can refer to [issue-5783](https://github.com/apache/dubbo/pull/5783])


-- 
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 #17752: IntervalShardingAlgorithm needs to support more JSR-310

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

   Waiting for your good news.


-- 
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 #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

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

   - My intuitive understanding is that once we decide to introduce a class like `java.time.LocalDate` in `IntervalShardingAlgorithm`, the corresponding `JDBC Type` is not a `Timestamp` class, then `LocalDateTime` should not be forced to be defined in `IntervalShardingAlgorithm`, but with the help of Its superclass or specific interface to help us deal with incoming classes, which more needs to take into account the ` private static final String DATE_TIME_PATTERN_KEY = "datetime-pattern";` in the configuration.


-- 
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 #17752: IntervalShardingAlgorithm needs to support more JSR-310

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

   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] linghengqian commented on issue #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

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

   > @linghengqian Support for localdatetime, lcaldate and Localtime
   > 
   > Can refer to [issue-5783](https://github.com/apache/dubbo/pull/5783%5D)
   
   Thank you for your help, but the conversion of `IntervalShardingAlgorithm` seems meaningless, because `Localdate` is forced to `Localdatetime`, `Localtime` can only get `LocalTime.MIN`, and the `LocalTime.MAX` of the lower bound of `Guava`'s `Range` also needs an additional flag, which does not seem to be appropriate s Choice.


-- 
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 #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

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

   - I've noticed that when `IntervalShardingAlgorithm` and `LocalDateTime` are strongly coupled to properties other than the incoming value, this is a difficult thing for me to deal with due to my lack of experience dealing with the common parent class of `LocalDateTime` and `LocalDate`. Hope some friends can help improve the design of `org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm`. There is still a lack of support for the following classes.
       - `java.time.LocalDate`(JDBC Type is Date in Mybatis)
       - `java.time.LocalTime`(JDBC Type is Time in Mybatis)
       - `java.time.OffsetTime`(JDBC Type is Time in Mybatis)
       - `java.time.Year`(JDBC Type is INTEGER in Mybatis)
       - `java.time.Month`(JDBC Type is INTEGER in Mybatis)
       - `java.time.YearMonth`(JDBC Type is VARCHAR or LONGVARCHAR in Mybatis) 
       - `java.time.chrono.JapaneseDate`(JDBC Type is Date in Mybatis) 


-- 
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 #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

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

   - @complone  Thank you very much for your help! 
   
   - Through the introduction of the `java.time.temporal.TemporalQueries` class, the support of four JSR-310 related classes has been successfully introduced into the `IntervalShardingAlgorithm`, namely `java.time.LocalTime`, `java.time.OffsetTime`, `java.time.LocalDate`, `java.time.chrono.JapaneseDate`.
   
   - Due to my unfamiliarity with `java.time.chrono.JapaneseDate`, its `DateTimeFormatter` looks like `DateTimeFormatter.ofPattern("Gy年MM月dd日")`. Under the premise of the Japanese calendar system, I can't build a unit test, I hope a friend can make it up.
   
   - In addition, since `TemporalQueries` does not specify more implementations (at least not from the perspective of JDK 8), the following JSR-310 related classes are still not supported in `IntervalShardingAlgorithm` for Mybatis.
       - `java.time.Year` (JDBC Type is INTEGER in Mybatis)
       - `java.time.Month` (JDBC Type is INTEGER in Mybatis)
       - `java.time.YearMonth` (JDBC Type is VARCHAR or LONGVARCHAR in Mybatis)
   - Hope some friends can submit additional PR.


-- 
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 #17752: Add support for more JSR-310 related classes in IntervalShardingAlgorithm

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

   @terrymanu There are still unprocessed JSR-310 classes, can I reopen 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