diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/combine/CombineSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/combine/CombineSegmentBinder.java index d2e83429fe8e4..b15c09dcc0042 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/combine/CombineSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/combine/CombineSegmentBinder.java @@ -40,20 +40,20 @@ public final class CombineSegmentBinder { * * @param segment table segment * @param statementBinderContext statement binder context - * @return bounded combine segment + * @return bound combine segment */ public static CombineSegment bind(final CombineSegment segment, final SQLStatementBinderContext statementBinderContext) { ShardingSphereMetaData metaData = statementBinderContext.getMetaData(); String currentDatabaseName = statementBinderContext.getCurrentDatabaseName(); Map externalTableBinderContexts = statementBinderContext.getExternalTableBinderContexts(); - SelectStatement boundedLeftSelect = new SelectStatementBinder().bind(segment.getLeft().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts); - SelectStatement boundedRightSelect = new SelectStatementBinder().bind(segment.getRight().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts); - SubquerySegment boundedLeft = new SubquerySegment(segment.getLeft().getStartIndex(), segment.getLeft().getStopIndex(), segment.getLeft().getText()); - boundedLeft.setSelect(boundedLeftSelect); - boundedLeft.setSubqueryType(segment.getLeft().getSubqueryType()); + SelectStatement boundLeftSelect = new SelectStatementBinder().bind(segment.getLeft().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts); + SelectStatement boundRightSelect = new SelectStatementBinder().bind(segment.getRight().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts); + SubquerySegment boundLeft = new SubquerySegment(segment.getLeft().getStartIndex(), segment.getLeft().getStopIndex(), segment.getLeft().getText()); + boundLeft.setSelect(boundLeftSelect); + boundLeft.setSubqueryType(segment.getLeft().getSubqueryType()); SubquerySegment boundedRight = new SubquerySegment(segment.getRight().getStartIndex(), segment.getRight().getStopIndex(), segment.getRight().getText()); - boundedRight.setSelect(boundedRightSelect); + boundedRight.setSelect(boundRightSelect); boundedRight.setSubqueryType(segment.getRight().getSubqueryType()); - return new CombineSegment(segment.getStartIndex(), segment.getStopIndex(), boundedLeft, segment.getCombineType(), boundedRight); + return new CombineSegment(segment.getStartIndex(), segment.getStopIndex(), boundLeft, segment.getCombineType(), boundedRight); } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/where/WhereSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/where/WhereSegmentBinder.java index e55c7c593680f..bea86e2fdd5d1 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/where/WhereSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/where/WhereSegmentBinder.java @@ -40,7 +40,7 @@ public final class WhereSegmentBinder { * @param statementBinderContext statement binder context * @param tableBinderContexts table binder contexts * @param outerTableBinderContexts outer table binder contexts - * @return bounded where segment + * @return bound where segment */ public static WhereSegment bind(final WhereSegment segment, final SQLStatementBinderContext statementBinderContext, final Map tableBinderContexts, final Map outerTableBinderContexts) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementBinderContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementBinderContext.java index 9d11941e82634..b29c36714b608 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementBinderContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementBinderContext.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import java.util.Collection; import java.util.HashSet; @@ -52,4 +53,11 @@ public final class SQLStatementBinderContext { private final Map externalTableBinderContexts = new CaseInsensitiveMap<>(); private final Collection pivotColumnNames = new HashSet<>(); + + public SQLStatementBinderContext(final SQLStatement sqlStatement, final ShardingSphereMetaData metaData, final String currentDatabaseName) { + this.metaData = metaData; + this.currentDatabaseName = currentDatabaseName; + databaseType = sqlStatement.getDatabaseType(); + variableNames = sqlStatement.getVariableNames(); + } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementBinder.java index 864268029b443..be35eae4d0b24 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementBinder.java @@ -44,7 +44,7 @@ private DeleteStatement bind(final DeleteStatement sqlStatement, final ShardingS final Map externalTableBinderContexts) { DeleteStatement result = copy(sqlStatement); Map tableBinderContexts = new LinkedHashMap<>(); - SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(metaData, currentDatabaseName, sqlStatement.getDatabaseType(), sqlStatement.getVariableNames()); + SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(sqlStatement, metaData, currentDatabaseName); statementBinderContext.getExternalTableBinderContexts().putAll(externalTableBinderContexts); result.setTable(TableSegmentBinder.bind(sqlStatement.getTable(), statementBinderContext, tableBinderContexts, Collections.emptyMap())); sqlStatement.getWhere().ifPresent(optional -> result.setWhere(WhereSegmentBinder.bind(optional, statementBinderContext, tableBinderContexts, Collections.emptyMap()))); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementBinder.java index 895d120412bb7..de38564532223 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementBinder.java @@ -50,7 +50,7 @@ public InsertStatement bind(final InsertStatement sqlStatement, final ShardingSp private InsertStatement bind(final InsertStatement sqlStatement, final ShardingSphereMetaData metaData, final String currentDatabaseName, final Map externalTableBinderContexts) { InsertStatement result = copy(sqlStatement); - SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(metaData, currentDatabaseName, sqlStatement.getDatabaseType(), sqlStatement.getVariableNames()); + SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(sqlStatement, metaData, currentDatabaseName); statementBinderContext.getExternalTableBinderContexts().putAll(externalTableBinderContexts); Map tableBinderContexts = new LinkedHashMap<>(); Optional.ofNullable(sqlStatement.getTable()).ifPresent(optional -> result.setTable(SimpleTableSegmentBinder.bind(optional, statementBinderContext, tableBinderContexts))); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/MergeStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/MergeStatementBinder.java index 721c6f48d872a..1b177ffb7108d 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/MergeStatementBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/MergeStatementBinder.java @@ -70,7 +70,7 @@ public MergeStatement bind(final MergeStatement sqlStatement, final ShardingSphe private MergeStatement bind(final MergeStatement sqlStatement, final ShardingSphereMetaData metaData, final String currentDatabaseName, final Map externalTableBinderContexts) { MergeStatement result = copy(sqlStatement); - SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(metaData, currentDatabaseName, sqlStatement.getDatabaseType(), sqlStatement.getVariableNames()); + SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(sqlStatement, metaData, currentDatabaseName); statementBinderContext.getExternalTableBinderContexts().putAll(externalTableBinderContexts); Map targetTableBinderContexts = new CaseInsensitiveMap<>(); TableSegment boundedTargetTableSegment = TableSegmentBinder.bind(sqlStatement.getTarget(), statementBinderContext, targetTableBinderContexts, Collections.emptyMap()); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java index a663d2f6945b4..a4f9ce4f8ba14 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java @@ -79,7 +79,7 @@ private SelectStatement bind(final SelectStatement sqlStatement, final ShardingS final Map outerTableBinderContexts, final Map externalTableBinderContexts) { SelectStatement result = copy(sqlStatement); Map tableBinderContexts = new LinkedHashMap<>(); - SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(metaData, currentDatabaseName, sqlStatement.getDatabaseType(), sqlStatement.getVariableNames()); + SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(sqlStatement, metaData, currentDatabaseName); statementBinderContext.getExternalTableBinderContexts().putAll(externalTableBinderContexts); sqlStatement.getWithSegment() .ifPresent(optional -> result.setWithSegment(WithSegmentBinder.bind(optional, statementBinderContext, tableBinderContexts, statementBinderContext.getExternalTableBinderContexts()))); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementBinder.java index da11801941fa3..104913ec9b52e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementBinder.java @@ -46,7 +46,7 @@ private UpdateStatement bind(final UpdateStatement sqlStatement, final ShardingS final Map externalTableBinderContexts) { UpdateStatement result = copy(sqlStatement); Map tableBinderContexts = new LinkedHashMap<>(); - SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(metaData, currentDatabaseName, sqlStatement.getDatabaseType(), sqlStatement.getVariableNames()); + SQLStatementBinderContext statementBinderContext = new SQLStatementBinderContext(sqlStatement, metaData, currentDatabaseName); statementBinderContext.getExternalTableBinderContexts().putAll(externalTableBinderContexts); TableSegment boundedTableSegment = TableSegmentBinder.bind(sqlStatement.getTable(), statementBinderContext, tableBinderContexts, Collections.emptyMap()); result.setTable(boundedTableSegment);