From 5623f0ce81b73f5916a4716fef7af5af4814fc2e Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 5 Nov 2024 23:12:21 +0800 Subject: [PATCH 1/6] Add ShadowDMLStatementDataSourceMappingsRetriever --- ...dowDataSourceMappingsRetrieverFactory.java | 38 ++++---- ...dowColumnDataSourceMappingsRetriever.java} | 39 ++------ ...eStatementDataSourceMappingsRetriever.java | 12 +-- ...tStatementDataSourceMappingsRetriever.java | 12 +-- ...tStatementDataSourceMappingsRetriever.java | 12 +-- ...eStatementDataSourceMappingsRetriever.java | 12 +-- ...LStatementDataSourceMappingsRetriever.java | 89 +++++++++++++++++++ ...ataSourceMappingsRetrieverFactoryTest.java | 13 ++- 8 files changed, 145 insertions(+), 82 deletions(-) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{dml/AbstractShadowDMLStatementDataSourceMappingsRetriever.java => column/ShadowColumnDataSourceMappingsRetriever.java} (62%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{dml => column}/ShadowDeleteStatementDataSourceMappingsRetriever.java (89%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{dml => column}/ShadowInsertStatementDataSourceMappingsRetriever.java (89%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{dml => column}/ShadowSelectStatementDataSourceMappingsRetriever.java (91%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{dml => column}/ShadowUpdateStatementDataSourceMappingsRetriever.java (90%) create mode 100644 features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactory.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactory.java index 44ca22b3b848b..a1bf5eddefade 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactory.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactory.java @@ -19,16 +19,17 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowDeleteStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowInsertStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowSelectStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowUpdateStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowDMLStatementDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.route.retriever.hint.ShadowHintDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.spi.ShadowOperationType; + +import java.util.Optional; /** * Shadow data source mappings retriever factory. @@ -43,22 +44,25 @@ public final class ShadowDataSourceMappingsRetrieverFactory { * @return created instance */ public static ShadowDataSourceMappingsRetriever newInstance(final QueryContext queryContext) { - if (queryContext.getSqlStatementContext() instanceof InsertStatementContext) { - return new ShadowInsertStatementDataSourceMappingsRetriever( - (InsertStatementContext) queryContext.getSqlStatementContext(), queryContext.getHintValueContext()); + Optional operationType = getShadowOperationType(queryContext.getSqlStatementContext()); + return operationType.isPresent() + ? new ShadowDMLStatementDataSourceMappingsRetriever(queryContext, operationType.get()) + : new ShadowHintDataSourceMappingsRetriever(queryContext.getHintValueContext()); + } + + private static Optional getShadowOperationType(final SQLStatementContext sqlStatementContext) { + if (sqlStatementContext instanceof InsertStatementContext) { + return Optional.of(ShadowOperationType.INSERT); } - if (queryContext.getSqlStatementContext() instanceof DeleteStatementContext) { - return new ShadowDeleteStatementDataSourceMappingsRetriever( - (DeleteStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); + if (sqlStatementContext instanceof DeleteStatementContext) { + return Optional.of(ShadowOperationType.DELETE); } - if (queryContext.getSqlStatementContext() instanceof UpdateStatementContext) { - return new ShadowUpdateStatementDataSourceMappingsRetriever( - (UpdateStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); + if (sqlStatementContext instanceof UpdateStatementContext) { + return Optional.of(ShadowOperationType.UPDATE); } - if (queryContext.getSqlStatementContext() instanceof SelectStatementContext) { - return new ShadowSelectStatementDataSourceMappingsRetriever( - (SelectStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), queryContext.getHintValueContext()); + if (sqlStatementContext instanceof SelectStatementContext) { + return Optional.of(ShadowOperationType.SELECT); } - return new ShadowHintDataSourceMappingsRetriever(queryContext.getHintValueContext()); + return Optional.empty(); } } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/AbstractShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowColumnDataSourceMappingsRetriever.java similarity index 62% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/AbstractShadowDMLStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowColumnDataSourceMappingsRetriever.java index f109c823db7ec..2bc8356391b46 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/AbstractShadowDMLStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowColumnDataSourceMappingsRetriever.java @@ -15,65 +15,38 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml; +package org.apache.shardingsphere.shadow.route.retriever.column; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; -import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.condition.ShadowCondition; import org.apache.shardingsphere.shadow.route.determiner.ColumnShadowAlgorithmDeterminer; import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.hint.ShadowTableHintDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.Map; /** - * Abstract shadow DML statement data source mappings retriever. + * Shadow column data source mappings retriever. */ @HighFrequencyInvocation -public abstract class AbstractShadowDMLStatementDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { +@RequiredArgsConstructor +public abstract class ShadowColumnDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { private final ShadowOperationType operationType; @Getter private final Map tableAliasAndNameMappings; - private final ShadowTableHintDataSourceMappingsRetriever tableHintDataSourceMappingsRetriever; - - protected AbstractShadowDMLStatementDataSourceMappingsRetriever(final SQLStatementContext sqlStatementContext, final HintValueContext hintValueContext, final ShadowOperationType operationType) { - this.operationType = operationType; - tableAliasAndNameMappings = getTableAliasAndNameMappings(((TableAvailable) sqlStatementContext).getTablesContext().getSimpleTables()); - tableHintDataSourceMappingsRetriever = new ShadowTableHintDataSourceMappingsRetriever(operationType, hintValueContext.isShadow(), tableAliasAndNameMappings); - } - - private Map getTableAliasAndNameMappings(final Collection tableSegments) { - Map result = new LinkedHashMap<>(tableSegments.size(), 1F); - for (SimpleTableSegment each : tableSegments) { - String tableName = each.getTableName().getIdentifier().getValue(); - String alias = each.getAliasName().isPresent() ? each.getAliasName().get() : tableName; - result.put(alias, tableName); - } - return result; - } - @Override public Map retrieve(final ShadowRule rule) { - Map result = tableHintDataSourceMappingsRetriever.retrieve(rule); - return result.isEmpty() ? findByShadowColumn(rule, rule.filterShadowTables(tableAliasAndNameMappings.values())) : result; - } - - private Map findByShadowColumn(final ShadowRule rule, final Collection shadowTables) { - for (String each : shadowTables) { + for (String each : rule.filterShadowTables(tableAliasAndNameMappings.values())) { Collection shadowColumnNames = rule.getShadowColumnNames(operationType, each); if (!shadowColumnNames.isEmpty() && isMatchAnyColumnShadowAlgorithms(rule, each, shadowColumnNames)) { return rule.getShadowDataSourceMappings(each); diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDeleteStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowDeleteStatementDataSourceMappingsRetriever.java similarity index 89% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDeleteStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowDeleteStatementDataSourceMappingsRetriever.java index 08a31ba9a2e5c..b88e676db9947 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDeleteStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowDeleteStatementDataSourceMappingsRetriever.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml; +package org.apache.shardingsphere.shadow.route.retriever.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; -import org.apache.shardingsphere.infra.hint.HintValueContext; -import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; +import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; @@ -30,18 +29,19 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; /** * Shadow delete statement data source mappings retriever. */ -public final class ShadowDeleteStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever { +public final class ShadowDeleteStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final DeleteStatementContext sqlStatementContext; private final List parameters; - public ShadowDeleteStatementDataSourceMappingsRetriever(final DeleteStatementContext sqlStatementContext, final List parameters, final HintValueContext hintValueContext) { - super(sqlStatementContext, hintValueContext, ShadowOperationType.DELETE); + public ShadowDeleteStatementDataSourceMappingsRetriever(final DeleteStatementContext sqlStatementContext, final List parameters, final Map tableAliasAndNameMappings) { + super(ShadowOperationType.DELETE, tableAliasAndNameMappings); this.sqlStatementContext = sqlStatementContext; this.parameters = parameters; } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowInsertStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowInsertStatementDataSourceMappingsRetriever.java similarity index 89% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowInsertStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowInsertStatementDataSourceMappingsRetriever.java index 2650a3f6fd7a0..88ee4af8e9983 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowInsertStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowInsertStatementDataSourceMappingsRetriever.java @@ -15,29 +15,29 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml; +package org.apache.shardingsphere.shadow.route.retriever.column; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; -import org.apache.shardingsphere.infra.hint.HintValueContext; -import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.exception.syntax.UnsupportedShadowInsertValueException; +import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; /** * Shadow insert statement data source mappings retriever. */ -public final class ShadowInsertStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever { +public final class ShadowInsertStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final InsertStatementContext sqlStatementContext; - public ShadowInsertStatementDataSourceMappingsRetriever(final InsertStatementContext sqlStatementContext, final HintValueContext hintValueContext) { - super(sqlStatementContext, hintValueContext, ShadowOperationType.INSERT); + public ShadowInsertStatementDataSourceMappingsRetriever(final InsertStatementContext sqlStatementContext, final Map tableAliasAndNameMappings) { + super(ShadowOperationType.INSERT, tableAliasAndNameMappings); this.sqlStatementContext = sqlStatementContext; } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowSelectStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowSelectStatementDataSourceMappingsRetriever.java similarity index 91% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowSelectStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowSelectStatementDataSourceMappingsRetriever.java index 2d9240b20dbbc..1c3f8626dd7f1 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowSelectStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowSelectStatementDataSourceMappingsRetriever.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml; +package org.apache.shardingsphere.shadow.route.retriever.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.hint.HintValueContext; +import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; -import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; @@ -33,19 +32,20 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Optional; /** * Shadow select statement data source mappings retriever. */ -public final class ShadowSelectStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever { +public final class ShadowSelectStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final SelectStatementContext sqlStatementContext; private final List parameters; - public ShadowSelectStatementDataSourceMappingsRetriever(final SelectStatementContext sqlStatementContext, final List parameters, final HintValueContext hintValueContext) { - super(sqlStatementContext, hintValueContext, ShadowOperationType.SELECT); + public ShadowSelectStatementDataSourceMappingsRetriever(final SelectStatementContext sqlStatementContext, final List parameters, final Map tableAliasAndNameMappings) { + super(ShadowOperationType.SELECT, tableAliasAndNameMappings); this.sqlStatementContext = sqlStatementContext; this.parameters = parameters; } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowUpdateStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowUpdateStatementDataSourceMappingsRetriever.java similarity index 90% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowUpdateStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowUpdateStatementDataSourceMappingsRetriever.java index 1f734fc6c0503..2092476594829 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowUpdateStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowUpdateStatementDataSourceMappingsRetriever.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml; +package org.apache.shardingsphere.shadow.route.retriever.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; -import org.apache.shardingsphere.infra.hint.HintValueContext; +import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; -import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; @@ -32,18 +31,19 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; /** * Shadow update statement data source mappings retriever. */ -public final class ShadowUpdateStatementDataSourceMappingsRetriever extends AbstractShadowDMLStatementDataSourceMappingsRetriever { +public final class ShadowUpdateStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final UpdateStatementContext sqlStatementContext; private final List parameters; - public ShadowUpdateStatementDataSourceMappingsRetriever(final UpdateStatementContext sqlStatementContext, final List parameters, final HintValueContext hintValueContext) { - super(sqlStatementContext, hintValueContext, ShadowOperationType.UPDATE); + public ShadowUpdateStatementDataSourceMappingsRetriever(final UpdateStatementContext sqlStatementContext, final List parameters, final Map tableAliasAndNameMappings) { + super(ShadowOperationType.UPDATE, tableAliasAndNameMappings); this.sqlStatementContext = sqlStatementContext; this.parameters = parameters; } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java new file mode 100644 index 0000000000000..5726449a11797 --- /dev/null +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java @@ -0,0 +1,89 @@ +/* + * 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.shadow.route.retriever.dml; + +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; +import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; +import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; +import org.apache.shardingsphere.infra.session.query.QueryContext; +import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.column.ShadowColumnDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.column.ShadowDeleteStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.column.ShadowInsertStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.column.ShadowSelectStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.column.ShadowUpdateStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.hint.ShadowTableHintDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.rule.ShadowRule; +import org.apache.shardingsphere.shadow.spi.ShadowOperationType; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Shadow DML statement data source mappings retriever. + */ +@HighFrequencyInvocation +public final class ShadowDMLStatementDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { + + private final ShadowTableHintDataSourceMappingsRetriever tableHintDataSourceMappingsRetriever; + + private final ShadowColumnDataSourceMappingsRetriever shadowColumnDataSourceMappingsRetriever; + + public ShadowDMLStatementDataSourceMappingsRetriever(final QueryContext queryContext, final ShadowOperationType operationType) { + Map tableAliasAndNameMappings = getTableAliasAndNameMappings(((TableAvailable) queryContext.getSqlStatementContext()).getTablesContext().getSimpleTables()); + tableHintDataSourceMappingsRetriever = new ShadowTableHintDataSourceMappingsRetriever(operationType, queryContext.getHintValueContext().isShadow(), tableAliasAndNameMappings); + shadowColumnDataSourceMappingsRetriever = createShadowDataSourceMappingsRetriever(queryContext, tableAliasAndNameMappings); + } + + private Map getTableAliasAndNameMappings(final Collection tableSegments) { + Map result = new LinkedHashMap<>(tableSegments.size(), 1F); + for (SimpleTableSegment each : tableSegments) { + String tableName = each.getTableName().getIdentifier().getValue(); + String alias = each.getAliasName().isPresent() ? each.getAliasName().get() : tableName; + result.put(alias, tableName); + } + return result; + } + + private ShadowColumnDataSourceMappingsRetriever createShadowDataSourceMappingsRetriever(final QueryContext queryContext, final Map tableAliasAndNameMappings) { + if (queryContext.getSqlStatementContext() instanceof InsertStatementContext) { + return new ShadowInsertStatementDataSourceMappingsRetriever((InsertStatementContext) queryContext.getSqlStatementContext(), tableAliasAndNameMappings); + } + if (queryContext.getSqlStatementContext() instanceof DeleteStatementContext) { + return new ShadowDeleteStatementDataSourceMappingsRetriever((DeleteStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), tableAliasAndNameMappings); + } + if (queryContext.getSqlStatementContext() instanceof UpdateStatementContext) { + return new ShadowUpdateStatementDataSourceMappingsRetriever((UpdateStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), tableAliasAndNameMappings); + } + if (queryContext.getSqlStatementContext() instanceof SelectStatementContext) { + return new ShadowSelectStatementDataSourceMappingsRetriever((SelectStatementContext) queryContext.getSqlStatementContext(), queryContext.getParameters(), tableAliasAndNameMappings); + } + throw new UnsupportedOperationException(String.format("unsupported SQL statement context `%s`", queryContext.getSqlStatementContext().getClass().getName())); + } + + @Override + public Map retrieve(final ShadowRule rule) { + Map result = tableHintDataSourceMappingsRetriever.retrieve(rule); + return result.isEmpty() ? shadowColumnDataSourceMappingsRetriever.retrieve(rule) : result; + } +} diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactoryTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactoryTest.java index 154a9ee9d185f..afd51c36a8eb1 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactoryTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/ShadowDataSourceMappingsRetrieverFactoryTest.java @@ -27,10 +27,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowDeleteStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowInsertStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowSelectStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowUpdateStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowDMLStatementDataSourceMappingsRetriever; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; @@ -52,16 +49,16 @@ class ShadowDataSourceMappingsRetrieverFactoryTest { void assertNewInstance() { ShadowDataSourceMappingsRetriever retriever = ShadowDataSourceMappingsRetrieverFactory.newInstance( new QueryContext(createInsertSqlStatementContext(), "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class))); - assertThat(retriever, instanceOf(ShadowInsertStatementDataSourceMappingsRetriever.class)); + assertThat(retriever, instanceOf(ShadowDMLStatementDataSourceMappingsRetriever.class)); ShadowDataSourceMappingsRetriever shadowUpdateRouteEngine = ShadowDataSourceMappingsRetrieverFactory.newInstance( new QueryContext(createUpdateSqlStatementContext(), "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class))); - assertThat(shadowUpdateRouteEngine, instanceOf(ShadowUpdateStatementDataSourceMappingsRetriever.class)); + assertThat(shadowUpdateRouteEngine, instanceOf(ShadowDMLStatementDataSourceMappingsRetriever.class)); ShadowDataSourceMappingsRetriever shadowDeleteRouteEngine = ShadowDataSourceMappingsRetrieverFactory.newInstance( new QueryContext(createDeleteSqlStatementContext(), "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class))); - assertThat(shadowDeleteRouteEngine, instanceOf(ShadowDeleteStatementDataSourceMappingsRetriever.class)); + assertThat(shadowDeleteRouteEngine, instanceOf(ShadowDMLStatementDataSourceMappingsRetriever.class)); ShadowDataSourceMappingsRetriever shadowSelectRouteEngine = ShadowDataSourceMappingsRetrieverFactory.newInstance( new QueryContext(createSelectSqlStatementContext(), "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class))); - assertThat(shadowSelectRouteEngine, instanceOf(ShadowSelectStatementDataSourceMappingsRetriever.class)); + assertThat(shadowSelectRouteEngine, instanceOf(ShadowDMLStatementDataSourceMappingsRetriever.class)); } private ConnectionContext mockConnectionContext() { From 89e79c41fbb42173f6ee767ea1e60ba0bae1b4c0 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 5 Nov 2024 23:22:52 +0800 Subject: [PATCH 2/6] Add ShadowDMLStatementDataSourceMappingsRetriever --- ...hadowDMLStatementDataSourceMappingsRetriever.java | 12 ++++++------ .../ShadowColumnDataSourceMappingsRetriever.java | 2 +- ...owDeleteStatementDataSourceMappingsRetriever.java | 2 +- ...owInsertStatementDataSourceMappingsRetriever.java | 2 +- ...owSelectStatementDataSourceMappingsRetriever.java | 2 +- ...owUpdateStatementDataSourceMappingsRetriever.java | 2 +- .../ShadowTableHintDataSourceMappingsRetriever.java | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{ => dml/impl}/column/ShadowColumnDataSourceMappingsRetriever.java (98%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{ => dml/impl}/column/ShadowDeleteStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{ => dml/impl}/column/ShadowInsertStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{ => dml/impl}/column/ShadowSelectStatementDataSourceMappingsRetriever.java (98%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{ => dml/impl}/column/ShadowUpdateStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/{ => dml/impl}/hint/ShadowTableHintDataSourceMappingsRetriever.java (98%) diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java index 5726449a11797..363cd944fad5c 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java @@ -25,12 +25,12 @@ import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.column.ShadowColumnDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.column.ShadowDeleteStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.column.ShadowInsertStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.column.ShadowSelectStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.column.ShadowUpdateStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.hint.ShadowTableHintDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowColumnDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowDeleteStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowInsertStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowSelectStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowUpdateStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.impl.hint.ShadowTableHintDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowColumnDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowColumnDataSourceMappingsRetriever.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowColumnDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowColumnDataSourceMappingsRetriever.java index 2bc8356391b46..61739ae831e29 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowColumnDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowColumnDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowDeleteStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowDeleteStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowDeleteStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowDeleteStatementDataSourceMappingsRetriever.java index b88e676db9947..5090ca192b820 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowDeleteStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowDeleteStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowInsertStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowInsertStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowInsertStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowInsertStatementDataSourceMappingsRetriever.java index 88ee4af8e9983..c8b0781224d24 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowInsertStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowInsertStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowSelectStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowSelectStatementDataSourceMappingsRetriever.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowSelectStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowSelectStatementDataSourceMappingsRetriever.java index 1c3f8626dd7f1..47d2346bba31d 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowSelectStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowSelectStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowUpdateStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowUpdateStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowUpdateStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowUpdateStatementDataSourceMappingsRetriever.java index 2092476594829..729a378b054f6 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/column/ShadowUpdateStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowUpdateStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/hint/ShadowTableHintDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/hint/ShadowTableHintDataSourceMappingsRetriever.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/hint/ShadowTableHintDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/hint/ShadowTableHintDataSourceMappingsRetriever.java index db9193172418f..13440c0062ca0 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/hint/ShadowTableHintDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/hint/ShadowTableHintDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.hint; +package org.apache.shardingsphere.shadow.route.retriever.dml.impl.hint; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; From 06599d9780efe2cf0dd5eacec1c789109a8b327c Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 5 Nov 2024 23:24:56 +0800 Subject: [PATCH 3/6] Add ShadowDMLStatementDataSourceMappingsRetriever --- ...hadowDMLStatementDataSourceMappingsRetriever.java | 12 ++++++------ .../ShadowColumnDataSourceMappingsRetriever.java | 2 +- ...owDeleteStatementDataSourceMappingsRetriever.java | 2 +- ...owInsertStatementDataSourceMappingsRetriever.java | 2 +- ...owSelectStatementDataSourceMappingsRetriever.java | 2 +- ...owUpdateStatementDataSourceMappingsRetriever.java | 2 +- .../ShadowTableHintDataSourceMappingsRetriever.java | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{impl => type}/column/ShadowColumnDataSourceMappingsRetriever.java (98%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{impl => type}/column/ShadowDeleteStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{impl => type}/column/ShadowInsertStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{impl => type}/column/ShadowSelectStatementDataSourceMappingsRetriever.java (98%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{impl => type}/column/ShadowUpdateStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{impl => type}/hint/ShadowTableHintDataSourceMappingsRetriever.java (98%) diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java index 363cd944fad5c..cfc1c7fedd0bd 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java @@ -25,12 +25,12 @@ import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowColumnDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowDeleteStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowInsertStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowSelectStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.impl.column.ShadowUpdateStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.impl.hint.ShadowTableHintDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowColumnDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowDeleteStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowInsertStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowSelectStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowUpdateStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.type.hint.ShadowTableHintDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowColumnDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowColumnDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java index 61739ae831e29..29ce5a5d180e9 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowColumnDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowDeleteStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowDeleteStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java index 5090ca192b820..37b8c78029188 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowDeleteStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowInsertStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowInsertStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java index c8b0781224d24..f531e2d996054 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowInsertStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowSelectStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowSelectStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java index 47d2346bba31d..2be115e9f81f2 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowSelectStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowUpdateStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowUpdateStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java index 729a378b054f6..8c20c47c881a5 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/column/ShadowUpdateStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.impl.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/hint/ShadowTableHintDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/hint/ShadowTableHintDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java index 13440c0062ca0..bdf8237b74415 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/impl/hint/ShadowTableHintDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.impl.hint; +package org.apache.shardingsphere.shadow.route.retriever.dml.type.hint; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; From 287d92bc1c0d9e336ab8a1fff0ccb909528252b9 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 5 Nov 2024 23:33:37 +0800 Subject: [PATCH 4/6] Add ShadowDMLStatementDataSourceMappingsRetriever --- ...LStatementDataSourceMappingsRetriever.java | 11 ++++-- ...hadowTableDataSourceMappingsRetriever.java | 38 +++++++++++++++++++ ...adowColumnDataSourceMappingsRetriever.java | 8 ++-- ...wTableHintDataSourceMappingsRetriever.java | 9 ++--- 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowTableDataSourceMappingsRetriever.java diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java index cfc1c7fedd0bd..4272498c77dc3 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java @@ -45,13 +45,15 @@ @HighFrequencyInvocation public final class ShadowDMLStatementDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { + private final Map tableAliasAndNameMappings; + private final ShadowTableHintDataSourceMappingsRetriever tableHintDataSourceMappingsRetriever; private final ShadowColumnDataSourceMappingsRetriever shadowColumnDataSourceMappingsRetriever; public ShadowDMLStatementDataSourceMappingsRetriever(final QueryContext queryContext, final ShadowOperationType operationType) { - Map tableAliasAndNameMappings = getTableAliasAndNameMappings(((TableAvailable) queryContext.getSqlStatementContext()).getTablesContext().getSimpleTables()); - tableHintDataSourceMappingsRetriever = new ShadowTableHintDataSourceMappingsRetriever(operationType, queryContext.getHintValueContext().isShadow(), tableAliasAndNameMappings); + tableAliasAndNameMappings = getTableAliasAndNameMappings(((TableAvailable) queryContext.getSqlStatementContext()).getTablesContext().getSimpleTables()); + tableHintDataSourceMappingsRetriever = new ShadowTableHintDataSourceMappingsRetriever(operationType, queryContext.getHintValueContext().isShadow()); shadowColumnDataSourceMappingsRetriever = createShadowDataSourceMappingsRetriever(queryContext, tableAliasAndNameMappings); } @@ -83,7 +85,8 @@ private ShadowColumnDataSourceMappingsRetriever createShadowDataSourceMappingsRe @Override public Map retrieve(final ShadowRule rule) { - Map result = tableHintDataSourceMappingsRetriever.retrieve(rule); - return result.isEmpty() ? shadowColumnDataSourceMappingsRetriever.retrieve(rule) : result; + Collection shadowTables = rule.filterShadowTables(tableAliasAndNameMappings.values()); + Map result = tableHintDataSourceMappingsRetriever.retrieve(rule, shadowTables); + return result.isEmpty() ? shadowColumnDataSourceMappingsRetriever.retrieve(rule, shadowTables) : result; } } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowTableDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowTableDataSourceMappingsRetriever.java new file mode 100644 index 0000000000000..69d4630f4ce31 --- /dev/null +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowTableDataSourceMappingsRetriever.java @@ -0,0 +1,38 @@ +/* + * 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.shadow.route.retriever.dml; + +import org.apache.shardingsphere.shadow.rule.ShadowRule; + +import java.util.Collection; +import java.util.Map; + +/** + * Shadow table data source mappings retriever. + */ +public interface ShadowTableDataSourceMappingsRetriever { + + /** + * Retrieve shadow data source mappings. + * + * @param rule shadow rule + * @param shadowTables shadow tables + * @return retrieved shadow data source mappings + */ + Map retrieve(ShadowRule rule, Collection shadowTables); +} diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java index 29ce5a5d180e9..84065c6ff80f5 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.condition.ShadowCondition; import org.apache.shardingsphere.shadow.route.determiner.ColumnShadowAlgorithmDeterminer; -import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowTableDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm; @@ -37,7 +37,7 @@ */ @HighFrequencyInvocation @RequiredArgsConstructor -public abstract class ShadowColumnDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { +public abstract class ShadowColumnDataSourceMappingsRetriever implements ShadowTableDataSourceMappingsRetriever { private final ShadowOperationType operationType; @@ -45,8 +45,8 @@ public abstract class ShadowColumnDataSourceMappingsRetriever implements ShadowD private final Map tableAliasAndNameMappings; @Override - public Map retrieve(final ShadowRule rule) { - for (String each : rule.filterShadowTables(tableAliasAndNameMappings.values())) { + public Map retrieve(final ShadowRule rule, final Collection shadowTables) { + for (String each : shadowTables) { Collection shadowColumnNames = rule.getShadowColumnNames(operationType, each); if (!shadowColumnNames.isEmpty() && isMatchAnyColumnShadowAlgorithms(rule, each, shadowColumnNames)) { return rule.getShadowDataSourceMappings(each); diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java index bdf8237b74415..4b70461b3667b 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.shadow.condition.ShadowCondition; import org.apache.shardingsphere.shadow.route.determiner.HintShadowAlgorithmDeterminer; -import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowTableDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; @@ -37,17 +37,14 @@ */ @HighFrequencyInvocation @RequiredArgsConstructor -public final class ShadowTableHintDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { +public final class ShadowTableHintDataSourceMappingsRetriever implements ShadowTableDataSourceMappingsRetriever { private final ShadowOperationType operationType; private final boolean isShadow; - private final Map tableAliasAndNameMappings; - @Override - public Map retrieve(final ShadowRule rule) { - Collection shadowTables = rule.filterShadowTables(tableAliasAndNameMappings.values()); + public Map retrieve(final ShadowRule rule, final Collection shadowTables) { return shadowTables.isEmpty() && isMatchDefaultAlgorithm(rule) ? rule.getAllShadowDataSourceMappings() : findShadowDataSourceMappingsBySQLHints(rule, shadowTables); } From 3ce687740b84d20576d18c27c2de876344b89e7d Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 5 Nov 2024 23:34:32 +0800 Subject: [PATCH 5/6] Add ShadowDMLStatementDataSourceMappingsRetriever --- .../ShadowDeleteStatementDataSourceMappingsRetriever.java | 2 ++ .../ShadowInsertStatementDataSourceMappingsRetriever.java | 2 ++ .../ShadowSelectStatementDataSourceMappingsRetriever.java | 2 ++ .../ShadowUpdateStatementDataSourceMappingsRetriever.java | 2 ++ 4 files changed, 8 insertions(+) diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java index 37b8c78029188..e55e75a1f1084 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; @@ -34,6 +35,7 @@ /** * Shadow delete statement data source mappings retriever. */ +@HighFrequencyInvocation public final class ShadowDeleteStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final DeleteStatementContext sqlStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java index f531e2d996054..397814f5872e7 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; @@ -32,6 +33,7 @@ /** * Shadow insert statement data source mappings retriever. */ +@HighFrequencyInvocation public final class ShadowInsertStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final InsertStatementContext sqlStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java index 2be115e9f81f2..d29feb09d87c3 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; @@ -38,6 +39,7 @@ /** * Shadow select statement data source mappings retriever. */ +@HighFrequencyInvocation public final class ShadowSelectStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final SelectStatementContext sqlStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java index 8c20c47c881a5..e4f0f51e20b10 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; @@ -36,6 +37,7 @@ /** * Shadow update statement data source mappings retriever. */ +@HighFrequencyInvocation public final class ShadowUpdateStatementDataSourceMappingsRetriever extends ShadowColumnDataSourceMappingsRetriever { private final UpdateStatementContext sqlStatementContext; From ba4d5c74af458929f2918d1c4d977104297c2df4 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 5 Nov 2024 23:36:21 +0800 Subject: [PATCH 6/6] Add ShadowDMLStatementDataSourceMappingsRetriever --- ...hadowDMLStatementDataSourceMappingsRetriever.java | 12 ++++++------ .../ShadowTableDataSourceMappingsRetriever.java | 2 +- .../ShadowColumnDataSourceMappingsRetriever.java | 4 ++-- ...owDeleteStatementDataSourceMappingsRetriever.java | 2 +- ...owInsertStatementDataSourceMappingsRetriever.java | 2 +- ...owSelectStatementDataSourceMappingsRetriever.java | 2 +- ...owUpdateStatementDataSourceMappingsRetriever.java | 2 +- .../ShadowTableHintDataSourceMappingsRetriever.java | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{ => table}/ShadowTableDataSourceMappingsRetriever.java (95%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{type => table}/column/ShadowColumnDataSourceMappingsRetriever.java (95%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{type => table}/column/ShadowDeleteStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{type => table}/column/ShadowInsertStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{type => table}/column/ShadowSelectStatementDataSourceMappingsRetriever.java (98%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{type => table}/column/ShadowUpdateStatementDataSourceMappingsRetriever.java (97%) rename features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/{type => table}/hint/ShadowTableHintDataSourceMappingsRetriever.java (94%) diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java index 4272498c77dc3..2971b1e35c164 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java @@ -25,12 +25,12 @@ import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowColumnDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowDeleteStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowInsertStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowSelectStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.type.column.ShadowUpdateStatementDataSourceMappingsRetriever; -import org.apache.shardingsphere.shadow.route.retriever.dml.type.hint.ShadowTableHintDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowColumnDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowDeleteStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowInsertStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowSelectStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowUpdateStatementDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.hint.ShadowTableHintDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowTableDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/ShadowTableDataSourceMappingsRetriever.java similarity index 95% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowTableDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/ShadowTableDataSourceMappingsRetriever.java index 69d4630f4ce31..fdb2e8bf29bdf 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowTableDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/ShadowTableDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml; +package org.apache.shardingsphere.shadow.route.retriever.dml.table; import org.apache.shardingsphere.shadow.rule.ShadowRule; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowColumnDataSourceMappingsRetriever.java similarity index 95% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowColumnDataSourceMappingsRetriever.java index 84065c6ff80f5..652012d446971 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowColumnDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowColumnDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.table.column; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -23,7 +23,7 @@ import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.condition.ShadowCondition; import org.apache.shardingsphere.shadow.route.determiner.ColumnShadowAlgorithmDeterminer; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowTableDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.ShadowTableDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowDeleteStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowDeleteStatementDataSourceMappingsRetriever.java index e55e75a1f1084..432d75d2793fc 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowDeleteStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowDeleteStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.table.column; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowInsertStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowInsertStatementDataSourceMappingsRetriever.java index 397814f5872e7..3a920f9ef8d28 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowInsertStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowInsertStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.table.column; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowSelectStatementDataSourceMappingsRetriever.java similarity index 98% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowSelectStatementDataSourceMappingsRetriever.java index d29feb09d87c3..c1901bc6e9de9 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowSelectStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowSelectStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.table.column; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowUpdateStatementDataSourceMappingsRetriever.java similarity index 97% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowUpdateStatementDataSourceMappingsRetriever.java index e4f0f51e20b10..a9c8d31fdba20 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/column/ShadowUpdateStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/ShadowUpdateStatementDataSourceMappingsRetriever.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.type.column; +package org.apache.shardingsphere.shadow.route.retriever.dml.table.column; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/hint/ShadowTableHintDataSourceMappingsRetriever.java similarity index 94% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/hint/ShadowTableHintDataSourceMappingsRetriever.java index 4b70461b3667b..f967d14a7d7ed 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/type/hint/ShadowTableHintDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/hint/ShadowTableHintDataSourceMappingsRetriever.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.route.retriever.dml.type.hint; +package org.apache.shardingsphere.shadow.route.retriever.dml.table.hint; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; import org.apache.shardingsphere.shadow.condition.ShadowCondition; import org.apache.shardingsphere.shadow.route.determiner.HintShadowAlgorithmDeterminer; -import org.apache.shardingsphere.shadow.route.retriever.dml.ShadowTableDataSourceMappingsRetriever; +import org.apache.shardingsphere.shadow.route.retriever.dml.table.ShadowTableDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm; import org.apache.shardingsphere.shadow.spi.ShadowOperationType;