You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/26 07:13:44 UTC

[shardingsphere] branch master updated: Simplify the logic processing of IntervalShardingAlgorithm and update corresponding documents (#17963)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f2d6cc22f38 Simplify the logic processing of IntervalShardingAlgorithm and update corresponding documents (#17963)
f2d6cc22f38 is described below

commit f2d6cc22f386f7245598d1041fbf2a7711274701
Author: Ling Hengqian <li...@outlook.com>
AuthorDate: Thu May 26 15:13:37 2022 +0800

    Simplify the logic processing of IntervalShardingAlgorithm and update corresponding documents (#17963)
    
    * Remove JapaneseDate related context in IntervalShardingAlgorithm due to JDK limitations.
    
    * - Use LocalDateTime#from instead of LocalDateTime#of in IntervalShardingAlgorithm.
    - Updated documentation for Interval Sharding Algorithm.
    
    * Fix Checkstyle.
    
    * Fix merge error.
---
 .../shardingsphere-jdbc/builtin-algorithm/sharding.cn.md | 16 ++++++++--------
 .../shardingsphere-jdbc/builtin-algorithm/sharding.en.md | 16 ++++++++--------
 .../sharding/datetime/IntervalShardingAlgorithm.java     |  8 ++++----
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.cn.md
index 5372104261b..afd102d9e06 100644
--- a/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.cn.md
@@ -84,14 +84,14 @@ Apache ShardingSphere 内置的标准分片算法实现类包括:
 
 可配置属性:
 
-| *属性名称*                    | *数据类型* | *说明*                                                                                                            | *默认值* |
-| ---------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------- | ------- |
-| datetime-pattern             | String   | 分片键的时间戳格式,必须遵循 Java DateTimeFormatter 的格式。例如:yyyy-MM-dd HH:mm:ss                                    |         |
-| datetime-lower               | String   | 时间分片下界值,格式与 `datetime-pattern` 定义的时间戳格式一致                                                           |         |
-| datetime-upper (?)           | String   | 时间分片上界值,格式与 `datetime-pattern` 定义的时间戳格式一致                                                           | 当前时间 |
-| sharding-suffix-pattern      | String   | 分片数据源或真实表的后缀格式,必须遵循 Java DateTimeFormatter 的格式,必须和 `datetime-interval-unit` 保持一致。例如:yyyyMM |         |
-| datetime-interval-amount (?) | int      | 分片键时间间隔,超过该时间间隔将进入下一分片                                                                             | 1       |
-| datetime-interval-unit (?)   | String   | 分片键时间间隔单位,必须遵循 Java ChronoUnit 的枚举值。例如:MONTHS                                                      | DAYS    |
+| *属性名称*                    | *数据类型* | *说明*                                                                                                                                                             | *默认值* |
+| ---------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------- |
+| datetime-pattern             | String   | 分片键的时间戳格式,必须遵循 Java DateTimeFormatter 的格式。例如:yyyy-MM-dd HH:mm:ss,yyyy-MM-dd 或 HH:mm:ss 等。但不支持与 `java.time.chrono.JapaneseDate` 相关的 Gy-MM 等   |         |
+| datetime-lower               | String   | 时间分片下界值,格式与 `datetime-pattern` 定义的时间戳格式一致                                                                                                            |         |
+| datetime-upper (?)           | String   | 时间分片上界值,格式与 `datetime-pattern` 定义的时间戳格式一致                                                                                                            | 当前时间 |
+| sharding-suffix-pattern      | String   | 分片数据源或真实表的后缀格式,必须遵循 Java DateTimeFormatter 的格式,必须和 `datetime-interval-unit` 保持一致。例如:yyyyMM                                                   |         |
+| datetime-interval-amount (?) | int      | 分片键时间间隔,超过该时间间隔将进入下一分片                                                                                                                              | 1       |
+| datetime-interval-unit (?)   | String   | 分片键时间间隔单位,必须遵循 Java ChronoUnit 的枚举值。例如:MONTHS                                                                                                       | DAYS    |
 
 ## 复合分片算法
 
diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.en.md
index c0c77a37c14..b850e1010cf 100644
--- a/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.en.md
+++ b/docs/document/content/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding.en.md
@@ -85,14 +85,14 @@ Type: INTERVAL
 
 Attributes:
 
-| *Name*                       | *DataType* | *Description*                                                                                                                                                             | *Default Value* |
-| ---------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
-| datetime-pattern             | String     | Timestamp pattern of sharding value, must can be transformed to Java LocalDateTime. For example: yyyy-MM-dd HH:mm:ss                                                      | -               |
-| datetime-lower               | String     | Datetime sharding lower boundary, pattern is defined `datetime-pattern`                                                                                                   | -               |
-| datetime-upper (?)           | String     | Datetime sharding upper boundary, pattern is defined `datetime-pattern`                                                                                                   | Now             |
-| sharding-suffix-pattern      | String     | Suffix pattern of sharding data sources or tables, must can be transformed to Java LocalDateTime, must be consistent with `datetime-interval-unit`. For example: yyyyMM   | -               |
-| datetime-interval-amount (?) | int        | Interval of sharding value                                                                                                                                                | 1               |
-| datetime-interval-unit (?)   | String     | Unit of sharding value interval, must can be transformed to Java ChronoUnit's Enum value. For example: MONTHS                                                             | DAYS            |
+| *Name*                       | *DataType* | *Description*                                                                                                                                                                                                                   | *Default Value* |
+| ---------------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| --------------- |
+| datetime-pattern             | String     | Timestamp pattern of sharding value, must can be transformed to Java LocalDateTime. For example: yyyy-MM-dd HH:mm:ss, yyyy-MM-dd or HH:mm:ss etc. But Gy-MM etc. related to `java.time.chrono.JapaneseDate` are not supported   | -               |
+| datetime-lower               | String     | Datetime sharding lower boundary, pattern is defined `datetime-pattern`                                                                                                                                                         | -               |
+| datetime-upper (?)           | String     | Datetime sharding upper boundary, pattern is defined `datetime-pattern`                                                                                                                                                         | Now             |
+| sharding-suffix-pattern      | String     | Suffix pattern of sharding data sources or tables, must can be transformed to Java LocalDateTime, must be consistent with `datetime-interval-unit`. For example: yyyyMM                                                         | -               |
+| datetime-interval-amount (?) | int        | Interval of sharding value                                                                                                                                                                                                      | 1               |
+| datetime-interval-unit (?)   | String     | Unit of sharding value interval, must can be transformed to Java ChronoUnit's Enum value. For example: MONTHS                                                                                                                   | DAYS            |
 
 ## Complex Sharding Algorithm
 
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
index d6ca8dd31ff..167b23ec20c 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
@@ -171,9 +171,9 @@ public final class IntervalShardingAlgorithm implements StandardShardingAlgorith
             }
             return result;
         }
-        LocalDateTime calculateTimeAsView = LocalDateTime.of(calculateTime.query(TemporalQueries.localDate()), calculateTime.query(TemporalQueries.localTime()));
-        LocalDateTime dateTimeUpperAsLocalDateTime = LocalDateTime.of(dateTimeUpperAsLocalDate, dateTimeUpperAsLocalTime);
-        LocalDateTime dateTimeLowerAsLocalDateTime = LocalDateTime.of(dateTimeLowerAsLocalDate, dateTimeLowerAsLocalTime);
+        LocalDateTime calculateTimeAsView = LocalDateTime.from(calculateTime);
+        LocalDateTime dateTimeUpperAsLocalDateTime = LocalDateTime.from(dateTimeUpper);
+        LocalDateTime dateTimeLowerAsLocalDateTime = LocalDateTime.from(dateTimeLower);
         while (!calculateTimeAsView.isAfter(dateTimeUpperAsLocalDateTime)) {
             if (hasIntersection(Range.closedOpen(calculateTimeAsView, calculateTimeAsView.plus(stepAmount, stepUnit)), range, dateTimeLowerAsLocalDateTime, dateTimeUpperAsLocalDateTime)) {
                 result.addAll(getMatchedTables(calculateTimeAsView, availableTargetNames));
@@ -249,7 +249,7 @@ public final class IntervalShardingAlgorithm implements StandardShardingAlgorith
             tableSuffix = viewAsLocalTime.format(tableSuffixPattern);
             return availableTargetNames.parallelStream().filter(each -> each.endsWith(tableSuffix)).collect(Collectors.toSet());
         }
-        tableSuffix = LocalDateTime.of(viewAsLocalDate, viewAsLocalTime).format(tableSuffixPattern);
+        tableSuffix = LocalDateTime.from(dateTime).format(tableSuffixPattern);
         return availableTargetNames.parallelStream().filter(each -> each.endsWith(tableSuffix)).collect(Collectors.toSet());
     }