This is an automated email from the ASF dual-hosted git repository.
panjuan 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 3433cb3 Shadow route optimization (#13669)
3433cb3 is described below
commit 3433cb37f28cb67add37cd3504da44c72070781a
Author: gin <[email protected]>
AuthorDate: Wed Nov 17 21:04:26 2021 +0800
Shadow route optimization (#13669)
---
.../repository/MybatisShadowUserRepository.java | 2 +-
...plication-shadow-readwrite-splitting.properties | 4 +-
.../shadow/condition/ShadowDetermineCondition.java | 8 +--
.../algorithm/ColumnShadowAlgorithmDeterminer.java | 8 +--
.../dml/AbstractShadowDMLStatementRouteEngine.java | 84 +++++++++++++++-------
.../dml/ShadowDeleteStatementRoutingEngine.java | 57 +++++++++------
.../dml/ShadowInsertStatementRoutingEngine.java | 83 ++++++++++++---------
.../dml/ShadowSelectStatementRoutingEngine.java | 73 ++++++++++++-------
.../dml/ShadowUpdateStatementRoutingEngine.java | 57 +++++++++------
.../shardingsphere/shadow/rule/ShadowRule.java | 5 +-
.../ColumnShadowAlgorithmDeterminerTest.java | 8 +--
.../ShadowDeleteStatementRoutingEngineTest.java | 10 ---
.../ShadowInsertStatementRoutingEngineTest.java | 18 -----
.../ShadowSelectStatementRoutingEngineTest.java | 10 ---
.../ShadowUpdateStatementRoutingEngineTest.java | 12 ----
15 files changed, 242 insertions(+), 197 deletions(-)
diff --git
a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java
b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java
index 7308b02..e231e4b 100644
---
a/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java
+++
b/examples/example-core/example-spring-mybatis/src/main/java/org/apache/shardingsphere/example/core/mybatis/repository/MybatisShadowUserRepository.java
@@ -32,8 +32,8 @@ public interface MybatisShadowUserRepository extends
ShadowUserRepository {
@Override
default void createTableIfNotExists() throws SQLException {
- createTableIfNotExistsShadow();
createTableIfNotExistsNative();
+ createTableIfNotExistsShadow();
}
void createTableIfNotExistsNative();
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties
b/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties
index b6d66e1..bdadc4e 100644
---
a/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/shadow-example/shadow-spring-boot-mybatis-example/src/main/resources/application-shadow-readwrite-splitting.properties
@@ -43,8 +43,8 @@ spring.shardingsphere.datasource.shadow-read-ds.password=
spring.shardingsphere.rules.readwrite-splitting.load-balancers.round_robin.type=ROUND_ROBIN
-spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.write-data-source-name=write-ds
-spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.read-data-source-names=read-ds
+spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.write-data-source-name=shadow-data-source-write
+spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.read-data-source-names=shadow-data-source-read
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.load-balancer-name=round_robin
spring.shardingsphere.rules.shadow.enable=true
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
index d6bdf22..123906d 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
@@ -33,7 +33,7 @@ public final class ShadowDetermineCondition {
private final ShadowOperationType shadowOperationType;
- private final Collection<ShadowColumnCondition> shadowColumnConditions =
new LinkedList<>();
+ private ShadowColumnCondition shadowColumnCondition;
private final Collection<String> sqlComments = new LinkedList<>();
@@ -56,11 +56,11 @@ public final class ShadowDetermineCondition {
/**
* Initialize shadow column condition.
*
- * @param shadowColumnConditions shadow column conditions
+ * @param shadowColumnCondition shadow column condition
* @return shadow determine condition
*/
- public ShadowDetermineCondition initShadowColumnCondition(final
Collection<ShadowColumnCondition> shadowColumnConditions) {
- this.shadowColumnConditions.addAll(shadowColumnConditions);
+ public ShadowDetermineCondition initShadowColumnCondition(final
ShadowColumnCondition shadowColumnCondition) {
+ this.shadowColumnCondition = shadowColumnCondition;
return this;
}
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
index 7cb694e..c84380b 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminer.java
@@ -39,13 +39,7 @@ public final class ColumnShadowAlgorithmDeterminer
implements ShadowAlgorithmDet
@Override
public boolean isShadow(final ShadowDetermineCondition
shadowDetermineCondition, final ShadowRule shadowRule) {
- Collection<ShadowColumnCondition> shadowColumnConditions =
shadowDetermineCondition.getShadowColumnConditions();
- for (ShadowColumnCondition each : shadowColumnConditions) {
- if (isShadowColumn(each, shadowRule,
shadowDetermineCondition.getTableName(),
shadowDetermineCondition.getShadowOperationType())) {
- return true;
- }
- }
- return false;
+ return
isShadowColumn(shadowDetermineCondition.getShadowColumnCondition(), shadowRule,
shadowDetermineCondition.getTableName(),
shadowDetermineCondition.getShadowOperationType());
}
private boolean isShadowColumn(final ShadowColumnCondition
shadowColumnCondition, final ShadowRule shadowRule, final String tableName,
final ShadowOperationType operationType) {
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/AbstractShadowDMLStatementRouteEngine.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/AbstractShadowDMLStatementRouteEngine.java
index 1fd4c7f..52cc958 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/AbstractShadowDMLStatementRouteEngine.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/AbstractShadowDMLStatementRouteEngine.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import java.util.Collection;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
@@ -55,12 +56,12 @@ public abstract class AbstractShadowDMLStatementRouteEngine
implements ShadowRou
return Optional.of(shadowRule.getAllShadowDataSourceMappings());
}
ShadowOperationType shadowOperationType = getShadowOperationType();
- for (String each : relatedShadowTables) {
- if (isShadowTable(each, shadowRule, shadowOperationType)) {
- return shadowRule.getRelatedShadowDataSourceMappings(each);
- }
+ Map<String, String> result = findBySQLComments(relatedShadowTables,
shadowRule, shadowOperationType);
+ if (!result.isEmpty()) {
+ return Optional.of(result);
}
- return Optional.empty();
+ result = findByShadowColumn(relatedShadowTables, shadowRule,
shadowOperationType);
+ return result.isEmpty() ? Optional.empty() : Optional.of(result);
}
private Collection<String> getRelatedShadowTables(final
Collection<SimpleTableSegment> simpleTableSegments, final ShadowRule
shadowRule) {
@@ -91,12 +92,15 @@ public abstract class AbstractShadowDMLStatementRouteEngine
implements ShadowRou
return false;
}
- private boolean isShadowTable(final String tableName, final ShadowRule
shadowRule, final ShadowOperationType shadowOperationType) {
- ShadowDetermineCondition shadowCondition = new
ShadowDetermineCondition(tableName, shadowOperationType);
- if (isContainsShadowInSQLComments(tableName, shadowRule,
shadowCondition)) {
- return true;
+ private Map<String, String> findBySQLComments(final Collection<String>
relatedShadowTables, final ShadowRule shadowRule, final ShadowOperationType
shadowOperationType) {
+ Map<String, String> result = new LinkedHashMap<>();
+ for (String each : relatedShadowTables) {
+ if (isContainsShadowInSQLComments(each, shadowRule, new
ShadowDetermineCondition(each, shadowOperationType))) {
+
result.putAll(shadowRule.getRelatedShadowDataSourceMappings(each));
+ return result;
+ }
}
- return isContainsShadowInColumns(tableName, shadowRule,
shadowCondition);
+ return result;
}
private boolean isContainsShadowInSQLComments(final String tableName,
final ShadowRule shadowRule, final ShadowDetermineCondition shadowCondition) {
@@ -117,9 +121,39 @@ public abstract class
AbstractShadowDMLStatementRouteEngine implements ShadowRou
return
ShadowDeterminerFactory.newInstance(hintShadowAlgorithm).isShadow(shadowCondition,
shadowRule);
}
- private boolean isContainsShadowInColumns(final String tableName, final
ShadowRule shadowRule, final ShadowDetermineCondition shadowCondition) {
- return shadowRule.getRelatedColumnShadowAlgorithms(tableName,
shadowCondition.getShadowOperationType()).filter(shadowAlgorithms ->
parseShadowColumnConditions()
- .filter(columnConditions ->
isMatchAnyColumnShadowAlgorithms(shadowAlgorithms,
shadowCondition.initShadowColumnCondition(columnConditions),
shadowRule)).isPresent()).isPresent();
+ private Map<String, String> findByShadowColumn(final Collection<String>
relatedShadowTables, final ShadowRule shadowRule, final ShadowOperationType
shadowOperationType) {
+ Map<String, String> result = new LinkedHashMap<>();
+ Iterator<Optional<ShadowColumnCondition>> iterator =
getShadowColumnConditionIterator();
+ while (iterator.hasNext()) {
+ Optional<ShadowColumnCondition> next = iterator.next();
+ if (!next.isPresent()) {
+ continue;
+ }
+ Optional<String> shadowTable =
findShadowTableByShadowColumn(relatedShadowTables, shadowRule, next.get(),
shadowOperationType);
+ if (!shadowTable.isPresent()) {
+ continue;
+ }
+
result.putAll(shadowRule.getRelatedShadowDataSourceMappings(shadowTable.get()));
+ return result;
+ }
+ return result;
+ }
+
+ private Optional<String> findShadowTableByShadowColumn(final
Collection<String> relatedShadowTables, final ShadowRule shadowRule, final
ShadowColumnCondition shadowColumnCondition,
+ final
ShadowOperationType shadowOperationType) {
+ ShadowDetermineCondition shadowDetermineCondition;
+ for (String each : relatedShadowTables) {
+ shadowDetermineCondition = new ShadowDetermineCondition(each,
shadowOperationType);
+ if (isContainsShadowInColumn(each, shadowRule,
shadowDetermineCondition.initShadowColumnCondition(shadowColumnCondition))) {
+ return Optional.of(each);
+ }
+ }
+ return Optional.empty();
+ }
+
+ private boolean isContainsShadowInColumn(final String tableName, final
ShadowRule shadowRule, final ShadowDetermineCondition shadowCondition) {
+ Optional<Collection<ColumnShadowAlgorithm<Comparable<?>>>>
relatedColumnShadowAlgorithms =
shadowRule.getRelatedColumnShadowAlgorithms(tableName,
shadowCondition.getShadowOperationType());
+ return relatedColumnShadowAlgorithms.isPresent() &&
isMatchAnyColumnShadowAlgorithms(relatedColumnShadowAlgorithms.get(),
shadowCondition, shadowRule);
}
private boolean isMatchAnyColumnShadowAlgorithms(final
Collection<ColumnShadowAlgorithm<Comparable<?>>> shadowAlgorithms, final
ShadowDetermineCondition shadowCondition,
@@ -137,32 +171,32 @@ public abstract class
AbstractShadowDMLStatementRouteEngine implements ShadowRou
}
/**
- * Parse shadow column conditions.
+ * Get all tables.
*
- * @return shadow column condition
+ * @return all tables
*/
- protected abstract Optional<Collection<ShadowColumnCondition>>
parseShadowColumnConditions();
+ protected abstract Collection<SimpleTableSegment> getAllTables();
/**
- * Parse SQL Comments.
+ * get shadow operation type.
*
- * @return SQL comments
+ * @return shadow operation type
*/
- protected abstract Optional<Collection<String>> parseSQLComments();
+ protected abstract ShadowOperationType getShadowOperationType();
/**
- * get shadow operation type.
+ * Parse SQL Comments.
*
- * @return shadow operation type
+ * @return SQL comments
*/
- protected abstract ShadowOperationType getShadowOperationType();
+ protected abstract Optional<Collection<String>> parseSQLComments();
/**
- * Get all tables.
+ * Get shadow column condition iterator.
*
- * @return all tables
+ * @return shadow column condition iterator
*/
- protected abstract Collection<SimpleTableSegment> getAllTables();
+ protected abstract Iterator<Optional<ShadowColumnCondition>>
getShadowColumnConditionIterator();
/**
* Get single table tame.
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngine.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngine.java
index 88ee98d..aae5cce 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngine.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngine.java
@@ -23,11 +23,11 @@ import
org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionExtractUtil;
import java.util.Collection;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -43,26 +43,6 @@ public final class ShadowDeleteStatementRoutingEngine
extends AbstractShadowDMLS
private final List<Object> parameters;
@Override
- protected Optional<Collection<ShadowColumnCondition>>
parseShadowColumnConditions() {
- Collection<ShadowColumnCondition> result = new LinkedList<>();
- deleteStatementContext.getWhere().ifPresent(whereSegment ->
parseWhereSegment(whereSegment, result));
- return result.isEmpty() ? Optional.empty() : Optional.of(result);
- }
-
- private void parseWhereSegment(final WhereSegment whereSegment, final
Collection<ShadowColumnCondition> shadowColumnConditions) {
-
ExpressionExtractUtil.getAndPredicates(whereSegment.getExpr()).forEach(each ->
parseAndPredicate(each.getPredicates(), shadowColumnConditions));
- }
-
- private void parseAndPredicate(final Collection<ExpressionSegment>
predicates, final Collection<ShadowColumnCondition> shadowColumnConditions) {
- predicates.forEach(each -> parseExpressionSegment(each,
shadowColumnConditions));
- }
-
- private void parseExpressionSegment(final ExpressionSegment
expressionSegment, final Collection<ShadowColumnCondition>
shadowColumnConditions) {
-
ShadowExtractor.extractColumn(expressionSegment).ifPresent(columnSegment ->
ShadowExtractor.extractValues(expressionSegment, parameters)
- .ifPresent(values -> shadowColumnConditions.add(new
ShadowColumnCondition(getSingleTableName(),
columnSegment.getIdentifier().getValue(), values))));
- }
-
- @Override
protected Collection<SimpleTableSegment> getAllTables() {
return deleteStatementContext.getAllTables();
}
@@ -78,4 +58,39 @@ public final class ShadowDeleteStatementRoutingEngine
extends AbstractShadowDMLS
deleteStatementContext.getSqlStatement().getCommentSegments().forEach(each ->
result.add(each.getText()));
return result.isEmpty() ? Optional.empty() : Optional.of(result);
}
+
+ @Override
+ protected Iterator<Optional<ShadowColumnCondition>>
getShadowColumnConditionIterator() {
+ return new ShadowColumnConditionIterator(parseWhereSegment(),
parameters);
+ }
+
+ private Collection<ExpressionSegment> parseWhereSegment() {
+ Collection<ExpressionSegment> result = new LinkedList<>();
+ deleteStatementContext.getWhere().ifPresent(whereSegment ->
ExpressionExtractUtil.getAndPredicates(whereSegment.getExpr()).forEach(each ->
result.addAll(each.getPredicates())));
+ return result;
+ }
+
+ private class ShadowColumnConditionIterator implements
Iterator<Optional<ShadowColumnCondition>> {
+
+ private final Iterator<ExpressionSegment> iterator;
+
+ private final List<Object> parameters;
+
+ ShadowColumnConditionIterator(final Collection<ExpressionSegment>
predicates, final List<Object> parameters) {
+ this.iterator = predicates.iterator();
+ this.parameters = parameters;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public Optional<ShadowColumnCondition> next() {
+ ExpressionSegment expressionSegment = iterator.next();
+ return
ShadowExtractor.extractColumn(expressionSegment).flatMap(segment ->
ShadowExtractor.extractValues(expressionSegment, parameters)
+ .map(values -> new
ShadowColumnCondition(getSingleTableName(), segment.getIdentifier().getValue(),
values)));
+ }
+ }
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngine.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngine.java
index f17ad63..136e484 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngine.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngine.java
@@ -39,38 +39,6 @@ public final class ShadowInsertStatementRoutingEngine
extends AbstractShadowDMLS
private final InsertStatementContext insertStatementContext;
@Override
- protected Optional<Collection<ShadowColumnCondition>>
parseShadowColumnConditions() {
- Collection<ShadowColumnCondition> result = new LinkedList<>();
- Iterator<String> columnNamesIt = parseColumnNames().iterator();
- List<InsertValueContext> insertValueContexts =
insertStatementContext.getInsertValueContexts();
- int index = 0;
- while (columnNamesIt.hasNext()) {
- String columnName = columnNamesIt.next();
- Optional<Collection<Comparable<?>>> columnValues =
getColumnValues(insertValueContexts, index);
- columnValues.ifPresent(values -> result.add(new
ShadowColumnCondition(getSingleTableName(), columnName, values)));
- index++;
- }
- return result.isEmpty() ? Optional.empty() : Optional.of(result);
- }
-
- private Optional<Collection<Comparable<?>>> getColumnValues(final
List<InsertValueContext> insertValueContexts, final int index) {
- Collection<Comparable<?>> result = new LinkedList<>();
- for (InsertValueContext each : insertValueContexts) {
- Object valueObject = each.getValue(index);
- if (valueObject instanceof Comparable<?>) {
- result.add((Comparable<?>) valueObject);
- } else {
- return Optional.empty();
- }
- }
- return result.isEmpty() ? Optional.empty() : Optional.of(result);
- }
-
- private Collection<String> parseColumnNames() {
- return insertStatementContext.getInsertColumnNames();
- }
-
- @Override
protected Collection<SimpleTableSegment> getAllTables() {
return insertStatementContext.getAllTables();
}
@@ -86,4 +54,55 @@ public final class ShadowInsertStatementRoutingEngine
extends AbstractShadowDMLS
insertStatementContext.getSqlStatement().getCommentSegments().forEach(each ->
result.add(each.getText()));
return result.isEmpty() ? Optional.empty() : Optional.of(result);
}
+
+ @Override
+ protected Iterator<Optional<ShadowColumnCondition>>
getShadowColumnConditionIterator() {
+ return new
ShadowColumnConditionIterator(parseColumnNames().iterator(),
insertStatementContext.getInsertValueContexts());
+ }
+
+ private Collection<String> parseColumnNames() {
+ return insertStatementContext.getInsertColumnNames();
+ }
+
+ private class ShadowColumnConditionIterator implements
Iterator<Optional<ShadowColumnCondition>> {
+
+ private int index;
+
+ private final Iterator<String> iterator;
+
+ private final List<InsertValueContext> insertValueContexts;
+
+ ShadowColumnConditionIterator(final Iterator<String> iterator, final
List<InsertValueContext> insertValueContexts) {
+ this.iterator = iterator;
+ this.insertValueContexts = insertValueContexts;
+ this.index = 0;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public Optional<ShadowColumnCondition> next() {
+ String columnName = iterator.next();
+ Optional<Collection<Comparable<?>>> columnValues =
getColumnValues(insertValueContexts, index);
+ index++;
+ return columnValues.map(values -> new
ShadowColumnCondition(getSingleTableName(), columnName, values));
+ }
+
+ private Optional<Collection<Comparable<?>>> getColumnValues(final
List<InsertValueContext> insertValueContexts, final int index) {
+ Collection<Comparable<?>> result = new LinkedList<>();
+ for (InsertValueContext each : insertValueContexts) {
+ Object valueObject = each.getValue(index);
+ if (valueObject instanceof Comparable<?>) {
+ result.add((Comparable<?>) valueObject);
+ } else {
+ return Optional.empty();
+ }
+ }
+ return result.isEmpty() ? Optional.empty() : Optional.of(result);
+ }
+ }
+
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngine.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngine.java
index c2e81ab..99d5bff 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngine.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngine.java
@@ -24,12 +24,12 @@ import
org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionExtractUtil;
import java.util.Collection;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -45,31 +45,6 @@ public final class ShadowSelectStatementRoutingEngine
extends AbstractShadowDMLS
private final List<Object> parameters;
@Override
- protected Optional<Collection<ShadowColumnCondition>>
parseShadowColumnConditions() {
- Collection<ShadowColumnCondition> result = new LinkedList<>();
- selectStatementContext.getWhere().ifPresent(whereSegment ->
parseWhereSegment(whereSegment, result));
- return result.isEmpty() ? Optional.empty() : Optional.of(result);
- }
-
- private void parseWhereSegment(final WhereSegment whereSegment, final
Collection<ShadowColumnCondition> shadowColumnConditions) {
-
ExpressionExtractUtil.getAndPredicates(whereSegment.getExpr()).forEach(each ->
parseAndPredicate(each.getPredicates(), shadowColumnConditions));
- }
-
- private void parseAndPredicate(final Collection<ExpressionSegment>
predicates, final Collection<ShadowColumnCondition> shadowColumnConditions) {
- predicates.forEach(each -> parseExpressionSegment(each,
shadowColumnConditions));
- }
-
- private void parseExpressionSegment(final ExpressionSegment
expressionSegment, final Collection<ShadowColumnCondition>
shadowColumnConditions) {
-
ShadowExtractor.extractColumn(expressionSegment).ifPresent(columnSegment ->
ShadowExtractor.extractValues(expressionSegment, parameters)
- .ifPresent(values -> shadowColumnConditions.add(new
ShadowColumnCondition(extractOwnerName(columnSegment),
columnSegment.getIdentifier().getValue(), values))));
- }
-
- private String extractOwnerName(final ColumnSegment columnSegment) {
- Optional<OwnerSegment> owner = columnSegment.getOwner();
- return owner.isPresent() ?
getTableAliasNameMappings().get(owner.get().getIdentifier().getValue()) :
getTableAliasNameMappings().keySet().iterator().next();
- }
-
- @Override
protected Collection<SimpleTableSegment> getAllTables() {
return selectStatementContext.getAllTables();
}
@@ -85,4 +60,50 @@ public final class ShadowSelectStatementRoutingEngine
extends AbstractShadowDMLS
selectStatementContext.getSqlStatement().getCommentSegments().forEach(each ->
result.add(each.getText()));
return result.isEmpty() ? Optional.empty() : Optional.of(result);
}
+
+ @Override
+ protected Iterator<Optional<ShadowColumnCondition>>
getShadowColumnConditionIterator() {
+ return new ShadowColumnConditionIterator(parseWhereSegment(),
parameters);
+ }
+
+ private Collection<ExpressionSegment> parseWhereSegment() {
+ Collection<ExpressionSegment> result = new LinkedList<>();
+ selectStatementContext.getWhere().ifPresent(whereSegment ->
ExpressionExtractUtil.getAndPredicates(whereSegment.getExpr()).forEach(each ->
result.addAll(each.getPredicates())));
+ return result;
+ }
+
+ private class ShadowColumnConditionIterator implements
Iterator<Optional<ShadowColumnCondition>> {
+
+ private final Iterator<ExpressionSegment> iterator;
+
+ private final List<Object> parameters;
+
+ ShadowColumnConditionIterator(final Collection<ExpressionSegment>
predicates, final List<Object> parameters) {
+ this.iterator = predicates.iterator();
+ this.parameters = parameters;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public Optional<ShadowColumnCondition> next() {
+ ExpressionSegment expressionSegment = iterator.next();
+ Optional<ColumnSegment> columnSegment =
ShadowExtractor.extractColumn(expressionSegment);
+ if (columnSegment.isPresent()) {
+ Optional<Collection<Comparable<?>>> values =
ShadowExtractor.extractValues(expressionSegment, parameters);
+ if (values.isPresent()) {
+ return Optional.of(new
ShadowColumnCondition(extractOwnerName(columnSegment.get()),
columnSegment.get().getIdentifier().getValue(), values.get()));
+ }
+ }
+ return Optional.empty();
+ }
+
+ private String extractOwnerName(final ColumnSegment columnSegment) {
+ Optional<OwnerSegment> owner = columnSegment.getOwner();
+ return owner.isPresent() ?
getTableAliasNameMappings().get(owner.get().getIdentifier().getValue()) :
getTableAliasNameMappings().keySet().iterator().next();
+ }
+ }
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngine.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngine.java
index e30dc72..0aeefd8 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngine.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngine.java
@@ -23,11 +23,11 @@ import
org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.route.engine.util.ShadowExtractor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionExtractUtil;
import java.util.Collection;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -43,26 +43,6 @@ public final class ShadowUpdateStatementRoutingEngine
extends AbstractShadowDMLS
private final List<Object> parameters;
@Override
- protected Optional<Collection<ShadowColumnCondition>>
parseShadowColumnConditions() {
- Collection<ShadowColumnCondition> result = new LinkedList<>();
- updateStatementContext.getWhere().ifPresent(whereSegment ->
parseWhereSegment(whereSegment, result));
- return result.isEmpty() ? Optional.empty() : Optional.of(result);
- }
-
- private void parseWhereSegment(final WhereSegment whereSegment, final
Collection<ShadowColumnCondition> shadowColumnConditions) {
-
ExpressionExtractUtil.getAndPredicates(whereSegment.getExpr()).forEach(each ->
parseAndPredicate(each.getPredicates(), shadowColumnConditions));
- }
-
- private void parseAndPredicate(final Collection<ExpressionSegment>
predicates, final Collection<ShadowColumnCondition> shadowColumnConditions) {
- predicates.forEach(each -> parseExpressionSegment(each,
shadowColumnConditions));
- }
-
- private void parseExpressionSegment(final ExpressionSegment
expressionSegment, final Collection<ShadowColumnCondition>
shadowColumnConditions) {
-
ShadowExtractor.extractColumn(expressionSegment).ifPresent(columnSegment ->
ShadowExtractor.extractValues(expressionSegment, parameters)
- .ifPresent(values -> shadowColumnConditions.add(new
ShadowColumnCondition(getSingleTableName(),
columnSegment.getIdentifier().getValue(), values))));
- }
-
- @Override
protected Collection<SimpleTableSegment> getAllTables() {
return updateStatementContext.getAllTables();
}
@@ -78,4 +58,39 @@ public final class ShadowUpdateStatementRoutingEngine
extends AbstractShadowDMLS
updateStatementContext.getSqlStatement().getCommentSegments().forEach(each ->
result.add(each.getText()));
return result.isEmpty() ? Optional.empty() : Optional.of(result);
}
+
+ @Override
+ protected Iterator<Optional<ShadowColumnCondition>>
getShadowColumnConditionIterator() {
+ return new ShadowColumnConditionIterator(parseWhereSegment(),
parameters);
+ }
+
+ private Collection<ExpressionSegment> parseWhereSegment() {
+ Collection<ExpressionSegment> result = new LinkedList<>();
+ updateStatementContext.getWhere().ifPresent(whereSegment ->
ExpressionExtractUtil.getAndPredicates(whereSegment.getExpr()).forEach(each ->
result.addAll(each.getPredicates())));
+ return result;
+ }
+
+ private class ShadowColumnConditionIterator implements
Iterator<Optional<ShadowColumnCondition>> {
+
+ private final Iterator<ExpressionSegment> iterator;
+
+ private final List<Object> parameters;
+
+ ShadowColumnConditionIterator(final Collection<ExpressionSegment>
predicates, final List<Object> parameters) {
+ this.iterator = predicates.iterator();
+ this.parameters = parameters;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public Optional<ShadowColumnCondition> next() {
+ ExpressionSegment expressionSegment = iterator.next();
+ return
ShadowExtractor.extractColumn(expressionSegment).flatMap(segment ->
ShadowExtractor.extractValues(expressionSegment, parameters)
+ .map(values -> new
ShadowColumnCondition(getSingleTableName(), segment.getIdentifier().getValue(),
values)));
+ }
+ }
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index 723f65a..a0a46bb 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -178,10 +178,9 @@ public final class ShadowRule implements SchemaRule,
DataSourceContainedRule {
* @param tableName table name
* @return shadow data source rules
*/
- public Optional<Map<String, String>>
getRelatedShadowDataSourceMappings(final String tableName) {
- Map<String, String> result =
shadowTableRules.get(tableName).getShadowDataSources().stream().map(shadowDataSourceMappings::get).filter(Objects::nonNull)
+ public Map<String, String> getRelatedShadowDataSourceMappings(final String
tableName) {
+ return
shadowTableRules.get(tableName).getShadowDataSources().stream().map(shadowDataSourceMappings::get).filter(Objects::nonNull)
.collect(Collectors.toMap(ShadowDataSourceRule::getSourceDataSource,
ShadowDataSourceRule::getShadowDataSource, (a, b) -> b, LinkedHashMap::new));
- return result.isEmpty() ? Optional.empty() : Optional.of(result);
}
/**
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
index 0152a09..458e1ef 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/algorithm/ColumnShadowAlgorithmDeterminerTest.java
@@ -106,15 +106,13 @@ public final class ColumnShadowAlgorithmDeterminerTest {
private ShadowDetermineCondition createShadowDetermineCondition() {
ShadowDetermineCondition result = new
ShadowDetermineCondition("t_order", ShadowOperationType.INSERT);
- result.initShadowColumnCondition(createColumnValuesMappings());
+ result.initShadowColumnCondition(createColumnValuesMapping());
return result;
}
- private Collection<ShadowColumnCondition> createColumnValuesMappings() {
- Collection<ShadowColumnCondition> result = new LinkedList<>();
+ private ShadowColumnCondition createColumnValuesMapping() {
Collection<Comparable<?>> values = new LinkedList<>();
values.add(1);
- result.add(new ShadowColumnCondition("t_order", "user_id", values));
- return result;
+ return new ShadowColumnCondition("t_order", "user_id", values);
}
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
index 537e02b..204542c 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
@@ -25,7 +25,6 @@ import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadow
import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
-import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -89,15 +88,6 @@ public final class ShadowDeleteStatementRoutingEngineTest {
routeUnits.add(new RouteUnit(new RouteMapper("ds", "ds_shadow"), new
LinkedList<>()));
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
shadowDeleteStatementRoutingEngine.route(routeContext, new
ShadowRule(createAlgorithmProvidedShadowRuleConfiguration()));
- Optional<Collection<ShadowColumnCondition>> shadowColumnConditions =
shadowDeleteStatementRoutingEngine.parseShadowColumnConditions();
- assertThat(shadowColumnConditions.isPresent(), is(true));
- Collection<ShadowColumnCondition> shadowColumns =
shadowColumnConditions.get();
- assertThat(shadowColumns.size(), is(1));
- Iterator<ShadowColumnCondition> iterator = shadowColumns.iterator();
- ShadowColumnCondition userId = iterator.next();
- assertThat(userId.getColumn(), is("user_id"));
- assertThat(userId.getOwner(), is("t_order"));
- assertThat(userId.getValues().iterator().next(), is("1"));
Optional<Collection<String>> sqlNotes =
shadowDeleteStatementRoutingEngine.parseSQLComments();
assertThat(sqlNotes.isPresent(), is(true));
assertThat(sqlNotes.get().size(), is(2));
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
index 382de1e..f434a90 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
@@ -26,7 +26,6 @@ import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadow
import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
-import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
@@ -94,23 +93,6 @@ public final class ShadowInsertStatementRoutingEngineTest {
routeUnits.add(new RouteUnit(new RouteMapper("ds", "ds_shadow"), new
LinkedList<>()));
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
shadowRouteEngine.route(routeContext, new
ShadowRule(createAlgorithmProvidedShadowRuleConfiguration()));
- Optional<Collection<ShadowColumnCondition>> shadowColumnConditions =
shadowRouteEngine.parseShadowColumnConditions();
- assertThat(shadowColumnConditions.isPresent(), is(true));
- Collection<ShadowColumnCondition> shadowColumns =
shadowColumnConditions.get();
- assertThat(shadowColumns.size(), is(3));
- Iterator<ShadowColumnCondition> iterator = shadowColumns.iterator();
- ShadowColumnCondition userId = iterator.next();
- assertThat(userId.getColumn(), is("user_id"));
- assertThat(userId.getOwner(), is("t_order"));
- assertThat(userId.getValues().iterator().next(), is("1"));
- ShadowColumnCondition orderCode = iterator.next();
- assertThat(orderCode.getColumn(), is("order_code"));
- assertThat(orderCode.getOwner(), is("t_order"));
- assertThat(orderCode.getValues().iterator().next(), is("orderCode"));
- ShadowColumnCondition orderName = iterator.next();
- assertThat(orderName.getColumn(), is("order_name"));
- assertThat(orderName.getOwner(), is("t_order"));
- assertThat(orderName.getValues().iterator().next(), is("orderName"));
Optional<Collection<String>> sqlNotes =
shadowRouteEngine.parseSQLComments();
assertThat(sqlNotes.isPresent(), is(true));
assertThat(sqlNotes.get().size(), is(2));
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
index d6fe9e5..599da20 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
@@ -25,7 +25,6 @@ import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadow
import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
-import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -89,15 +88,6 @@ public final class ShadowSelectStatementRoutingEngineTest {
routeUnits.add(new RouteUnit(new RouteMapper("ds", "ds_shadow"), new
LinkedList<>()));
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
shadowRouteEngine.route(routeContext, new
ShadowRule(createAlgorithmProvidedShadowRuleConfiguration()));
- Optional<Collection<ShadowColumnCondition>> shadowColumnConditions =
shadowRouteEngine.parseShadowColumnConditions();
- assertThat(shadowColumnConditions.isPresent(), is(true));
- Collection<ShadowColumnCondition> shadowColumns =
shadowColumnConditions.get();
- assertThat(shadowColumns.size(), is(1));
- Iterator<ShadowColumnCondition> iterator = shadowColumns.iterator();
- ShadowColumnCondition userId = iterator.next();
- assertThat(userId.getColumn(), is("user_id"));
- assertThat(userId.getOwner(), is("t_order"));
- assertThat(userId.getValues().iterator().next(), is("1"));
Optional<Collection<String>> sqlNotes =
shadowRouteEngine.parseSQLComments();
assertThat(sqlNotes.isPresent(), is(true));
assertThat(sqlNotes.get().size(), is(2));
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngineTest.java
index c5d4d9d..88d04d1 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowUpdateStatementRoutingEngineTest.java
@@ -25,8 +25,6 @@ import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadow
import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
-import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
@@ -89,16 +87,6 @@ public final class ShadowUpdateStatementRoutingEngineTest {
Collection<RouteUnit> routeUnits = new LinkedList<>();
routeUnits.add(new RouteUnit(new RouteMapper("ds", "ds_shadow"), new
LinkedList<>()));
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
- shadowRouteEngine.route(routeContext, new
ShadowRule(createAlgorithmProvidedShadowRuleConfiguration()));
- Optional<Collection<ShadowColumnCondition>> shadowColumnConditions =
shadowRouteEngine.parseShadowColumnConditions();
- assertTrue(shadowColumnConditions.isPresent());
- Collection<ShadowColumnCondition> shadowColumns =
shadowColumnConditions.get();
- assertThat(shadowColumns.size(), is(1));
- Iterator<ShadowColumnCondition> iterator = shadowColumns.iterator();
- ShadowColumnCondition userId = iterator.next();
- assertThat(userId.getColumn(), is("user_id"));
- assertThat(userId.getOwner(), is("t_order"));
- assertThat(userId.getValues().iterator().next(), is("1"));
Optional<Collection<String>> sqlNotes =
shadowRouteEngine.parseSQLComments();
assertTrue(sqlNotes.isPresent());
assertThat(sqlNotes.get().size(), is(2));