This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 944eb30a931 Reject none sharding strategy on auto tables in rule
validation (#39869)
944eb30a931 is described below
commit 944eb30a931a226e8e67c76a9245926ff3f9e27a
Author: Eunbin Son <[email protected]>
AuthorDate: Mon Oct 5 15:49:54 2026 +0900
Reject none sharding strategy on auto tables in rule validation (#39869)
* Reject sharding auto table without sharding strategy in rule checker
* Reject none sharding strategy on auto tables in rule validation
Rule configuration checks moved to Bean Validation, where @NotNull already
rejects an auto table without a sharding strategy. The none strategy still
passed isShardingStrategyValid, so reject it for auto tables in
ShardingRuleConfigurationValidator instead of the rule checker.
* Combine auto table strategy conditions on one line
Both conditions fit within 200 characters on a single continuation line, as
required by the line-wrapping rule.
---
RELEASE-NOTES.md | 1 +
.../api/config/validator/ShardingRuleConfigurationValidator.java | 6 +++++-
.../sharding/api/config/ShardingRuleConfigurationTest.java | 5 ++++-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 23fc5a650ef..143b8736dc8 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -105,6 +105,7 @@
1. Sharding: Include auto tables in ShardingRuleConfiguration logic table
names - [#39854](https://github.com/apache/shardingsphere/pull/39854)
1. Sharding: Fix NULL ordering when merging ORDER BY results for ClickHouse
and Presto - [#40014](https://github.com/apache/shardingsphere/issues/40014)
1. Sharding: Rewrite generated ORDER BY column owners to actual table names -
[#39866](https://github.com/apache/shardingsphere/pull/39866)
+1. Sharding: Reject sharding auto table configured with none sharding strategy
- [#39869](https://github.com/apache/shardingsphere/pull/39869)
1. Readwrite-splitting: Evaluate inline expressions in data source names of
rule configuration checker -
[#39374](https://github.com/apache/shardingsphere/pull/39374)
1. SQL Federation: Fix SQL Federation pagination binding for long LIMIT
parameters - [#39237](https://github.com/apache/shardingsphere/pull/39237)
1. Broadcast: Fix case-sensitive table name lookup in broadcast data node rule
attribute - [#39153](https://github.com/apache/shardingsphere/pull/39153)
diff --git
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/validator/ShardingRuleConfigurationValidator.java
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/validator/ShardingRuleConfigurationValidator.java
index fd32b06e1fd..11369ea92c7 100644
---
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/validator/ShardingRuleConfigurationValidator.java
+++
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/validator/ShardingRuleConfigurationValidator.java
@@ -53,7 +53,11 @@ public final class ShardingRuleConfigurationValidator
implements ConstraintValid
private boolean areAutoTablesValid(final ShardingRuleConfiguration
ruleConfig, final ConstraintValidatorContext context) {
return ruleConfig.getAutoTables().stream().noneMatch(each ->
!isAuditStrategyValid(each.getAuditStrategy(), "autoTables", ruleConfig,
context)
- || !isShardingStrategyValid(each.getShardingStrategy(),
"autoTables", ruleConfig, context));
+ ||
!isAutoTableShardingStrategyValid(each.getShardingStrategy(), context) ||
!isShardingStrategyValid(each.getShardingStrategy(), "autoTables", ruleConfig,
context));
+ }
+
+ private boolean isAutoTableShardingStrategyValid(final
ShardingStrategyConfiguration strategyConfig, final ConstraintValidatorContext
context) {
+ return !(strategyConfig instanceof NoneShardingStrategyConfiguration)
|| addViolation("autoTables", "requires a sharding strategy other than `none`",
context);
}
private boolean isKeyGenerateStrategyValid(final
KeyGenerateStrategyConfiguration strategyConfig, final String propertyName,
diff --git
a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfigurationTest.java
b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfigurationTest.java
index 78f144f9b7a..8cb9a7a8404 100644
---
a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfigurationTest.java
+++
b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfigurationTest.java
@@ -32,6 +32,8 @@ import
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAudi
import
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ComplexShardingStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration;
+import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
+import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -263,6 +265,7 @@ class ShardingRuleConfigurationTest {
Arguments.of("Blank auto table logic name",
createRuleConfiguration(createAutoTableRuleConfiguration("", new
HintShardingStrategyConfiguration("foo_hint")))),
Arguments.of("Null auto table strategy",
createRuleConfiguration(nullAutoTableStrategy)),
Arguments.of("Invalid auto table strategy",
createRuleConfiguration(invalidAutoTableStrategy)),
+ Arguments.of("None auto table strategy",
createRuleConfiguration(createAutoTableRuleConfiguration("foo_auto_tbl", new
NoneShardingStrategyConfiguration()))),
Arguments.of("Invalid auto table audit strategy",
createRuleConfiguration(invalidAutoTableAuditStrategy)),
Arguments.of("Blank binding table group name",
createRuleConfiguration(new ShardingTableReferenceRuleConfiguration("",
"foo_tbl,foo_item"))),
Arguments.of("Blank binding table group reference",
createRuleConfiguration(new
ShardingTableReferenceRuleConfiguration("foo_group", ""))),
@@ -348,7 +351,7 @@ class ShardingRuleConfigurationTest {
return createAutoTableRuleConfiguration("foo_auto_tbl", new
HintShardingStrategyConfiguration("foo_hint"));
}
- private static ShardingAutoTableRuleConfiguration
createAutoTableRuleConfiguration(final String logicTable, final
HintShardingStrategyConfiguration strategyConfig) {
+ private static ShardingAutoTableRuleConfiguration
createAutoTableRuleConfiguration(final String logicTable, final
ShardingStrategyConfiguration strategyConfig) {
ShardingAutoTableRuleConfiguration result = new
ShardingAutoTableRuleConfiguration(logicTable, null);
result.setShardingStrategy(strategyConfig);
return result;