diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java index 1a82b8480b2b2..0eabb0847b6c5 100644 --- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java +++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java @@ -26,10 +26,8 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.ddl.CloseStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DALStatement; @@ -137,7 +135,6 @@ void assertNewInstanceWithUpdateStatementAndIsAllBroadcastTables() { } private TablesContext createTablesContext() { - DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); - return new TablesContext(Collections.singleton(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))), databaseType, null); + return new TablesContext(Collections.singleton(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))), null); } } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java index d513329c082f8..bd54b59414a6a 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java @@ -123,7 +123,7 @@ private SelectStatementContext mockSelectStatementContext(final String tableName when(result.getOrderByContext().getItems()).thenReturn(Collections.singleton(orderByItem)); when(result.getGroupByContext().getItems()).thenReturn(Collections.emptyList()); when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); - when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, "foo_db")); + when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment))); return result; } } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java index 80287886d790c..5befae4ed0535 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java @@ -164,7 +164,7 @@ public static UpdateStatementContext createUpdateStatementContext() { updateStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user")))); updateStatement.setWhere(createWhereSegment()); updateStatement.setSetAssignment(createSetAssignmentSegment()); - return new UpdateStatementContext(updateStatement, "foo_db"); + return new UpdateStatementContext(updateStatement); } private static WhereSegment createWhereSegment() { diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java index 627e0b4b17151..5648193a7d5c0 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java @@ -92,7 +92,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAlias() { when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections); when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); SimpleTableSegment doctorOneTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor1"))); - when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, "foo_db")); + when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable))); when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("a", "mobile", null, databaseType))); Collection actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); @@ -114,7 +114,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAliasForSameTable() { when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections); when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); SimpleTableSegment sameDoctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); - when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, sameDoctorTable), databaseType, "foo_db")); + when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, sameDoctorTable))); when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("a", "mobile", null, databaseType))); Collection actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); @@ -133,7 +133,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableName() { when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); SimpleTableSegment doctorOneTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor1"))); - when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, "foo_db")); + when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable))); when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("doctor", "mobile", null, databaseType))); Collection actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java index c503669a7be06..add57075398b5 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java @@ -86,7 +86,7 @@ private SelectStatementContext buildSelectStatementContext() { OrderByItem orderByItem = new OrderByItem(columnOrderByItemSegment); when(result.getGroupByContext().getItems()).thenReturn(Collections.singleton(orderByItem)); when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); - when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, "foo_db")); + when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment))); return result; } } 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 bc711bb832e38..85e20e1b0c84a 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 @@ -43,14 +43,14 @@ @HighFrequencyInvocation public final class ShadowDMLStatementDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { - private final Map tableAliasNameMap; + private final Collection tableNames; private final ShadowTableHintDataSourceMappingsRetriever tableHintDataSourceMappingsRetriever; private final ShadowColumnDataSourceMappingsRetriever shadowColumnDataSourceMappingsRetriever; public ShadowDMLStatementDataSourceMappingsRetriever(final QueryContext queryContext, final ShadowOperationType operationType) { - tableAliasNameMap = ((TableAvailable) queryContext.getSqlStatementContext()).getTablesContext().getTableAliasNameMap(); + tableNames = ((TableAvailable) queryContext.getSqlStatementContext()).getTablesContext().getTableNames(); tableHintDataSourceMappingsRetriever = new ShadowTableHintDataSourceMappingsRetriever(operationType, queryContext.getHintValueContext().isShadow()); shadowColumnDataSourceMappingsRetriever = createShadowDataSourceMappingsRetriever(queryContext); } @@ -73,7 +73,7 @@ private ShadowColumnDataSourceMappingsRetriever createShadowDataSourceMappingsRe @Override public Map retrieve(final ShadowRule rule) { - Collection shadowTables = rule.filterShadowTables(tableAliasNameMap.values()); + Collection shadowTables = rule.filterShadowTables(tableNames); Map result = tableHintDataSourceMappingsRetriever.retrieve(rule, shadowTables); return result.isEmpty() && null != shadowColumnDataSourceMappingsRetriever ? shadowColumnDataSourceMappingsRetriever.retrieve(rule, shadowTables) : result; } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java index 1eed56d03eeae..aaefa816fd523 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java @@ -23,18 +23,16 @@ import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowColumnDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; 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; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import java.util.Optional; /** * Shadow select statement data source mappings retriever. @@ -60,7 +58,8 @@ protected Collection getShadowColumnConditions(final Stri if (1 != columns.size()) { continue; } - ShadowExtractor.extractValues(each, parameters).map(values -> new ShadowColumnCondition(getOwnerTableName(columns.iterator().next()), shadowColumnName, values)).ifPresent(result::add); + ShadowExtractor.extractValues(each, parameters).map(values -> new ShadowColumnCondition( + columns.iterator().next().getColumnBoundInfo().getOriginalTable().getValue(), shadowColumnName, values)).ifPresent(result::add); } return result; } @@ -74,11 +73,4 @@ private Collection getWhereSegment() { } return result; } - - private String getOwnerTableName(final ColumnSegment columnSegment) { - Optional owner = columnSegment.getOwner(); - return owner.isPresent() - ? sqlStatementContext.getTablesContext().getTableAliasNameMap().get(owner.get().getIdentifier().getValue()) - : sqlStatementContext.getTablesContext().getTableNames().iterator().next(); - } } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java index f66278379d7d0..f4b34481b3558 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java @@ -20,11 +20,12 @@ 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; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; 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.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -36,7 +37,7 @@ import java.util.Collections; import java.util.Optional; -import static org.apache.shardingsphere.test.matcher.ShardingSphereAssertionMatchers.deepEqual; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -53,16 +54,22 @@ void assertRetrieveWithColumnOwner() { ExpressionSegment expressionSegment = mock(ExpressionSegment.class); when(whereSegment.getExpr()).thenReturn(expressionSegment); when(sqlStatementContext.getWhereSegments()).thenReturn(Arrays.asList(whereSegment, mock(WhereSegment.class, RETURNS_DEEP_STUBS))); - ColumnSegment columnSegment = mock(ColumnSegment.class); - when(columnSegment.getOwner()).thenReturn(Optional.of(new OwnerSegment(0, 0, new IdentifierValue("foo")))); + ColumnSegment columnSegment = mock(ColumnSegment.class, RETURNS_DEEP_STUBS); + when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl"); + OwnerSegment ownerSegment = new OwnerSegment(0, 0, new IdentifierValue("foo")); + ownerSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + when(columnSegment.getOwner()).thenReturn(Optional.of(ownerSegment)); when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment)); when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo"))); when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl")); - when(sqlStatementContext.getTablesContext().getTableAliasNameMap().get("foo")).thenReturn("foo_tbl"); ShadowSelectStatementDataSourceMappingsRetriever retriever = new ShadowSelectStatementDataSourceMappingsRetriever(sqlStatementContext, Collections.singletonList("foo")); Collection actual = retriever.getShadowColumnConditions("foo_col"); - Collection expected = Collections.singletonList(new ShadowColumnCondition("foo_tbl", "foo_col", Collections.singleton("foo"))); - assertThat(actual, deepEqual(expected)); + assertThat(actual.size(), is(1)); + ShadowColumnCondition actualCondition = actual.iterator().next(); + assertThat(actualCondition.getTable(), is("foo_tbl")); + assertThat(actualCondition.getColumn(), is("foo_col")); + assertThat(actualCondition.getValues(), is(Collections.singleton("foo"))); + } @Test @@ -72,14 +79,18 @@ void assertRetrieveWithoutColumnOwner() { ExpressionSegment expressionSegment = mock(ExpressionSegment.class); when(whereSegment.getExpr()).thenReturn(expressionSegment); when(sqlStatementContext.getWhereSegments()).thenReturn(Arrays.asList(whereSegment, mock(WhereSegment.class, RETURNS_DEEP_STUBS))); - ColumnSegment columnSegment = mock(ColumnSegment.class); + ColumnSegment columnSegment = mock(ColumnSegment.class, RETURNS_DEEP_STUBS); + when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl"); when(columnSegment.getOwner()).thenReturn(Optional.empty()); when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment)); when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo"))); when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl")); ShadowSelectStatementDataSourceMappingsRetriever retriever = new ShadowSelectStatementDataSourceMappingsRetriever(sqlStatementContext, Collections.singletonList("foo")); Collection actual = retriever.getShadowColumnConditions("foo_col"); - Collection expected = Collections.singletonList(new ShadowColumnCondition("foo_tbl", "foo_col", Collections.singleton("foo"))); - assertThat(actual, deepEqual(expected)); + assertThat(actual.size(), is(1)); + ShadowColumnCondition actualCondition = actual.iterator().next(); + assertThat(actualCondition.getTable(), is("foo_tbl")); + assertThat(actualCondition.getColumn(), is("foo_col")); + assertThat(actualCondition.getValues(), is(Collections.singleton("foo"))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java index 897a46822ec57..0c17547c6c5a7 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java @@ -60,7 +60,7 @@ void assertCheckWhenIndexExistRenameIndexNotExistForPostgreSQL() { when(schema.getAllTables()).thenReturn(Collections.singleton(table)); when(table.containsIndex("t_order_index")).thenReturn(true); when(table.containsIndex("t_order_index_new")).thenReturn(false); - assertDoesNotThrow(() -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement))); } @Test @@ -70,7 +70,7 @@ void assertCheckWhenIndexNotExistRenameIndexNotExistForPostgreSQL() { sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new")))); ShardingSphereTable table = mock(ShardingSphereTable.class); when(database.getSchema("public").getTable("t_order")).thenReturn(table); - assertThrows(IndexNotFoundException.class, () -> new ShardingAlterIndexSupportedChecker().check(rule, database, mock(), new AlterIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(IndexNotFoundException.class, () -> new ShardingAlterIndexSupportedChecker().check(rule, database, mock(), new AlterIndexStatementContext(sqlStatement))); } @Test @@ -84,6 +84,6 @@ void assertCheckAlterIndexWhenIndexExistRenameIndexExistForPostgreSQL() { when(table.containsIndex("t_order_index")).thenReturn(true); when(table.containsIndex("t_order_index_new")).thenReturn(true); assertThrows(DuplicateIndexException.class, - () -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement, "foo_db"))); + () -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java index 0ed445f918ce7..7fbb8d3588836 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java @@ -51,7 +51,7 @@ void assertCheckWithRenameTableWithShardingTable() { PostgreSQLAlterTableStatement sqlStatement = new PostgreSQLAlterTableStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_new")))); - AlterTableStatementContext sqlStatementContext = new AlterTableStatementContext(sqlStatement, "foo_db"); + AlterTableStatementContext sqlStatementContext = new AlterTableStatementContext(sqlStatement); when(rule.containsShardingTable(Arrays.asList("t_order", "t_order_new"))).thenReturn(true); assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingAlterTableSupportedChecker().check(rule, database, mock(), sqlStatementContext)); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java index 0b7c2ce56b7c0..1acaea3299c45 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java @@ -49,7 +49,7 @@ void assertPreValidateAlterViewForMySQL() { MySQLAlterViewStatement sqlStatement = new MySQLAlterViewStatement(); sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view")))); sqlStatement.setSelect(selectStatement); - AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db"); + AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement); when(rule.isShardingTable("t_order")).thenReturn(false); assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); } @@ -61,7 +61,7 @@ void assertPreValidateAlterViewWithShardingTableForMySQL() { MySQLAlterViewStatement sqlStatement = new MySQLAlterViewStatement(); sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view")))); sqlStatement.setSelect(selectStatement); - AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db"); + AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement); when(rule.isShardingTable("t_order")).thenReturn(true); assertThrows(EngagedViewException.class, () -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); } @@ -71,7 +71,7 @@ void assertPreValidateAlterRenamedView() { OpenGaussAlterViewStatement sqlStatement = new OpenGaussAlterViewStatement(); sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view")))); sqlStatement.setRenameView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_new")))); - AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db"); + AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement); assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java index c37805b434698..517500fbdae6c 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java @@ -64,7 +64,7 @@ void assertCheckCreateFunctionForMySQL() { routineBody.getValidStatements().add(selectValidStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order_item")).thenReturn(true); @@ -81,7 +81,7 @@ void assertCheckCreateFunctionWithShardingTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(rule.isShardingTable("t_order")).thenReturn(true); assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingCreateFunctionSupportedChecker().check(rule, database, mock(), sqlStatementContext)); @@ -97,7 +97,7 @@ void assertCheckCreateFunctionWithNoSuchTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); assertThrows(NoSuchTableException.class, () -> new ShardingCreateFunctionSupportedChecker().check(rule, database, mock(), sqlStatementContext)); } @@ -112,7 +112,7 @@ void assertCheckCreateFunctionWithTableExistsForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java index 3f115e5e965e8..1fedc80468e83 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java @@ -57,7 +57,7 @@ void assertCheckWhenTableExistIndexNotExistForPostgreSQL() { sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); - assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -67,7 +67,7 @@ void assertCheckWhenTableNotExistIndexNotExistForPostgreSQL() { sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(false); - assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -78,7 +78,7 @@ void assertCheckWhenTableExistIndexExistForPostgreSQL() { ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); when(schema.containsIndex("t_order", "t_order_index")).thenReturn(true); - assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -89,7 +89,7 @@ void assertCheckWithoutIndexNameWhenTableExistIndexNotExistForPostgreSQL() { sqlStatement.setGeneratedIndexStartIndex(10); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); - assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -100,7 +100,7 @@ void assertCheckWithoutIndexNameWhenTableNotExistIndexNotExistForPostgreSQL() { sqlStatement.setGeneratedIndexStartIndex(10); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(false); - assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -112,6 +112,6 @@ void assertCheckWithoutIndexNameWhenTableExistIndexExistForPostgreSQL() { ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); when(schema.containsIndex("t_order", "content_idx")).thenReturn(true); - assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java index 48b55eaa30b8e..e48488ffe9472 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java @@ -68,7 +68,7 @@ void assertCheckForMySQL() { ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order_item")).thenReturn(true); when(rule.isShardingTable("t_order_item")).thenReturn(false); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); assertDoesNotThrow(() -> new ShardingCreateProcedureSupportedChecker().check(rule, database, schema, sqlStatementContext)); } @@ -82,7 +82,7 @@ void assertCheckWithShardingTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(rule.isShardingTable("t_order")).thenReturn(true); assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingCreateProcedureSupportedChecker().check(rule, database, mock(), sqlStatementContext)); @@ -98,7 +98,7 @@ void assertCheckWithNoSuchTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); assertThrows(NoSuchTableException.class, () -> new ShardingCreateProcedureSupportedChecker().check(rule, database, mock(), sqlStatementContext)); } @@ -113,7 +113,7 @@ void assertCheckWithTableExistsForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java index 539c40418be03..6231def67420d 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java @@ -83,7 +83,7 @@ void assertCheckForSQLServer() { } private void assertCheck(final CreateTableStatement sqlStatement) { - CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement, "sharding_db"); + CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); @@ -105,7 +105,7 @@ void assertCheckIfNotExistsForPostgreSQL() { } private void assertCheckIfNotExists(final CreateTableStatement sqlStatement) { - CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement, "foo_db"); + CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); new ShardingCreateTableSupportedChecker().check(rule, database, mock(), sqlStatementContext); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java index c6784dd59e775..3ae4f537141bf 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java @@ -59,7 +59,7 @@ void assertCheckWhenIndexExistForPostgreSQL() { when(schema.getAllTables()).thenReturn(Collections.singleton(table)); when(table.containsIndex("t_order_index")).thenReturn(true); when(table.containsIndex("t_order_index_new")).thenReturn(true); - assertDoesNotThrow(() -> new ShardingDropIndexSupportedChecker().check(rule, database, schema, new DropIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingDropIndexSupportedChecker().check(rule, database, schema, new DropIndexStatementContext(sqlStatement))); } @Test @@ -70,6 +70,6 @@ void assertCheckWhenIndexNotExistForPostgreSQL() { ShardingSphereTable table = mock(ShardingSphereTable.class); when(database.getSchema("public").getAllTables()).thenReturn(Collections.singleton(table)); when(database.getSchema("public").getTable("t_order")).thenReturn(table); - assertThrows(IndexNotFoundException.class, () -> new ShardingDropIndexSupportedChecker().check(rule, database, mock(), new DropIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(IndexNotFoundException.class, () -> new ShardingDropIndexSupportedChecker().check(rule, database, mock(), new DropIndexStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java index 38489b6b6dff0..5223b63b3747d 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java @@ -64,7 +64,7 @@ void init() { void assertCheckForMySQL() { MySQLDropTableStatement sqlStatement = new MySQLDropTableStatement(false); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_item")))); - DropTableStatementContext sqlStatementContext = new DropTableStatementContext(sqlStatement, "db_schema"); + DropTableStatementContext sqlStatementContext = new DropTableStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order_item")).thenReturn(true); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java index 52fce0fd43062..da9a6cebc883b 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java @@ -148,13 +148,13 @@ private InsertStatement createInsertSelectStatement() { private TablesContext createSingleTablesContext() { List result = new LinkedList<>(); result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); - return new TablesContext(result, databaseType, "foo_db"); + return new TablesContext(result); } private TablesContext createMultiTablesContext() { List result = new LinkedList<>(); result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order")))); - return new TablesContext(result, databaseType, "foo_db"); + return new TablesContext(result); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java index d4aaae3d616ea..9b8000cfb055b 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java @@ -61,6 +61,6 @@ private RenameTableStatementContext createRenameTableStatementContext(final Stri renameTableDefinitionSegment.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(originTableName)))); renameTableDefinitionSegment.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(newTableName)))); sqlStatement.getRenameTables().add(renameTableDefinitionSegment); - return new RenameTableStatementContext(sqlStatement, "foo_db"); + return new RenameTableStatementContext(sqlStatement); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java index 271eed7fd04f8..9b15a14b9f549 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java @@ -46,14 +46,14 @@ class ShardingCopySupportedCheckerTest { void assertCheckWhenTableSegmentForPostgreSQL() { PostgreSQLCopyStatement sqlStatement = new PostgreSQLCopyStatement(); sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement))); } @Test void assertCheckWhenTableSegmentForOpenGauss() { OpenGaussCopyStatement sqlStatement = new OpenGaussCopyStatement(); sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement))); } @Test @@ -68,7 +68,7 @@ void assertCheckCopyWithShardingTableForOpenGauss() { private void assertCheckCopyTable(final CopyStatement sqlStatement) { sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - CopyStatementContext sqlStatementContext = new CopyStatementContext(sqlStatement, "foo_db"); + CopyStatementContext sqlStatementContext = new CopyStatementContext(sqlStatement); String tableName = "t_order"; when(rule.isShardingTable(tableName)).thenReturn(true); new ShardingCopySupportedChecker().check(rule, mock(), mock(), sqlStatementContext); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java index 7644a8f410994..7af8a2b3de8f5 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java @@ -83,7 +83,7 @@ private void assertCheckWhenDeleteMultiTables(final DeleteStatement sqlStatement Collection tableNames = new HashSet<>(Arrays.asList("user", "order", "order_item")); when(rule.isAllShardingTables(tableNames)).thenReturn(false); when(rule.containsShardingTable(tableNames)).thenReturn(true); - DeleteStatementContext sqlStatementContext = new DeleteStatementContext(sqlStatement, "foo_db"); + DeleteStatementContext sqlStatementContext = new DeleteStatementContext(sqlStatement); new ShardingDeleteSupportedChecker().check(rule, mock(), mock(), sqlStatementContext); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java index 9cda9b658229c..37c8bfd91fb57 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java @@ -43,13 +43,13 @@ class ShardingLoadDataSupportedCheckerTest { @Test void assertCheckWithSingleTable() { MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement))); } @Test void assertCheckWithShardingTable() { MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); when(rule.isShardingTable("t_order")).thenReturn(true); - assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement, "foo_db"))); + assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java index 718e3787a3181..0538a83d47873 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java @@ -43,13 +43,13 @@ class ShardingLoadXmlSupportedCheckerTest { @Test void assertCheckWithSingleTable() { MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement))); } @Test void assertCheckWithShardingTable() { MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); when(rule.isShardingTable("t_order")).thenReturn(true); - assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement, "foo_db"))); + assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java index 867ebf0f93dc1..d49c5da1e3515 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java @@ -55,7 +55,7 @@ class ShardingUpdateSupportedCheckerTest { void assertCheckWhenUpdateSingleTable() { UpdateStatement updateStatement = createUpdateStatement(); updateStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); - UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement, "foo_db"); + UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement); Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); when(rule.isAllShardingTables(tableNames)).thenReturn(true); when(rule.containsShardingTable(tableNames)).thenReturn(true); @@ -69,7 +69,7 @@ void assertCheckWhenUpdateMultipleTables() { joinTableSegment.setLeft(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); joinTableSegment.setRight(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order")))); updateStatement.setTable(joinTableSegment); - UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement, "foo_db"); + UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement); Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); when(rule.containsShardingTable(tableNames)).thenReturn(true); assertThrows(DMLWithMultipleShardingTablesException.class, () -> new ShardingUpdateSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java index b92876ccb3e6b..8914d07529f0f 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java @@ -77,7 +77,7 @@ void assertMergeWithFetchStreamMergedResult() throws SQLException { } private FetchStatementContext createFetchStatementContext(final ShardingSphereDatabase database) { - FetchStatementContext result = new FetchStatementContext(mockFetchStatement(), "foo_db"); + FetchStatementContext result = new FetchStatementContext(mockFetchStatement()); result.setCursorStatementContext(createCursorStatementContext(database)); return result; } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java index 6bb043a312b7c..55f0b15ffe152 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java @@ -91,7 +91,7 @@ void setUp() { } private static FetchStatementContext createFetchStatementContext(final boolean containsAllDirectionType) { - FetchStatementContext result = new FetchStatementContext(createFetchStatement(containsAllDirectionType), "foo_db"); + FetchStatementContext result = new FetchStatementContext(createFetchStatement(containsAllDirectionType)); result.setCursorStatementContext(mockCursorStatementContext()); return result; } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java index cf04e3fe042f1..ec44b25c16cf6 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java @@ -72,7 +72,7 @@ void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingAlterTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -85,7 +85,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingAlterTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java index f848860a00c20..e2f568eb205ae 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java @@ -72,7 +72,7 @@ void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -85,7 +85,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -94,7 +94,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { void assertCheckWithSameRouteResultBroadcastTableForPostgreSQL() { PostgreSQLCreateTableStatement sqlStatement = new PostgreSQLCreateTableStatement(false); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_config")))); - when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java index 1118626b51e10..9d57556c3eedf 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java @@ -79,7 +79,7 @@ void assertCheckWithSameRouteResultShardingTableIndexForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingDropIndexRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -98,7 +98,7 @@ void assertCheckWithDifferentRouteResultShardingTableIndexForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingDropIndexRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java index 68958c4eda4f1..4a26cb3d8aff9 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java @@ -94,7 +94,7 @@ void assertCheckWhenDropTableInUsedForMySQL() { routeUnits.add(routeUnit); RouteContext routeContext = mock(RouteContext.class); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertThrows(InUsedTablesException.class, () -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -127,7 +127,7 @@ void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singleton(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singleton(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext)); } @@ -141,7 +141,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singleton(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext)); } @@ -155,7 +155,7 @@ void assertCheckWithSameRouteResultBroadcastTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singleton(new RouteMapper("t_config", "t_config")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singleton(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext)); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java index 8500bab365c68..5be926ffb604f 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java @@ -91,6 +91,6 @@ private SQLStatementContext createRenameTableStatementContext() { renameTableDefinitionSegment.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); renameTableDefinitionSegment.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user_order")))); sqlStatement.getRenameTables().add(renameTableDefinitionSegment); - return new RenameTableStatementContext(sqlStatement, "foo_db"); + return new RenameTableStatementContext(sqlStatement); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java index 9ec657382d831..160e2a9926420 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java @@ -72,7 +72,7 @@ class ShardingUpdateRouteContextCheckerTest { @Test void assertCheckWhenNotUpdateShardingColumn() { - UpdateStatementContext sqlStatementContext = new UpdateStatementContext(createUpdateStatement(), "foo_db"); + UpdateStatementContext sqlStatementContext = new UpdateStatementContext(createUpdateStatement()); when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext); assertDoesNotThrow(() -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), mock(RouteContext.class))); } @@ -80,14 +80,14 @@ void assertCheckWhenNotUpdateShardingColumn() { @Test void assertCheckWhenUpdateShardingColumnWithSameRouteContext() { mockShardingRuleForUpdateShardingColumn(); - when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement(), "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement())); assertDoesNotThrow(() -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), createSingleRouteContext())); } @Test void assertCheckWhenUpdateShardingColumnWithDifferentRouteContext() { mockShardingRuleForUpdateShardingColumn(); - when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement(), "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement())); assertThrows(UnsupportedUpdatingShardingValueException.class, () -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), createFullRouteContext())); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java index cbbe43c2a274c..755d1da8837d0 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java @@ -160,7 +160,7 @@ void assertNewInstanceForDCLForSingleTableForSQL92() { private void assertNewInstanceForDCLForSingleTable(final GrantStatement grantStatement) { grantStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); - GrantStatementContext sqlStatementContext = new GrantStatementContext(grantStatement, "foo_db"); + GrantStatementContext sqlStatementContext = new GrantStatementContext(grantStatement); QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class)); ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.singletonList("tbl"), props); assertThat(actual, instanceOf(ShardingTableBroadcastRouteEngine.class)); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java index 2ce342a18e82d..4d2c328ee126f 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java @@ -675,7 +675,7 @@ void assertIsAllBindingTableWithJoinQueryWithDatabaseJoinConditionInUpperCaseAnd Collection tableSegments = Arrays.asList( new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("LOGIC_TABLE"))), new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("SUB_LOGIC_TABLE")))); - TablesContext tablesContext = new TablesContext(tableSegments, Collections.emptyMap(), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(tableSegments, Collections.emptyMap()); when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext); when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java index e137bbe16b19e..50fb33851a60e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java @@ -27,17 +27,13 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.subquery.SubqueryTableContext; import org.apache.shardingsphere.infra.binder.context.segment.select.subquery.engine.SubqueryTableContextEngine; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.util.Collection; import java.util.Collections; @@ -69,33 +65,29 @@ public final class TablesContext { @Getter(AccessLevel.NONE) private final Map> subqueryTables = new HashMap<>(); - private final Map tableAliasNameMap = new HashMap<>(); - - public TablesContext(final SimpleTableSegment table, final DatabaseType databaseType, final String currentDatabaseName) { - this(null == table ? Collections.emptyList() : Collections.singletonList(table), databaseType, currentDatabaseName); + public TablesContext(final SimpleTableSegment table) { + this(null == table ? Collections.emptyList() : Collections.singletonList(table)); } - public TablesContext(final Collection tables, final DatabaseType databaseType, final String currentDatabaseName) { - this(tables, Collections.emptyMap(), databaseType, currentDatabaseName); + public TablesContext(final Collection tables) { + this(tables, Collections.emptyMap()); } - public TablesContext(final Collection tables, final Map subqueryContexts, - final DatabaseType databaseType, final String currentDatabaseName) { + public TablesContext(final Collection tables, final Map subqueryContexts) { if (tables.isEmpty()) { return; } this.tables.addAll(tables); for (TableSegment each : tables) { if (each instanceof SimpleTableSegment) { - String tableName = ((SimpleTableSegment) each).getTableName().getIdentifier().getValue(); - if (!"DUAL".equalsIgnoreCase(tableName)) { - SimpleTableSegment simpleTableSegment = (SimpleTableSegment) each; + SimpleTableSegment simpleTableSegment = (SimpleTableSegment) each; + TableNameSegment tableName = simpleTableSegment.getTableName(); + if (!"DUAL".equalsIgnoreCase(tableName.getIdentifier().getValue())) { simpleTables.add(simpleTableSegment); - tableNames.add(tableName); - // TODO use SQL binder result when statement which contains tables support bind logic - simpleTableSegment.getOwner().ifPresent(optional -> schemaNames.add(optional.getIdentifier().getValue())); - databaseNames.add(findDatabaseName(simpleTableSegment, databaseType).orElse(currentDatabaseName)); - tableAliasNameMap.put(each.getAlias().map(IdentifierValue::getValue).orElse(tableName).toLowerCase(), tableName.toLowerCase()); + tableNames.add(tableName.getIdentifier().getValue()); + // TODO support bind with all statement contains table segement @duanzhengqiang + tableName.getTableBoundInfo().ifPresent(optional -> schemaNames.add(optional.getOriginalSchema().getValue())); + tableName.getTableBoundInfo().ifPresent(optional -> databaseNames.add(optional.getOriginalDatabase().getValue())); } } if (each instanceof SubqueryTableSegment) { @@ -104,12 +96,6 @@ public TablesContext(final Collection tables, final Map< } } - private Optional findDatabaseName(final SimpleTableSegment tableSegment, final DatabaseType databaseType) { - DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData(); - Optional owner = dialectDatabaseMetaData.getDefaultSchema().isPresent() ? tableSegment.getOwner().flatMap(OwnerSegment::getOwner) : tableSegment.getOwner(); - return owner.map(optional -> optional.getIdentifier().getValue()); - } - private Map> createSubqueryTables(final Map subqueryContexts, final SubqueryTableSegment subqueryTable) { if (!subqueryContexts.containsKey(subqueryTable.getSubquery().getStartIndex())) { return Collections.emptyMap(); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java index fdfdf048fc28f..dce944382f904 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java @@ -134,10 +134,10 @@ public static SQLStatementContext newInstance(final ShardingSphereMetaData metaD return getDDLStatementContext(metaData, (DDLStatement) sqlStatement, params, currentDatabaseName); } if (sqlStatement instanceof DCLStatement) { - return getDCLStatementContext((DCLStatement) sqlStatement, currentDatabaseName); + return getDCLStatementContext((DCLStatement) sqlStatement); } if (sqlStatement instanceof DALStatement) { - return getDALStatementContext((DALStatement) sqlStatement, currentDatabaseName); + return getDALStatementContext((DALStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } @@ -147,22 +147,22 @@ private static SQLStatementContext getDMLStatementContext(final ShardingSphereMe return new SelectStatementContext(metaData, params, (SelectStatement) sqlStatement, currentDatabaseName, Collections.emptyList()); } if (sqlStatement instanceof UpdateStatement) { - return new UpdateStatementContext((UpdateStatement) sqlStatement, currentDatabaseName); + return new UpdateStatementContext((UpdateStatement) sqlStatement); } if (sqlStatement instanceof DeleteStatement) { - return new DeleteStatementContext((DeleteStatement) sqlStatement, currentDatabaseName); + return new DeleteStatementContext((DeleteStatement) sqlStatement); } if (sqlStatement instanceof InsertStatement) { return new InsertStatementContext(metaData, params, (InsertStatement) sqlStatement, currentDatabaseName); } if (sqlStatement instanceof CopyStatement) { - return new CopyStatementContext((CopyStatement) sqlStatement, currentDatabaseName); + return new CopyStatementContext((CopyStatement) sqlStatement); } if (sqlStatement instanceof LoadDataStatement) { - return new LoadDataStatementContext((LoadDataStatement) sqlStatement, currentDatabaseName); + return new LoadDataStatementContext((LoadDataStatement) sqlStatement); } if (sqlStatement instanceof LoadXMLStatement) { - return new LoadXMLStatementContext((LoadXMLStatement) sqlStatement, currentDatabaseName); + return new LoadXMLStatementContext((LoadXMLStatement) sqlStatement); } if (sqlStatement instanceof CallStatement || sqlStatement instanceof DoStatement || sqlStatement instanceof MergeStatement) { return new UnknownSQLStatementContext(sqlStatement); @@ -175,87 +175,87 @@ private static SQLStatementContext getDDLStatementContext(final ShardingSphereMe return new CreateSchemaStatementContext((CreateSchemaStatement) sqlStatement); } if (sqlStatement instanceof CreateTableStatement) { - return new CreateTableStatementContext((CreateTableStatement) sqlStatement, currentDatabaseName); + return new CreateTableStatementContext((CreateTableStatement) sqlStatement); } if (sqlStatement instanceof AlterTableStatement) { - return new AlterTableStatementContext((AlterTableStatement) sqlStatement, currentDatabaseName); + return new AlterTableStatementContext((AlterTableStatement) sqlStatement); } if (sqlStatement instanceof RenameTableStatement) { - return new RenameTableStatementContext((RenameTableStatement) sqlStatement, currentDatabaseName); + return new RenameTableStatementContext((RenameTableStatement) sqlStatement); } if (sqlStatement instanceof DropTableStatement) { - return new DropTableStatementContext((DropTableStatement) sqlStatement, currentDatabaseName); + return new DropTableStatementContext((DropTableStatement) sqlStatement); } if (sqlStatement instanceof CreateIndexStatement) { - return new CreateIndexStatementContext((CreateIndexStatement) sqlStatement, currentDatabaseName); + return new CreateIndexStatementContext((CreateIndexStatement) sqlStatement); } if (sqlStatement instanceof AlterIndexStatement) { - return new AlterIndexStatementContext((AlterIndexStatement) sqlStatement, currentDatabaseName); + return new AlterIndexStatementContext((AlterIndexStatement) sqlStatement); } if (sqlStatement instanceof DropIndexStatement) { - return new DropIndexStatementContext((DropIndexStatement) sqlStatement, currentDatabaseName); + return new DropIndexStatementContext((DropIndexStatement) sqlStatement); } if (sqlStatement instanceof TruncateStatement) { - return new TruncateStatementContext((TruncateStatement) sqlStatement, currentDatabaseName); + return new TruncateStatementContext((TruncateStatement) sqlStatement); } if (sqlStatement instanceof CreateFunctionStatement) { - return new CreateFunctionStatementContext((CreateFunctionStatement) sqlStatement, currentDatabaseName); + return new CreateFunctionStatementContext((CreateFunctionStatement) sqlStatement); } if (sqlStatement instanceof CreateProcedureStatement) { - return new CreateProcedureStatementContext((CreateProcedureStatement) sqlStatement, currentDatabaseName); + return new CreateProcedureStatementContext((CreateProcedureStatement) sqlStatement); } if (sqlStatement instanceof CreateViewStatement) { - return new CreateViewStatementContext((CreateViewStatement) sqlStatement, currentDatabaseName); + return new CreateViewStatementContext((CreateViewStatement) sqlStatement); } if (sqlStatement instanceof AlterViewStatement) { - return new AlterViewStatementContext((AlterViewStatement) sqlStatement, currentDatabaseName); + return new AlterViewStatementContext((AlterViewStatement) sqlStatement); } if (sqlStatement instanceof DropViewStatement) { - return new DropViewStatementContext((DropViewStatement) sqlStatement, currentDatabaseName); + return new DropViewStatementContext((DropViewStatement) sqlStatement); } if (sqlStatement instanceof PrepareStatement) { - return new PrepareStatementContext((PrepareStatement) sqlStatement, currentDatabaseName); + return new PrepareStatementContext((PrepareStatement) sqlStatement); } if (sqlStatement instanceof CommentStatement) { - return new CommentStatementContext((CommentStatement) sqlStatement, currentDatabaseName); + return new CommentStatementContext((CommentStatement) sqlStatement); } if (sqlStatement instanceof CursorStatement) { return new CursorStatementContext(metaData, params, (CursorStatement) sqlStatement, currentDatabaseName); } if (sqlStatement instanceof CloseStatement) { - return new CloseStatementContext((CloseStatement) sqlStatement, currentDatabaseName); + return new CloseStatementContext((CloseStatement) sqlStatement); } if (sqlStatement instanceof MoveStatement) { - return new MoveStatementContext((MoveStatement) sqlStatement, currentDatabaseName); + return new MoveStatementContext((MoveStatement) sqlStatement); } if (sqlStatement instanceof FetchStatement) { - return new FetchStatementContext((FetchStatement) sqlStatement, currentDatabaseName); + return new FetchStatementContext((FetchStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } - private static SQLStatementContext getDCLStatementContext(final DCLStatement sqlStatement, final String currentDatabaseName) { + private static SQLStatementContext getDCLStatementContext(final DCLStatement sqlStatement) { if (sqlStatement instanceof GrantStatement) { - return new GrantStatementContext((GrantStatement) sqlStatement, currentDatabaseName); + return new GrantStatementContext((GrantStatement) sqlStatement); } if (sqlStatement instanceof RevokeStatement) { - return new RevokeStatementContext((RevokeStatement) sqlStatement, currentDatabaseName); + return new RevokeStatementContext((RevokeStatement) sqlStatement); } if (sqlStatement instanceof DenyUserStatement) { - return new DenyUserStatementContext((DenyUserStatement) sqlStatement, currentDatabaseName); + return new DenyUserStatementContext((DenyUserStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } - private static SQLStatementContext getDALStatementContext(final DALStatement sqlStatement, final String currentDatabaseName) { + private static SQLStatementContext getDALStatementContext(final DALStatement sqlStatement) { if (sqlStatement instanceof ExplainStatement) { - return new ExplainStatementContext((ExplainStatement) sqlStatement, currentDatabaseName); + return new ExplainStatementContext((ExplainStatement) sqlStatement); } if (sqlStatement instanceof ShowCreateTableStatement) { - return new ShowCreateTableStatementContext((ShowCreateTableStatement) sqlStatement, currentDatabaseName); + return new ShowCreateTableStatementContext((ShowCreateTableStatement) sqlStatement); } if (sqlStatement instanceof ShowColumnsStatement) { - return new ShowColumnsStatementContext((ShowColumnsStatement) sqlStatement, currentDatabaseName); + return new ShowColumnsStatementContext((ShowColumnsStatement) sqlStatement); } if (sqlStatement instanceof ShowTablesStatement) { return new ShowTablesStatementContext((ShowTablesStatement) sqlStatement); @@ -264,16 +264,16 @@ private static SQLStatementContext getDALStatementContext(final DALStatement sql return new ShowTableStatusStatementContext((ShowTableStatusStatement) sqlStatement); } if (sqlStatement instanceof ShowIndexStatement) { - return new ShowIndexStatementContext((ShowIndexStatement) sqlStatement, currentDatabaseName); + return new ShowIndexStatementContext((ShowIndexStatement) sqlStatement); } if (sqlStatement instanceof AnalyzeTableStatement) { - return new AnalyzeTableStatementContext((AnalyzeTableStatement) sqlStatement, currentDatabaseName); + return new AnalyzeTableStatementContext((AnalyzeTableStatement) sqlStatement); } if (sqlStatement instanceof FlushStatement) { - return new FlushStatementContext((FlushStatement) sqlStatement, currentDatabaseName); + return new FlushStatementContext((FlushStatement) sqlStatement); } if (sqlStatement instanceof OptimizeTableStatement) { - return new OptimizeTableStatementContext((OptimizeTableStatement) sqlStatement, currentDatabaseName); + return new OptimizeTableStatementContext((OptimizeTableStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java index a17889aa1a9a2..8264edfec5da4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java @@ -31,9 +31,9 @@ public final class AnalyzeTableStatementContext extends CommonSQLStatementContex private final TablesContext tablesContext; - public AnalyzeTableStatementContext(final AnalyzeTableStatement sqlStatement, final String currentDatabaseName) { + public AnalyzeTableStatementContext(final AnalyzeTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java index 57ed251ced076..b97ba364c0d28 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java @@ -37,9 +37,9 @@ public final class ExplainStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public ExplainStatementContext(final ExplainStatement sqlStatement, final String currentDatabaseName) { + public ExplainStatementContext(final ExplainStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(extractTablesFromExplain(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(extractTablesFromExplain(sqlStatement)); } private Collection extractTablesFromExplain(final ExplainStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java index 2854ff80d2825..0ce573efb189d 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java @@ -31,9 +31,9 @@ public final class FlushStatementContext extends CommonSQLStatementContext imple private final TablesContext tablesContext; - public FlushStatementContext(final FlushStatement sqlStatement, final String currentDatabaseName) { + public FlushStatementContext(final FlushStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java index bf9cedb76342b..2fd4a2c617042 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java @@ -31,9 +31,9 @@ public final class OptimizeTableStatementContext extends CommonSQLStatementConte private final TablesContext tablesContext; - public OptimizeTableStatementContext(final OptimizeTableStatement sqlStatement, final String currentDatabaseName) { + public OptimizeTableStatementContext(final OptimizeTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java index c0501b126805e..7f0279ba3e99c 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java @@ -36,9 +36,9 @@ public final class ShowColumnsStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public ShowColumnsStatementContext(final ShowColumnsStatement sqlStatement, final String currentDatabaseName) { + public ShowColumnsStatementContext(final ShowColumnsStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java index d626c28aa05ff..b6ab3f2293ddd 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java @@ -31,9 +31,9 @@ public final class ShowCreateTableStatementContext extends CommonSQLStatementCon private final TablesContext tablesContext; - public ShowCreateTableStatementContext(final ShowCreateTableStatement sqlStatement, final String currentDatabaseName) { + public ShowCreateTableStatementContext(final ShowCreateTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java index 2a0d3bd8a58c8..653da167b4177 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java @@ -36,9 +36,9 @@ public final class ShowIndexStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public ShowIndexStatementContext(final ShowIndexStatement sqlStatement, final String currentDatabaseName) { + public ShowIndexStatementContext(final ShowIndexStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java index 36010fb630246..49341412bb1f1 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java @@ -31,9 +31,9 @@ public final class DenyUserStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public DenyUserStatementContext(final DenyUserStatement sqlStatement, final String currentDatabaseName) { + public DenyUserStatementContext(final DenyUserStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java index 3c7acfa3d1d27..b7e62ab80077b 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java @@ -31,9 +31,9 @@ public final class GrantStatementContext extends CommonSQLStatementContext imple private final TablesContext tablesContext; - public GrantStatementContext(final GrantStatement sqlStatement, final String currentDatabaseName) { + public GrantStatementContext(final GrantStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java index 6a5ff0fb8975d..eec519646120a 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java @@ -31,9 +31,9 @@ public final class RevokeStatementContext extends CommonSQLStatementContext impl private final TablesContext tablesContext; - public RevokeStatementContext(final RevokeStatement sqlStatement, final String currentDatabaseName) { + public RevokeStatementContext(final RevokeStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java index 15da776f23e7b..28b335fdfa8da 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java @@ -39,10 +39,10 @@ public final class AlterIndexStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public AlterIndexStatementContext(final AlterIndexStatement sqlStatement, final String currentDatabaseName) { + public AlterIndexStatementContext(final AlterIndexStatement sqlStatement) { super(sqlStatement); SimpleTableSegment simpleTableSegment = sqlStatement.getSimpleTable().orElse(null); - tablesContext = new TablesContext(simpleTableSegment, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(simpleTableSegment); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java index 3dfe294409b5e..21be1d92fe533 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java @@ -48,9 +48,9 @@ public final class AlterTableStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public AlterTableStatementContext(final AlterTableStatement sqlStatement, final String currentDatabaseName) { + public AlterTableStatementContext(final AlterTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getTables(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getTables(sqlStatement)); } private Collection getTables(final AlterTableStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java index 5406c78f1be9c..1b0e25a3c07b0 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java @@ -38,7 +38,7 @@ public final class AlterViewStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public AlterViewStatementContext(final AlterViewStatement sqlStatement, final String currentDatabaseName) { + public AlterViewStatementContext(final AlterViewStatement sqlStatement) { super(sqlStatement); Collection tables = new LinkedList<>(); tables.add(sqlStatement.getView()); @@ -49,7 +49,7 @@ public AlterViewStatementContext(final AlterViewStatement sqlStatement, final St tables.addAll(extractor.getRewriteTables()); }); sqlStatement.getRenameView().ifPresent(tables::add); - tablesContext = new TablesContext(tables, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tables); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java index 95bb62adeb9a7..e8b4a9c867d1f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java @@ -44,9 +44,9 @@ public final class CloseStatementContext extends CommonSQLStatementContext imple private TablesContext tablesContext; - public CloseStatementContext(final CloseStatement sqlStatement, final String currentDatabaseName) { + public CloseStatementContext(final CloseStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(Collections.emptyList(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(Collections.emptyList()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java index 79605ca3ba48d..1fa10fbbc4ff4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java @@ -33,9 +33,9 @@ public final class CommentStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public CommentStatementContext(final CommentStatement sqlStatement, final String currentDatabaseName) { + public CommentStatementContext(final CommentStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(null == sqlStatement.getTable() ? Collections.emptyList() : Collections.singletonList(sqlStatement.getTable()), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(null == sqlStatement.getTable() ? Collections.emptyList() : Collections.singletonList(sqlStatement.getTable())); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java index a07f00f2a20ec..0264709615d3e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java @@ -37,11 +37,11 @@ public final class CreateFunctionStatementContext extends CommonSQLStatementCont private final TablesContext tablesContext; - public CreateFunctionStatementContext(final CreateFunctionStatement sqlStatement, final String currentDatabaseName) { + public CreateFunctionStatementContext(final CreateFunctionStatement sqlStatement) { super(sqlStatement); Optional routineBodySegment = sqlStatement.getRoutineBody(); Collection tables = routineBodySegment.map(optional -> new TableExtractor().extractExistTableFromRoutineBody(optional)).orElseGet(Collections::emptyList); - tablesContext = new TablesContext(tables, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tables); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java index 0b08db3bfaa62..e43ff274ecc79 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java @@ -42,9 +42,9 @@ public final class CreateIndexStatementContext extends CommonSQLStatementContext private final boolean generatedIndex; - public CreateIndexStatementContext(final CreateIndexStatement sqlStatement, final String currentDatabaseName) { + public CreateIndexStatementContext(final CreateIndexStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); generatedIndex = null == sqlStatement.getIndex(); } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java index b9ba75d010428..1bf88c0469827 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java @@ -37,11 +37,11 @@ public final class CreateProcedureStatementContext extends CommonSQLStatementCon private final TablesContext tablesContext; - public CreateProcedureStatementContext(final CreateProcedureStatement sqlStatement, final String currentDatabaseName) { + public CreateProcedureStatementContext(final CreateProcedureStatement sqlStatement) { super(sqlStatement); Optional routineBodySegment = sqlStatement.getRoutineBody(); Collection tables = routineBodySegment.map(optional -> new TableExtractor().extractExistTableFromRoutineBody(optional)).orElseGet(Collections::emptyList); - tablesContext = new TablesContext(tables, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tables); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java index d12cc0aa63b67..091fac0a2b574 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java @@ -42,9 +42,9 @@ public final class CreateTableStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public CreateTableStatementContext(final CreateTableStatement sqlStatement, final String currentDatabaseName) { + public CreateTableStatementContext(final CreateTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getTables(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getTables(sqlStatement)); } private Collection getTables(final CreateTableStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java index 83d2f8fd8d665..730d89b76db23 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java @@ -32,11 +32,11 @@ public final class CreateViewStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public CreateViewStatementContext(final CreateViewStatement sqlStatement, final String currentDatabaseName) { + public CreateViewStatementContext(final CreateViewStatement sqlStatement) { super(sqlStatement); TableExtractor extractor = new TableExtractor(); extractor.extractTablesFromCreateViewStatement(sqlStatement); - tablesContext = new TablesContext(extractor.getRewriteTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(extractor.getRewriteTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java index 4d6e67c71fe43..22c316fa3447f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java @@ -25,13 +25,13 @@ import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.cursor.CursorNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CursorStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import java.util.Collection; import java.util.Collections; @@ -57,7 +57,7 @@ public final class CursorStatementContext extends CommonSQLStatementContext impl public CursorStatementContext(final ShardingSphereMetaData metaData, final List params, final CursorStatement sqlStatement, final String currentDatabaseName) { super(sqlStatement); - tablesContext = new TablesContext(getSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getSimpleTableSegments()); selectStatementContext = new SelectStatementContext(metaData, params, sqlStatement.getSelect(), currentDatabaseName, Collections.emptyList()); whereSegments.addAll(selectStatementContext.getWhereSegments()); columnSegments.addAll(selectStatementContext.getColumnSegments()); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java index 0389b137afed8..88b389a5a1182 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java @@ -38,10 +38,10 @@ public final class DropIndexStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public DropIndexStatementContext(final DropIndexStatement sqlStatement, final String currentDatabaseName) { + public DropIndexStatementContext(final DropIndexStatement sqlStatement) { super(sqlStatement); SimpleTableSegment simpleTableSegment = sqlStatement.getSimpleTable().orElse(null); - tablesContext = new TablesContext(simpleTableSegment, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(simpleTableSegment); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java index 8babf0c8fa33a..9741d893d0d56 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java @@ -31,9 +31,9 @@ public final class DropTableStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public DropTableStatementContext(final DropTableStatement sqlStatement, final String currentDatabaseName) { + public DropTableStatementContext(final DropTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java index 99ae13b289faa..6c5d158a01c9f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java @@ -31,9 +31,9 @@ public final class DropViewStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public DropViewStatementContext(final DropViewStatement sqlStatement, final String currentDatabaseName) { + public DropViewStatementContext(final DropViewStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getViews(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getViews()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java index 385b1736a17dd..2dbb0dd950897 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java @@ -44,9 +44,9 @@ public final class FetchStatementContext extends CommonSQLStatementContext imple private TablesContext tablesContext; - public FetchStatementContext(final FetchStatement sqlStatement, final String currentDatabaseName) { + public FetchStatementContext(final FetchStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(Collections.emptyList(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(Collections.emptyList()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java index d3f91659fc6b8..380ea200bb974 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java @@ -44,9 +44,9 @@ public final class MoveStatementContext extends CommonSQLStatementContext implem private TablesContext tablesContext; - public MoveStatementContext(final MoveStatement sqlStatement, final String currentDatabaseName) { + public MoveStatementContext(final MoveStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(Collections.emptyList(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(Collections.emptyList()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java index a97c1d8eaa9c5..007a3eda53d0c 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java @@ -36,9 +36,9 @@ public final class PrepareStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public PrepareStatementContext(final PrepareStatement sqlStatement, final String currentDatabaseName) { + public PrepareStatementContext(final PrepareStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(extractTablesFromPreparedStatement(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(extractTablesFromPreparedStatement(sqlStatement)); } private Collection extractTablesFromPreparedStatement(final PrepareStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java index 34d4b87f68fc9..550f36707ec9a 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java @@ -36,9 +36,9 @@ public final class RenameTableStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public RenameTableStatementContext(final RenameTableStatement sqlStatement, final String currentDatabaseName) { + public RenameTableStatementContext(final RenameTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getTables(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getTables(sqlStatement)); } private Collection getTables(final RenameTableStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java index b4a5d8323957a..e97aa018d29e8 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java @@ -31,9 +31,9 @@ public final class TruncateStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public TruncateStatementContext(final TruncateStatement sqlStatement, final String currentDatabaseName) { + public TruncateStatementContext(final TruncateStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java index 4b157bd6969db..ce39780ad4858 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java @@ -31,9 +31,9 @@ public final class CopyStatementContext extends CommonSQLStatementContext implem private final TablesContext tablesContext; - public CopyStatementContext(final CopyStatement sqlStatement, final String currentDatabaseName) { + public CopyStatementContext(final CopyStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTableSegment(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTableSegment()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java index 4bde06fb361cd..d5a01ab9b1eb8 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java @@ -50,9 +50,9 @@ public final class DeleteStatementContext extends CommonSQLStatementContext impl private final Collection joinConditions = new LinkedList<>(); - public DeleteStatementContext(final DeleteStatement sqlStatement, final String currentDatabaseName) { + public DeleteStatementContext(final DeleteStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getAllSimpleTableSegments()); getSqlStatement().getWhere().ifPresent(whereSegments::add); ColumnExtractor.extractColumnSegments(columnSegments, whereSegments); ExpressionExtractor.extractJoinConditions(joinConditions, whereSegments); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java index 2f48a3daada07..4b8de3e31b5e6 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java @@ -37,6 +37,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.sql.parser.statement.core.enums.SubqueryType; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.InsertValuesSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; @@ -49,7 +50,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import java.util.ArrayList; import java.util.Collection; @@ -101,7 +101,7 @@ public InsertStatementContext(final ShardingSphereMetaData metaData, final List< insertValueContexts = getInsertValueContexts(params, parametersOffset, valueExpressions); insertSelectContext = getInsertSelectContext(metaData, params, parametersOffset, currentDatabaseName).orElse(null); onDuplicateKeyUpdateValueContext = getOnDuplicateKeyUpdateValueContext(params, parametersOffset).orElse(null); - tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getAllSimpleTableSegments()); List insertColumnNames = getInsertColumnNames(); ShardingSphereSchema schema = getSchema(metaData, currentDatabaseName); columnNames = containsInsertColumns() diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java index 6b172406f9117..8cb65ff7e9be8 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java @@ -31,9 +31,9 @@ public final class LoadDataStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public LoadDataStatementContext(final LoadDataStatement sqlStatement, final String currentDatabaseName) { + public LoadDataStatementContext(final LoadDataStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTableSegment(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTableSegment()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java index d4d804d138c0c..a3a32ca505e82 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java @@ -31,9 +31,9 @@ public final class LoadXMLStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public LoadXMLStatementContext(final LoadXMLStatement sqlStatement, final String currentDatabaseName) { + public LoadXMLStatementContext(final LoadXMLStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTableSegment(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTableSegment()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java index b094b2e3dc71b..36d9a28221d11 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java @@ -120,7 +120,7 @@ public SelectStatementContext(final ShardingSphereMetaData metaData, final List< Collection tableSegments = getAllTableSegments(inheritedTables); ExpressionExtractor.extractJoinConditions(joinConditions, whereSegments); subqueryContexts = createSubqueryContexts(metaData, params, currentDatabaseName, tableSegments); - tablesContext = new TablesContext(tableSegments, subqueryContexts, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tableSegments, subqueryContexts); groupByContext = new GroupByContextEngine().createGroupByContext(sqlStatement); orderByContext = new OrderByContextEngine().createOrderBy(sqlStatement, groupByContext); projectionsContext = new ProjectionsContextEngine(getDatabaseType()).createProjectionsContext(getSqlStatement().getProjections(), groupByContext, orderByContext); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java index bf0938e4b04a1..b8f1ad79bdcf4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java @@ -22,14 +22,14 @@ import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import java.util.Collection; import java.util.LinkedList; @@ -48,9 +48,9 @@ public final class UpdateStatementContext extends CommonSQLStatementContext impl private final Collection joinConditions = new LinkedList<>(); - public UpdateStatementContext(final UpdateStatement sqlStatement, final String currentDatabaseName) { + public UpdateStatementContext(final UpdateStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getAllSimpleTableSegments()); getSqlStatement().getWhere().ifPresent(whereSegments::add); ColumnExtractor.extractColumnSegments(columnSegments, whereSegments); ExpressionExtractor.extractJoinConditions(joinConditions, whereSegments); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java index e77dc4f7f4ebe..be851ce38965e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java @@ -89,6 +89,7 @@ public static SimpleTableSegment bind(final SimpleTableSegment segment, final SQ tableBinderContexts.put(new CaseInsensitiveString(segment.getAliasName().orElseGet(tableName::getValue)), createSimpleTableBinderContext(segment, schema, databaseName, schemaName, binderContext)); TableNameSegment tableNameSegment = new TableNameSegment(segment.getTableName().getStartIndex(), segment.getTableName().getStopIndex(), tableName); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(databaseName, schemaName)); SimpleTableSegment result = new SimpleTableSegment(tableNameSegment); segment.getOwner().ifPresent(result::setOwner); segment.getAliasSegment().ifPresent(result::setAlias); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java index 3abaf2d0df173..145801229a9a5 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.IndexOrderByItemSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; @@ -126,6 +127,7 @@ private void assertProjectionsContextCreatedProperlyWhenProjectionPresent(final selectStatement.setProjections(projectionsSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement); @@ -164,6 +166,7 @@ private void createProjectionsContextWhenOrderByContextOrderItemsPresent(final S selectStatement.setProjections(projectionsSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new IndexOrderByItemSegment(0, 1, 0, OrderDirection.ASC, NullsOrderType.FIRST)); @@ -204,6 +207,7 @@ private void assertCreateProjectionsContextWithoutIndexOrderByItemSegment(final selectStatement.setProjections(projectionsSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 1, "", OrderDirection.ASC, NullsOrderType.FIRST)); @@ -248,9 +252,12 @@ void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerAbsentForSQL private void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerAbsent(final SelectStatement selectStatement) { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("name")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("name")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderType.FIRST)); @@ -289,9 +296,12 @@ void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresentForSQ private void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresent(final SelectStatement selectStatement) { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("name")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("name")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderType.FIRST)); @@ -328,14 +338,17 @@ void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresentAndTa } private void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresentAndTablePresent(final SelectStatement selectStatement) { - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("name"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 10, new IdentifierValue("name")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db"))); selectStatement.setFrom(tableSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); - SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("name"))); + SimpleTableSegment table = new SimpleTableSegment(tableNameSegment); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); table.setOwner(new OwnerSegment(0, 10, new IdentifierValue("name"))); shorthandProjectionSegment.setOwner(owner); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("col")); @@ -447,7 +460,9 @@ void assertCreateProjectionsContextWithOrderByExpressionForMySQL() { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(new ShorthandProjectionSegment(0, 0)); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 0, "id + 1", OrderDirection.ASC, NullsOrderType.FIRST)); OrderByContext orderByContext = new OrderByContext(Collections.singleton(orderByItem), false); SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java index 6beda71aba140..377c317dfb3da 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java @@ -17,14 +17,13 @@ package org.apache.shardingsphere.infra.binder.context.segment.table; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment; @@ -47,92 +46,94 @@ class TablesContextTest { - private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); - @Test void assertGetTableNamesWithoutTableSegments() { - assertTrue(new TablesContext(Collections.emptyList(), Collections.emptyMap(), databaseType, "foo_db").getTableNames().isEmpty()); + assertTrue(new TablesContext(Collections.emptyList(), Collections.emptyMap()).getTableNames().isEmpty()); } @Test void assertGetTableNamesWithoutSimpleTableSegments() { - assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class)), Collections.emptyMap(), databaseType, "foo_db").getTableNames().isEmpty()); + assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class)), Collections.emptyMap()).getTableNames().isEmpty()); } @Test void assertGetTableNames() { TablesContext tablesContext = new TablesContext( - Arrays.asList(createTableSegment("table_1", "tbl_1"), createTableSegment("table_2", "tbl_2"), createTableSegment("DUAL", "dual")), databaseType, "foo_db"); + Arrays.asList(createTableSegment("table_1", "tbl_1", "sharding_db_1"), createTableSegment("table_2", "tbl_2", "sharding_db_1"), createTableSegment("DUAL", "dual", "sharding_db_1"))); assertThat(tablesContext.getTableNames(), is(new HashSet<>(Arrays.asList("table_1", "table_2")))); } @Test void assertInstanceCreatedWhenNoExceptionThrown() { - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("tbl"))); - tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("schema"))); - TablesContext tablesContext = new TablesContext(Collections.singleton(tableSegment), databaseType, "foo_db"); - assertThat(tablesContext.getDatabaseName(), is(Optional.of("schema"))); - assertThat(tablesContext.getSchemaName(), is(Optional.of("schema"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 10, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); + tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db"))); + TablesContext tablesContext = new TablesContext(Collections.singleton(tableSegment)); + assertThat(tablesContext.getDatabaseName(), is(Optional.of("foo_db"))); + assertThat(tablesContext.getSchemaName(), is(Optional.of("foo_db"))); assertThat(tablesContext.getTableNames(), is(Collections.singleton("tbl"))); } @Test void assertFindTableNameWhenSingleTable() { - SimpleTableSegment tableSegment = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment = createTableSegment("table_1", "tbl_1", "sharding_db_1"); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Collections.singletonList(tableSegment), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock()); + Map actual = new TablesContext(Collections.singletonList(tableSegment)).findTableNames(Collections.singletonList(columnSegment), mock()); assertFalse(actual.isEmpty()); assertThat(actual.get("col"), is("table_1")); } @Test void assertFindTableNameWhenColumnSegmentOwnerPresent() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); ColumnSegment columnSegment = createColumnSegment("table_1", "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock()); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), mock()); assertFalse(actual.isEmpty()); assertThat(actual.get("table_1.col"), is("table_1")); } @Test void assertFindTableNameWhenColumnSegmentOwnerAbsent() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock()); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), mock()); assertTrue(actual.isEmpty()); } @Test void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsColumn() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("table_1")).thenReturn(true); ShardingSphereTable table = mock(ShardingSphereTable.class); when(table.containsColumn("col")).thenReturn(true); when(schema.getTable("table_1")).thenReturn(table); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), schema); assertThat(actual.get("col"), is("table_1")); } @Test void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsColumnInUpperCase() { - SimpleTableSegment tableSegment1 = createTableSegment("TABLE_1", "TBL_1"); - SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", "TBL_2"); + SimpleTableSegment tableSegment1 = createTableSegment("TABLE_1", "TBL_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", "TBL_2", "sharding_db_1"); ShardingSphereTable table = new ShardingSphereTable("TABLE_1", Collections.singletonList(new ShardingSphereColumn("COL", 0, false, false, true, true, false, false)), Collections.emptyList(), Collections.emptyList()); ShardingSphereSchema schema = new ShardingSphereSchema("foo_db", Collections.singleton(table), Collections.emptyList()); ColumnSegment columnSegment = createColumnSegment(null, "COL"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), schema); assertFalse(actual.isEmpty()); assertThat(actual.get("col"), is("TABLE_1")); } - private SimpleTableSegment createTableSegment(final String tableName, final String alias) { - SimpleTableSegment result = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(tableName))); + private SimpleTableSegment createTableSegment(final String tableName, final String alias, final String databaseName) { + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue(tableName)); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(databaseName), new IdentifierValue(databaseName))); + SimpleTableSegment result = new SimpleTableSegment(tableNameSegment); AliasSegment aliasSegment = new AliasSegment(0, 0, new IdentifierValue(alias)); result.setAlias(aliasSegment); return result; @@ -148,51 +149,51 @@ private ColumnSegment createColumnSegment(final String owner, final String name) @Test void assertGetSchemaNameWithSameSchemaAndSameTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)); assertTrue(tablesContext.getDatabaseName().isPresent()); assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1")); } @Test void assertGetSchemaNameWithSameSchemaAndDifferentTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)); assertTrue(tablesContext.getDatabaseName().isPresent()); assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1")); } @Test void assertGetSchemaNameWithDifferentSchemaAndSameTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1", "sharding_db_2"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2"))); - assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName()); + assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).getDatabaseName()); } @Test void assertGetSchemaNameWithDifferentSchemaAndDifferentTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_2"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2"))); - assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName()); + assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).getDatabaseName()); } @Test void assertGetSchemaName() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)); assertTrue(tablesContext.getSchemaName().isPresent()); assertThat(tablesContext.getSchemaName().get(), is("sharding_db_1")); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java index b7a3b7c303273..c1df0eb15adc1 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.AnalyzeTableStatement; @@ -36,7 +37,7 @@ class AnalyzeTableStatementContextTest { @Test - void assertMysqlNewInstance() { + void assertMySQLNewInstance() { assertNewInstance(new MySQLAnalyzeTableStatement()); } @@ -46,10 +47,14 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final AnalyzeTableStatement analyzeTableStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); analyzeTableStatement.getTables().addAll(Arrays.asList(table1, table2)); - AnalyzeTableStatementContext actual = new AnalyzeTableStatementContext(analyzeTableStatement, "foo_db"); + AnalyzeTableStatementContext actual = new AnalyzeTableStatementContext(analyzeTableStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(analyzeTableStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2"))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java index fda4d10df6e39..76b7dc2f3096b 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java @@ -48,7 +48,7 @@ void assertPostgreSQLNewInstance() { private void assertNewInstance(final ExplainStatement explainStatement) { SQLStatement statement = mock(SQLStatement.class); when(explainStatement.getSqlStatement()).thenReturn(Optional.of(statement)); - ExplainStatementContext actual = new ExplainStatementContext(explainStatement, "foo_db"); + ExplainStatementContext actual = new ExplainStatementContext(explainStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(explainStatement)); assertThat(actual.getSqlStatement().getSqlStatement().orElse(null), is(statement)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java index 8fb44f8d550c9..3e6576d9b27e6 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; @@ -36,8 +37,10 @@ class OptimizeTableStatementContextTest { @Test void assertNewInstance() { MySQLOptimizeTableStatement sqlStatement = new MySQLOptimizeTableStatement(); - sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1")))); - OptimizeTableStatementContext actual = new OptimizeTableStatementContext(sqlStatement, "foo_db"); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.getTables().add(new SimpleTableSegment(tableNameSegment)); + OptimizeTableStatementContext actual = new OptimizeTableStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java index 35bbd289fdc55..5fb7bc6768e81 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromDatabaseSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; @@ -38,10 +39,12 @@ class ShowColumnsStatementContextTest { @Test void assertNewInstance() { MySQLShowColumnsStatement sqlStatement = new MySQLShowColumnsStatement(); - sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.setTable(new SimpleTableSegment(tableNameSegment)); FromDatabaseSegment fromDatabase = new FromDatabaseSegment(0, 0, new DatabaseSegment(0, 0, new IdentifierValue("foo_db"))); sqlStatement.setFromDatabase(fromDatabase); - ShowColumnsStatementContext actual = new ShowColumnsStatementContext(sqlStatement, "foo_db"); + ShowColumnsStatementContext actual = new ShowColumnsStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java index 8495b3f077878..9eb20175d8928 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; @@ -36,8 +37,10 @@ class ShowCreateTableStatementContextTest { @Test void assertNewInstance() { MySQLShowCreateTableStatement sqlStatement = new MySQLShowCreateTableStatement(); - sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); - ShowCreateTableStatementContext actual = new ShowCreateTableStatementContext(sqlStatement, "foo_db"); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.setTable(new SimpleTableSegment(tableNameSegment)); + ShowCreateTableStatementContext actual = new ShowCreateTableStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java index 602ebb2c4e9e1..0893b896fde29 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; @@ -36,8 +37,10 @@ class ShowIndexStatementContextTest { @Test void assertNewInstance() { MySQLShowIndexStatement sqlStatement = new MySQLShowIndexStatement(); - sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); - ShowIndexStatementContext actual = new ShowIndexStatementContext(sqlStatement, "foo_db"); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.setTable(new SimpleTableSegment(tableNameSegment)); + ShowIndexStatementContext actual = new ShowIndexStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java index ad7f4fabda468..bbd448dc87f19 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dcl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; @@ -36,9 +37,11 @@ class DenyUserStatementContextTest { @Test void assertNewInstance() { SQLServerDenyUserStatement sqlStatement = new SQLServerDenyUserStatement(); - SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table = new SimpleTableSegment(tableNameSegment); sqlStatement.setTable(table); - DenyUserStatementContext actual = new DenyUserStatementContext(sqlStatement, "foo_db"); + DenyUserStatementContext actual = new DenyUserStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java index 08f0b286caea2..5d52f83f74967 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dcl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.GrantStatement; @@ -64,10 +65,14 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final GrantStatement grantStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("bar_tbl"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("bar_tbl")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); grantStatement.getTables().addAll(Arrays.asList(table1, table2)); - GrantStatementContext actual = new GrantStatementContext(grantStatement, "foo_db"); + GrantStatementContext actual = new GrantStatementContext(grantStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(grantStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java index af3f91c127f48..b8a18d75a37dd 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dcl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.RevokeStatement; @@ -64,10 +65,14 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final RevokeStatement revokeStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("bar_tbl"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("bar_tbl")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); revokeStatement.getTables().addAll(Arrays.asList(table1, table2)); - RevokeStatementContext actual = new RevokeStatementContext(revokeStatement, "foo_db"); + RevokeStatementContext actual = new RevokeStatementContext(revokeStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(revokeStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java index 3ffcca418e53f..dddcf50d788ab 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java @@ -57,7 +57,7 @@ void assertSQLServerNewInstance() { private void assertNewInstance(final AlterIndexStatement alterIndexStatement) { IndexSegment indexSegment = new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index_1"))); when(alterIndexStatement.getIndex()).thenReturn(Optional.of(indexSegment)); - AlterIndexStatementContext actual = new AlterIndexStatementContext(alterIndexStatement, "foo_db"); + AlterIndexStatementContext actual = new AlterIndexStatementContext(alterIndexStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(alterIndexStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.emptyList())); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java index 8567b81cd23f1..945ef575558f4 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.DropIndexDefinitionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTableStatement; @@ -80,8 +81,12 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final AlterTableStatement alterTableStatement) { - SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment renameTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("rename_tbl_1"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("rename_tbl_1")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment renameTable = new SimpleTableSegment(tableNameSegment2); alterTableStatement.setTable(table); alterTableStatement.setRenameTable(renameTable); Collection referencedTables = Collections.singletonList(table); @@ -110,7 +115,7 @@ private void assertNewInstance(final AlterTableStatement alterTableStatement) { DropIndexDefinitionSegment dropIndexDefinitionSegment = mock(DropIndexDefinitionSegment.class); when(dropIndexDefinitionSegment.getIndexSegment()).thenReturn(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("drop_index")))); alterTableStatement.getDropIndexDefinitions().add(dropIndexDefinitionSegment); - AlterTableStatementContext actual = new AlterTableStatementContext(alterTableStatement, "foo_db"); + AlterTableStatementContext actual = new AlterTableStatementContext(alterTableStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(alterTableStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java index 1da87742c075f..0feea9fbeddb0 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.ddl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterViewStatement; @@ -43,7 +44,9 @@ class AlterViewStatementContextTest { @BeforeEach void setUp() { - view = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("view"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("view")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + view = new SimpleTableSegment(tableNameSegment); } @Test @@ -60,12 +63,14 @@ void assertMySQLNewInstance() { void assertPostgreSQLNewInstance() { PostgreSQLAlterViewStatement alterViewStatement = new PostgreSQLAlterViewStatement(); alterViewStatement.setView(view); - alterViewStatement.setRenameView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("view")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("view")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + alterViewStatement.setRenameView(new SimpleTableSegment(tableNameSegment)); assertNewInstance(alterViewStatement); } private void assertNewInstance(final AlterViewStatement alterViewStatement) { - AlterViewStatementContext actual = new AlterViewStatementContext(alterViewStatement, "foo_db"); + AlterViewStatementContext actual = new AlterViewStatementContext(alterViewStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(alterViewStatement)); assertThat(actual.getTablesContext().getSimpleTables().size(), is(2)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java index 3a35101c12361..594602813481e 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java @@ -47,7 +47,7 @@ void assertSQLServerNewInstance() { } private void assertNewInstance(final CreateFunctionStatement createDatabaseStatement) { - CreateFunctionStatementContext actual = new CreateFunctionStatementContext(createDatabaseStatement, "foo_db"); + CreateFunctionStatementContext actual = new CreateFunctionStatementContext(createDatabaseStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createDatabaseStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java index 93af84f0b560c..e162431b56627 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java @@ -61,14 +61,14 @@ void assertSQLServerSQLNewInstance() { } private void assertNewInstance(final CreateIndexStatement createIndexStatement) { - CreateIndexStatementContext actual = new CreateIndexStatementContext(createIndexStatement, "foo_db"); + CreateIndexStatementContext actual = new CreateIndexStatementContext(createIndexStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createIndexStatement)); assertTrue(actual.isGeneratedIndex()); assertThat(actual.getTablesContext().getSimpleTables(), is(Collections.emptyList())); assertThat(actual.getIndexes(), is(Collections.emptyList())); when(createIndexStatement.getIndex()).thenReturn(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index_2")))); - CreateIndexStatementContext actual2 = new CreateIndexStatementContext(createIndexStatement, "foo_db"); + CreateIndexStatementContext actual2 = new CreateIndexStatementContext(createIndexStatement); assertThat(actual2.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_2"))); } } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java index 3c57c0e7ad7c1..15af5fd7d38df 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java @@ -41,7 +41,7 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final CreateProcedureStatement createProcedureStatement) { - CreateProcedureStatementContext actual = new CreateProcedureStatementContext(createProcedureStatement, "foo_db"); + CreateProcedureStatementContext actual = new CreateProcedureStatementContext(createProcedureStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createProcedureStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java index b6acd3c670334..9f256f9c9335e 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java @@ -73,7 +73,7 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final CreateTableStatement createTableStatement) { - CreateTableStatementContext actual = new CreateTableStatementContext(createTableStatement, "foo_db"); + CreateTableStatementContext actual = new CreateTableStatementContext(createTableStatement); SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); when(createTableStatement.getTable()).thenReturn(table); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java index cd584254ea5ae..5a59b58cc00b9 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.ddl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateViewStatement; @@ -45,10 +46,12 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final CreateViewStatement createViewStatement) { - SimpleTableSegment view = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("view"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("view")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment view = new SimpleTableSegment(tableNameSegment); createViewStatement.setView(view); createViewStatement.setSelect(mock(SelectStatement.class)); - CreateViewStatementContext actual = new CreateViewStatementContext(createViewStatement, "foo_db"); + CreateViewStatementContext actual = new CreateViewStatementContext(createViewStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createViewStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java index 59459297a060f..30f88aa9eaeae 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java @@ -69,7 +69,7 @@ private void assertNewInstance(final DropIndexStatement dropIndexStatement) { indexes.add(index1); indexes.add(index2); when(dropIndexStatement.getIndexes()).thenReturn(indexes); - DropIndexStatementContext actual = new DropIndexStatementContext(dropIndexStatement, "foo_db"); + DropIndexStatementContext actual = new DropIndexStatementContext(dropIndexStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(dropIndexStatement)); assertThat(actual.getTablesContext().getSimpleTables(), is(Collections.emptyList())); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java index 0fe7f4e2f0193..54104522fae81 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java @@ -65,7 +65,7 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final DropTableStatement dropTableStatement) { - DropTableStatementContext actual = new DropTableStatementContext(dropTableStatement, "foo_db"); + DropTableStatementContext actual = new DropTableStatementContext(dropTableStatement); SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); when(dropTableStatement.getTables()).thenReturn(Arrays.asList(table1, table2)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java index 068deaee09768..cdc1720e1beb6 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.ddl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropViewStatement; @@ -45,10 +46,14 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final DropViewStatement dropViewStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); dropViewStatement.getViews().addAll(Arrays.asList(table1, table2)); - DropViewStatementContext actual = new DropViewStatementContext(dropViewStatement, "foo_db"); + DropViewStatementContext actual = new DropViewStatementContext(dropViewStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(dropViewStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java index 5f85b0745ebdf..4b32d861ac89f 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; @@ -52,7 +53,9 @@ class PrepareStatementContextTest { @BeforeEach void setUp() { - table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + table = new SimpleTableSegment(tableNameSegment); column = new ColumnSegment(0, 0, new IdentifierValue("col_1")); } @@ -63,7 +66,7 @@ void assertNewInstance() { sqlStatement.setInsert(getInsert()); sqlStatement.setUpdate(getUpdate()); sqlStatement.setDelete(getDelete()); - PrepareStatementContext actual = new PrepareStatementContext(sqlStatement, "foo_db"); + PrepareStatementContext actual = new PrepareStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java index 6acd2a9bc561d..8574372855ef4 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.ddl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.TruncateStatement; @@ -58,10 +59,14 @@ void assertSQLServerNewInstance() { } private void assertNewInstance(final TruncateStatement truncateStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); truncateStatement.getTables().addAll(Arrays.asList(table1, table2)); - TruncateStatementContext actual = new TruncateStatementContext(truncateStatement, "foo_db"); + TruncateStatementContext actual = new TruncateStatementContext(truncateStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(truncateStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2"))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java index c010c6ada9c5d..1b828ebf4e3a4 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; @@ -77,14 +78,18 @@ void assertSQLServerNewInstance() { private void assertNewInstance(final DeleteStatement deleteStatement) { when(whereSegment.getExpr()).thenReturn(mock(ExpressionSegment.class)); - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); JoinTableSegment tableSegment = new JoinTableSegment(); tableSegment.setLeft(table1); tableSegment.setRight(table2); deleteStatement.setWhere(whereSegment); deleteStatement.setTable(tableSegment); - DeleteStatementContext actual = new DeleteStatementContext(deleteStatement, "foo_db"); + DeleteStatementContext actual = new DeleteStatementContext(deleteStatement); assertThat(actual.getTablesContext().getTableNames(), is(new HashSet<>(Arrays.asList("tbl_1", "tbl_2")))); assertThat(actual.getWhereSegments(), is(Collections.singletonList(whereSegment))); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2"))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java index 0665b71acfe55..17da31d5c807d 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; @@ -92,7 +93,9 @@ void assertSQLServerInsertStatementContextWithColumnNames() { } private void assertInsertStatementContextWithColumnNames(final InsertStatement insertStatement) { - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db".toUpperCase()))); insertStatement.setTable(tableSegment); InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0, Arrays.asList( @@ -125,7 +128,9 @@ private String getSchemaName(final InsertStatement insertStatement) { @Test void assertInsertStatementContextWithoutColumnNames() { InsertStatement insertStatement = new MySQLInsertStatement(); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); setUpInsertValues(insertStatement); InsertStatementContext actual = createInsertStatementContext(Arrays.asList(1, "Tom", 2, "Jerry"), insertStatement); actual.setUpParameters(Arrays.asList(1, "Tom", 2, "Jerry")); @@ -135,7 +140,9 @@ void assertInsertStatementContextWithoutColumnNames() { @Test void assertGetGroupedParametersWithoutOnDuplicateParameter() { InsertStatement insertStatement = new MySQLInsertStatement(); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); setUpInsertValues(insertStatement); InsertStatementContext actual = createInsertStatementContext(Arrays.asList(1, "Tom", 2, "Jerry"), insertStatement); actual.setUpParameters(Arrays.asList(1, "Tom", 2, "Jerry")); @@ -147,7 +154,9 @@ void assertGetGroupedParametersWithoutOnDuplicateParameter() { @Test void assertGetGroupedParametersWithOnDuplicateParameters() { MySQLInsertStatement insertStatement = new MySQLInsertStatement(); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); setUpInsertValues(insertStatement); setUpOnDuplicateValues(insertStatement); InsertStatementContext actual = createInsertStatementContext(Arrays.asList(1, "Tom", 2, "Jerry", "onDuplicateKeyUpdateColumnValue"), insertStatement); @@ -165,7 +174,9 @@ void assertInsertSelect() { selectStatement.setProjections(new ProjectionsSegment(0, 0)); SubquerySegment insertSelect = new SubquerySegment(0, 0, selectStatement, ""); insertStatement.setInsertSelect(insertSelect); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext actual = createInsertStatementContext(Collections.singletonList("param"), insertStatement); actual.setUpParameters(Collections.singletonList("param")); assertThat(actual.getInsertSelectContext().getParameterCount(), is(1)); @@ -246,7 +257,9 @@ void assertUseDefaultColumnsForSQLServer() { } private void assertNotContainsInsertColumns(final InsertStatement insertStatement) { - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertFalse(insertStatementContext.containsInsertColumns()); } @@ -279,7 +292,9 @@ void assertNotUseDefaultColumnsWithColumnsForSQLServer() { private void assertContainsInsertColumns(final InsertStatement insertStatement) { InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0, Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("col")))); insertStatement.setInsertColumns(insertColumnsSegment); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertTrue(insertStatementContext.containsInsertColumns()); } @@ -288,7 +303,9 @@ private void assertContainsInsertColumns(final InsertStatement insertStatement) void assertContainsInsertColumnsWithSetAssignmentForMySQL() { MySQLInsertStatement insertStatement = new MySQLInsertStatement(); insertStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.emptyList())); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertTrue(insertStatementContext.containsInsertColumns()); } @@ -321,7 +338,9 @@ void assertGetValueListCountWithValuesForSQLServer() { private void assertGetValueListCountWithValues(final InsertStatement insertStatement) { insertStatement.getValues().add(new InsertValuesSegment(0, 0, Collections.singletonList(new LiteralExpressionSegment(0, 0, 1)))); insertStatement.getValues().add(new InsertValuesSegment(0, 0, Collections.singletonList(new LiteralExpressionSegment(0, 0, 2)))); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertThat(insertStatementContext.getValueListCount(), is(2)); } @@ -333,7 +352,9 @@ void assertGetValueListCountWithSetAssignmentForMySQL() { columns.add(new ColumnSegment(0, 0, new IdentifierValue("col"))); ColumnAssignmentSegment insertStatementAssignment = new ColumnAssignmentSegment(0, 0, columns, new LiteralExpressionSegment(0, 0, 1)); insertStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.singletonList(insertStatementAssignment))); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertThat(insertStatementContext.getValueListCount(), is(1)); } @@ -366,7 +387,9 @@ void assertGetInsertColumnNamesForInsertColumnsForSQLServer() { private void assertGetInsertColumnNamesForInsertColumns(final InsertStatement insertStatement) { InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0, Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("col")))); insertStatement.setInsertColumns(insertColumnsSegment); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); List columnNames = insertStatementContext.getInsertColumnNames(); assertThat(columnNames.size(), is(1)); @@ -380,7 +403,9 @@ void assertGetInsertColumnNamesForSetAssignmentForMySQL() { columns.add(new ColumnSegment(0, 0, new IdentifierValue("col"))); ColumnAssignmentSegment insertStatementAssignment = new ColumnAssignmentSegment(0, 0, columns, new LiteralExpressionSegment(0, 0, 1)); insertStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.singletonList(insertStatementAssignment))); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); List columnNames = insertStatementContext.getInsertColumnNames(); assertThat(columnNames.size(), is(1)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java index 54a25eb915ab6..2f4ebfcd27ab3 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java @@ -48,6 +48,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment; @@ -108,10 +109,12 @@ void assertSetIndexForItemsByIndexOrderByForSQLServer() { } private void assertSetIndexForItemsByIndexOrderBy(final SelectStatement selectStatement) { - ShardingSphereDatabase database = mockDatabase(); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(INDEX_ORDER_BY)))); selectStatement.setProjections(createProjectionsSegment()); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("table")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("table")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); + ShardingSphereDatabase database = mockDatabase(); SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList()); selectStatementContext.setIndexes(Collections.emptyMap()); @@ -155,7 +158,9 @@ void assertSetIndexForItemsByColumnOrderByWithOwnerForSQLServer() { private void assertSetIndexForItemsByColumnOrderByWithOwner(final SelectStatement selectStatement) { selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITH_OWNER)))); selectStatement.setProjections(createProjectionsSegment()); - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("table"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("table")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db".toUpperCase()))); selectStatement.setFrom(tableSegment); ShardingSphereDatabase database = mockDatabase(); @@ -591,7 +596,9 @@ private OrderByItemSegment createOrderByItemSegment(final String type) { return new IndexOrderByItemSegment(0, 0, 4, OrderDirection.ASC, NullsOrderType.FIRST); case COLUMN_ORDER_BY_WITH_OWNER: ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("name")); - columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("table"))); + OwnerSegment owner = new OwnerSegment(0, 0, new IdentifierValue("table")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + columnSegment.setOwner(owner); return new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, NullsOrderType.FIRST); case COLUMN_ORDER_BY_WITH_ALIAS: return new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("n")), OrderDirection.ASC, NullsOrderType.FIRST); @@ -601,16 +608,17 @@ private OrderByItemSegment createOrderByItemSegment(final String type) { } private ProjectionsSegment createProjectionsSegment() { - ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); - projectionsSegment.setDistinctRow(true); - projectionsSegment.getProjections().addAll(Arrays.asList(getColumnProjectionSegmentWithoutOwner(), - getColumnProjectionSegmentWithoutOwner(true), getColumnProjectionSegmentWithoutOwner(false))); - return projectionsSegment; + ProjectionsSegment result = new ProjectionsSegment(0, 0); + result.setDistinctRow(true); + result.getProjections().addAll(Arrays.asList(getColumnProjectionSegmentWithoutOwner(), getColumnProjectionSegmentWithoutOwner(true), getColumnProjectionSegmentWithoutOwner(false))); + return result; } private ProjectionSegment getColumnProjectionSegmentWithoutOwner() { ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("name")); - columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("table"))); + OwnerSegment owner = new OwnerSegment(0, 0, new IdentifierValue("table")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + columnSegment.setOwner(owner); return new ColumnProjectionSegment(columnSegment); } @@ -627,7 +635,9 @@ void assertIsContainsEnhancedTable() { projectionsSegment.getProjections().add(new ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("order_id")))); SelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); ShardingSphereMetaData metaData = new ShardingSphereMetaData( Collections.singleton(mockDatabase()), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class)); SelectStatementContext actual = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList()); @@ -650,7 +660,9 @@ private SelectStatement createSubSelectStatement() { projectionsSegment.getProjections().add(new ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("order_id")))); SelectStatement result = new MySQLSelectStatement(); result.setProjections(projectionsSegment); - result.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + result.setFrom(new SimpleTableSegment(tableNameSegment)); return result; } } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java index e9b80e88fdbf6..4420b6749c6c1 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; @@ -54,11 +55,17 @@ class UpdateStatementContextTest { @Test void assertNewInstance() { - when(columnSegment.getOwner()).thenReturn(Optional.of(new OwnerSegment(0, 0, new IdentifierValue("tbl_2")))); + OwnerSegment ownerSegment = new OwnerSegment(0, 0, new IdentifierValue("tbl_2")); + ownerSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + when(columnSegment.getOwner()).thenReturn(Optional.of(ownerSegment)); BinaryOperationExpression expression = new BinaryOperationExpression(0, 0, columnSegment, null, null, null); when(whereSegment.getExpr()).thenReturn(expression); - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); JoinTableSegment joinTableSegment = new JoinTableSegment(); joinTableSegment.setLeft(table1); joinTableSegment.setRight(table2); @@ -66,7 +73,7 @@ void assertNewInstance() { updateStatement.setWhere(whereSegment); updateStatement.setTable(joinTableSegment); updateStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.emptyList())); - UpdateStatementContext actual = new UpdateStatementContext(updateStatement, "foo_db"); + UpdateStatementContext actual = new UpdateStatementContext(updateStatement); assertThat(actual.getTablesContext().getTableNames(), is(new HashSet<>(Arrays.asList("tbl_1", "tbl_2")))); assertThat(actual.getWhereSegments(), is(Collections.singletonList(whereSegment))); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java index 149449f5e1a7d..88450ae0fbd8e 100644 --- a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java +++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; @@ -65,7 +66,7 @@ void assertExecuteSQL() { ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); ExecutionGroupContext executionGroupContext = mockExecutionGroupContext(); new ProcessEngine().executeSQL(executionGroupContext, - new QueryContext(new UpdateStatementContext(getSQLStatement(), "foo_db"), null, null, new HintValueContext(), connectionContext, metaData)); + new QueryContext(new UpdateStatementContext(getSQLStatement()), null, null, new HintValueContext(), connectionContext, metaData)); verify(processRegistry).add(any()); } @@ -80,7 +81,9 @@ private ExecutionGroupContext mockExecutionGroupCont private MySQLUpdateStatement getSQLStatement() { MySQLUpdateStatement result = new MySQLUpdateStatement(); - result.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + result.setTable(new SimpleTableSegment(tableNameSegment)); result.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.emptyList())); return result; } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java index a66b824cb2f8c..e4206b50d6b98 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java @@ -67,6 +67,6 @@ private DropTableStatementContext createSQLStatementContext(final boolean contai PostgreSQLDropTableStatement dropSchemaStatement = mock(PostgreSQLDropTableStatement.class, RETURNS_DEEP_STUBS); when(dropSchemaStatement.isContainsCascade()).thenReturn(containsCascade); when(dropSchemaStatement.getTables()).thenReturn(Collections.emptyList()); - return new DropTableStatementContext(dropSchemaStatement, "foo_db"); + return new DropTableStatementContext(dropSchemaStatement); } } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java index 4c39da843870d..d14c60b38c4ab 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java @@ -42,6 +42,7 @@ import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement; @@ -215,13 +216,14 @@ void assertDecorateRouteContextWithMultiDataSource() throws SQLException { private QueryContext createQueryContext() { CreateTableStatement createTableStatement = new MySQLCreateTableStatement(false); - createTableStatement.setTable(new SimpleTableSegment(new TableNameSegment(1, 2, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(1, 2, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + createTableStatement.setTable(new SimpleTableSegment(tableNameSegment)); ConnectionContext connectionContext = mock(ConnectionContext.class); when(connectionContext.getCurrentDatabaseName()).thenReturn(Optional.of("foo_db")); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); when(metaData.containsDatabase("foo_db")).thenReturn(true); when(metaData.getDatabase("foo_db")).thenReturn(mock(ShardingSphereDatabase.class)); - return new QueryContext(new CreateTableStatementContext(createTableStatement, "foo_db"), "CREATE TABLE", new LinkedList<>(), new HintValueContext(), connectionContext, - metaData); + return new QueryContext(new CreateTableStatementContext(createTableStatement), "CREATE TABLE", new LinkedList<>(), new HintValueContext(), connectionContext, metaData); } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java index 7b3ae07a2b06e..310f2238af603 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java @@ -225,7 +225,9 @@ private void extractTablesFromProjections(final ProjectionsSegment projections) } private SimpleTableSegment createSimpleTableSegment(final OwnerSegment ownerSegment) { - SimpleTableSegment result = new SimpleTableSegment(new TableNameSegment(ownerSegment.getStartIndex(), ownerSegment.getStopIndex(), ownerSegment.getIdentifier())); + TableNameSegment tableNameSegment = new TableNameSegment(ownerSegment.getStartIndex(), ownerSegment.getStopIndex(), ownerSegment.getIdentifier()); + ownerSegment.getTableBoundInfo().ifPresent(tableNameSegment::setTableBoundInfo); + SimpleTableSegment result = new SimpleTableSegment(tableNameSegment); ownerSegment.getOwner().ifPresent(result::setOwner); return result; } @@ -235,7 +237,9 @@ private void extractTablesFromOrderByItems(final Collection if (each instanceof ColumnOrderByItemSegment) { Optional owner = ((ColumnOrderByItemSegment) each).getColumn().getOwner(); if (owner.isPresent() && needRewrite(owner.get())) { - rewriteTables.add(new SimpleTableSegment(new TableNameSegment(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier()))); + TableNameSegment tableNameSegment = new TableNameSegment(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier()); + owner.get().getTableBoundInfo().ifPresent(tableNameSegment::setTableBoundInfo); + rewriteTables.add(new SimpleTableSegment(tableNameSegment)); } } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java index d12bf30caad43..936abc3d8ee8e 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java @@ -24,12 +24,13 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; +import java.util.Optional; + /** * Table name segment. */ @RequiredArgsConstructor @Getter -@Setter public final class TableNameSegment implements SQLSegment { private final int startIndex; @@ -38,5 +39,15 @@ public final class TableNameSegment implements SQLSegment { private final IdentifierValue identifier; + @Setter private TableSegmentBoundInfo tableBoundInfo; + + /** + * Get table bound info. + * + * @return table bound info + */ + public Optional getTableBoundInfo() { + return Optional.ofNullable(tableBoundInfo); + } } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java index e15e19d7bb2ff..b2dbcc146d3fd 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java @@ -240,19 +240,19 @@ void assertCheckExecutePrerequisitesWhenExecuteDDLNotInPostgreSQLTransaction() { private CreateTableStatementContext createMySQLCreateTableStatementContext() { MySQLCreateTableStatement sqlStatement = new MySQLCreateTableStatement(false); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new CreateTableStatementContext(sqlStatement, "foo_db"); + return new CreateTableStatementContext(sqlStatement); } private TruncateStatementContext createMySQLTruncateStatementContext() { MySQLTruncateStatement sqlStatement = new MySQLTruncateStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new TruncateStatementContext(sqlStatement, "foo_db"); + return new TruncateStatementContext(sqlStatement); } private SQLStatementContext createPostgreSQLTruncateStatementContext() { PostgreSQLTruncateStatement sqlStatement = new PostgreSQLTruncateStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new TruncateStatementContext(sqlStatement, "foo_db"); + return new TruncateStatementContext(sqlStatement); } private CursorStatementContext createCursorStatementContext() { @@ -276,7 +276,7 @@ private InsertStatementContext createMySQLInsertStatementContext() { private CreateTableStatementContext createPostgreSQLCreateTableStatementContext() { PostgreSQLCreateTableStatement sqlStatement = new PostgreSQLCreateTableStatement(false); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new CreateTableStatementContext(sqlStatement, "foo_db"); + return new CreateTableStatementContext(sqlStatement); } private InsertStatementContext createPostgreSQLInsertStatementContext() { diff --git a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java index bb7ed467d3bb2..83a46ca8d2651 100644 --- a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java +++ b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java @@ -163,7 +163,7 @@ void assertCreateWithResetStatement() { @Test void assertCreateWithDMLStatement() { - DeleteStatementContext sqlStatementContext = new DeleteStatementContext(new PostgreSQLDeleteStatement(), "foo_db"); + DeleteStatementContext sqlStatementContext = new DeleteStatementContext(new PostgreSQLDeleteStatement()); assertThat(new PostgreSQLAdminExecutorCreator().create(sqlStatementContext, "delete from t where id = 1", "", Collections.emptyList()), is(Optional.empty())); } }