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 b849cce82cd Add PipelineShardingColumnsExtractorTest (#37089)
b849cce82cd is described below

commit b849cce82cdeb2b6e955dbcb3fbe9e45ca8c06da
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Nov 13 20:38:35 2025 +0800

    Add PipelineShardingColumnsExtractorTest (#37089)
---
 AGENTS.md                                          |   4 +
 .../PipelineShardingColumnsExtractorTest.java      | 101 +++++++++++++++++++++
 2 files changed, 105 insertions(+)

diff --git a/AGENTS.md b/AGENTS.md
index 3022ccd1d88..4714b90b210 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -162,6 +162,10 @@ Mention which topology you target, the registry used, and 
any compatibility cons
 - Do not mock simple objects that can be instantiated directly with `new`.
 - Do not enable Mockito’s `RETURNS_DEEP_STUBS` unless unavoidable chained 
interactions make explicit stubs impractical; if you must enable it, mention 
the justification in the test description.
 
+## SPI Loader Usage
+- Cache services obtained through SPI loaders (`OrderedSPILoader`, 
`TypedSPILoader`, `DatabaseTypedSPILoader`, etc.) at the test-class or suite 
level whenever the same type is reused, so repeated lookups do not slow tests 
or introduce ordering surprises.
+- When multiple loader invocations require different keys (e.g., different 
database types), scope and document each cached instance per key instead of 
calling the loader inline inside every test.
+
 ## AI Self-Check Checklist (Pre-Submission Must-Do)
 1. Instruction precedence: `CODE_OF_CONDUCT.md` → user request → this guide → 
other docs. Are any conflicts unresolved?
 2. Are edited files minimal, include ASF headers, and pass Spotless?
diff --git 
a/kernel/data-pipeline/feature/sharding/src/test/java/org/apache/shardingsphere/data/pipeline/sharding/PipelineShardingColumnsExtractorTest.java
 
b/kernel/data-pipeline/feature/sharding/src/test/java/org/apache/shardingsphere/data/pipeline/sharding/PipelineShardingColumnsExtractorTest.java
new file mode 100644
index 00000000000..d54f95e150e
--- /dev/null
+++ 
b/kernel/data-pipeline/feature/sharding/src/test/java/org/apache/shardingsphere/data/pipeline/sharding/PipelineShardingColumnsExtractorTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.sharding;
+
+import 
org.apache.shardingsphere.data.pipeline.core.importer.PipelineRequiredColumnsExtractor;
+import 
org.apache.shardingsphere.infra.metadata.identifier.ShardingSphereIdentifier;
+import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
+import 
org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlComplexShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlStandardShardingStrategyConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class PipelineShardingColumnsExtractorTest {
+    
+    @SuppressWarnings("unchecked")
+    private final 
PipelineRequiredColumnsExtractor<YamlShardingRuleConfiguration> extractor = 
OrderedSPILoader.getServicesByClass(
+            PipelineRequiredColumnsExtractor.class, 
Collections.singleton(YamlShardingRuleConfiguration.class)).get(YamlShardingRuleConfiguration.class);
+    
+    @Test
+    void assertGetTableAndRequiredColumnsMap() {
+        YamlShardingRuleConfiguration yamlConfig = new 
YamlShardingRuleConfiguration();
+        
yamlConfig.setDefaultDatabaseStrategy(createYAMLStandardStrategyConfiguration("default_db_col"));
+        
yamlConfig.setDefaultTableStrategy(createYAMLStandardStrategyConfiguration("default_tbl_col"));
+        yamlConfig.getTables().put("t_explicit", 
getYamlExplicitTableRuleConfiguration());
+        yamlConfig.getTables().put("t_default", 
getYamlTableRuleConfiguration("t_default"));
+        yamlConfig.getTables().put("t_ignored", 
getYamlTableRuleConfiguration("t_ignored"));
+        yamlConfig.getAutoTables().put("t_auto", 
getYamlShardingAutoTableRuleConfiguration("t_auto"));
+        yamlConfig.getAutoTables().put("t_ignored_auto", 
getYamlShardingAutoTableRuleConfiguration("t_ignored_auto"));
+        Collection<ShardingSphereIdentifier> logicTables = Arrays.asList(
+                new ShardingSphereIdentifier("t_explicit"), new 
ShardingSphereIdentifier("t_default"), new ShardingSphereIdentifier("t_auto"));
+        Map<ShardingSphereIdentifier, Collection<String>> actual = 
extractor.getTableAndRequiredColumnsMap(yamlConfig, logicTables);
+        assertThat(actual.size(), is(3));
+        assertThat(actual.get(new ShardingSphereIdentifier("t_explicit")), 
containsInAnyOrder("user_id", "order_id", "item_id"));
+        assertThat(actual.get(new ShardingSphereIdentifier("t_default")), 
containsInAnyOrder("default_db_col", "default_tbl_col"));
+        assertTrue(actual.get(new 
ShardingSphereIdentifier("t_auto")).isEmpty());
+    }
+    
+    private YamlTableRuleConfiguration getYamlExplicitTableRuleConfiguration() 
{
+        YamlTableRuleConfiguration result = new YamlTableRuleConfiguration();
+        result.setLogicTable("t_explicit");
+        
result.setDatabaseStrategy(createYAMLComplexStrategyConfiguration("user_id,order_id"));
+        
result.setTableStrategy(createYAMLComplexStrategyConfiguration("item_id"));
+        return result;
+    }
+    
+    private YamlTableRuleConfiguration getYamlTableRuleConfiguration(final 
String tableName) {
+        YamlTableRuleConfiguration result = new YamlTableRuleConfiguration();
+        result.setLogicTable(tableName);
+        return result;
+    }
+    
+    private YamlShardingAutoTableRuleConfiguration 
getYamlShardingAutoTableRuleConfiguration(final String tableName) {
+        YamlShardingAutoTableRuleConfiguration result = new 
YamlShardingAutoTableRuleConfiguration();
+        result.setLogicTable(tableName);
+        return result;
+    }
+    
+    private YamlShardingStrategyConfiguration 
createYAMLStandardStrategyConfiguration(final String column) {
+        YamlShardingStrategyConfiguration result = new 
YamlShardingStrategyConfiguration();
+        YamlStandardShardingStrategyConfiguration standard = new 
YamlStandardShardingStrategyConfiguration();
+        standard.setShardingColumn(column);
+        result.setStandard(standard);
+        return result;
+    }
+    
+    private YamlShardingStrategyConfiguration 
createYAMLComplexStrategyConfiguration(final String columns) {
+        YamlShardingStrategyConfiguration result = new 
YamlShardingStrategyConfiguration();
+        YamlComplexShardingStrategyConfiguration complex = new 
YamlComplexShardingStrategyConfiguration();
+        complex.setShardingColumns(columns);
+        result.setComplex(complex);
+        return result;
+    }
+}

Reply via email to