You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/07/04 10:53:37 UTC
(shardingsphere) branch master updated: Refactor IndexContextAvailable to IndexSQLStatementAttribute (#35878)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new bc43db5e8e3 Refactor IndexContextAvailable to IndexSQLStatementAttribute (#35878)
bc43db5e8e3 is described below
commit bc43db5e8e30b82b0de430fd7f2d7fe246a33817
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jul 4 18:53:32 2025 +0800
Refactor IndexContextAvailable to IndexSQLStatementAttribute (#35878)
* Remove CursorAware
* Refactor CreateIndexStatementContext
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
* Refactor IndexContextAvailable to IndexSQLStatementAttribute
---
.../ddl/EncryptAlterTableTokenGenerator.java | 28 +++----
.../ddl/EncryptCreateTableTokenGenerator.java | 14 ++--
.../select/EncryptIndexColumnTokenGenerator.java | 7 +-
.../token/EncryptTokenGenerateBuilderTest.java | 2 +
.../ddl/EncryptAlterTableTokenGeneratorTest.java | 37 +++++----
.../ddl/EncryptCreateTableTokenGeneratorTest.java | 16 ++--
.../ddl/ShardingAlterIndexSupportedChecker.java | 10 +--
.../ddl/ShardingAlterTableSupportedChecker.java | 12 +--
.../ddl/ShardingCreateIndexSupportedChecker.java | 14 ++--
.../ddl/ShardingCreateTableSupportedChecker.java | 10 +--
.../sql/ddl/ShardingDropIndexSupportedChecker.java | 10 +--
.../ShardingSQLRewriteContextDecorator.java | 6 +-
.../impl/ShardingIndexTokenGenerator.java | 14 ++--
.../impl/ShardingTableTokenGenerator.java | 4 +-
.../sharding/rewrite/token/pojo/IndexToken.java | 6 +-
.../ddl/ShardingAlterTableRouteContextChecker.java | 7 +-
.../ShardingCreateTableRouteContextChecker.java | 8 +-
.../ShardingTableBroadcastRouteEngine.java | 7 +-
.../ShardingAlterIndexSupportedCheckerTest.java | 8 +-
.../ShardingAlterTableSupportedCheckerTest.java | 7 +-
.../ShardingCreateIndexSupportedCheckerTest.java | 14 ++--
.../ShardingCreateTableSupportedCheckerTest.java | 6 +-
.../ddl/ShardingDropIndexSupportedCheckerTest.java | 6 +-
.../impl/ShardingConstraintTokenGeneratorTest.java | 4 +-
.../impl/ShardingIndexTokenGeneratorTest.java | 35 +++++---
.../impl/ShardingTableTokenGeneratorTest.java | 7 +-
.../rewrite/token/pojo/IndexTokenTest.java | 7 +-
.../ShardingAlterTableRouteContextCheckerTest.java | 6 +-
...ShardingCreateTableRouteContextCheckerTest.java | 8 +-
.../ShardingDropIndexRouteContextCheckerTest.java | 6 +-
.../ShardingTableBroadcastRouteEngineTest.java | 19 +++--
.../binder/context/SQLStatementContextFactory.java | 25 ------
.../infra/binder/context/aware/CursorAware.java | 33 --------
.../extractor/SQLStatementContextExtractor.java | 9 +-
.../type/ddl/AlterIndexStatementContext.java | 65 ---------------
.../type/ddl/AlterTableStatementContext.java | 96 ----------------------
.../type/ddl/CreateIndexStatementContext.java | 69 ----------------
.../type/ddl/CreateTableStatementContext.java | 81 ------------------
.../type/ddl/CursorHeldSQLStatementContext.java | 9 +-
.../type/ddl/DropIndexStatementContext.java | 59 -------------
.../type/ddl/AlterIndexStatementContextTest.java | 47 -----------
.../type/ddl/AlterTableStatementContextTest.java | 95 ---------------------
.../type/ddl/CreateIndexStatementContextTest.java | 49 -----------
.../type/ddl/CreateTableStatementContextTest.java | 59 -------------
.../type/ddl/DropIndexStatementContextTest.java | 50 -----------
.../connection/kernel/KernelProcessorTest.java | 8 +-
.../generator/generic/RemoveTokenGenerator.java | 13 +--
.../infra/rewrite/SQLRewriteEntryTest.java | 5 ++
.../rewrite/context/SQLRewriteContextTest.java | 5 ++
.../metadata/generator/PipelineDDLDecorator.java | 26 +++---
.../shardingsphere/single/rule/SingleRule.java | 9 +-
.../single/route/SingleSQLRouterTest.java | 4 +-
.../attribute/type/IndexSQLStatementAttribute.java | 7 +-
.../type/ddl/index/AlterIndexStatement.java | 30 +++++++
.../type/ddl/index/CreateIndexStatement.java | 42 ++++++++++
.../type/ddl/index/DropIndexStatement.java | 23 ++++++
.../type/ddl/table/AlterTableStatement.java | 52 +++++++++++-
.../type/ddl/table/CreateTableStatement.java | 37 ++++++++-
.../connector/StandardDatabaseConnector.java | 6 +-
.../handler/distsql/rul/PreviewExecutor.java | 11 +--
.../backend/connector/ProxySQLExecutorTest.java | 26 ++----
.../test/it/rewrite/engine/SQLRewriterIT.java | 6 +-
62 files changed, 448 insertions(+), 953 deletions(-)
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGenerator.java
index 7f6a88abe7b..3953e1bbb5b 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGenerator.java
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.altertable.DialectAlterTableOption;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
@@ -45,36 +45,38 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.al
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.position.ColumnPositionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Alter table token generator for encrypt.
*/
@RequiredArgsConstructor
@Setter
-public final class EncryptAlterTableTokenGenerator implements CollectionSQLTokenGenerator<AlterTableStatementContext> {
+public final class EncryptAlterTableTokenGenerator implements CollectionSQLTokenGenerator<CommonSQLStatementContext> {
private final EncryptRule rule;
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof AlterTableStatementContext;
+ return sqlStatementContext.getSqlStatement() instanceof AlterTableStatement;
}
@Override
- public Collection<SQLToken> generateSQLTokens(final AlterTableStatementContext sqlStatementContext) {
- String tableName = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
+ public Collection<SQLToken> generateSQLTokens(final CommonSQLStatementContext sqlStatementContext) {
+ AlterTableStatement sqlStatement = (AlterTableStatement) sqlStatementContext.getSqlStatement();
+ String tableName = sqlStatement.getTable().getTableName().getIdentifier().getValue();
EncryptTable encryptTable = rule.getEncryptTable(tableName);
- Collection<SQLToken> result = new LinkedList<>(getAddColumnTokens(encryptTable, sqlStatementContext.getSqlStatement().getAddColumnDefinitions()));
- result.addAll(getModifyColumnTokens(encryptTable, sqlStatementContext.getSqlStatement().getModifyColumnDefinitions()));
- result.addAll(getChangeColumnTokens(encryptTable, sqlStatementContext.getSqlStatement().getChangeColumnDefinitions()));
- List<SQLToken> dropColumnTokens = getDropColumnTokens(encryptTable, sqlStatementContext.getSqlStatement().getDropColumnDefinitions());
+ Collection<SQLToken> result = new LinkedList<>(getAddColumnTokens(encryptTable, sqlStatement.getAddColumnDefinitions()));
+ result.addAll(getModifyColumnTokens(encryptTable, sqlStatement.getModifyColumnDefinitions()));
+ result.addAll(getChangeColumnTokens(encryptTable, sqlStatement.getChangeColumnDefinitions()));
+ List<SQLToken> dropColumnTokens = getDropColumnTokens(encryptTable, sqlStatement.getDropColumnDefinitions());
Optional<DialectAlterTableOption> alterTableOption = new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDialectDatabaseMetaData().getAlterTableOption();
if (alterTableOption.isPresent() && alterTableOption.get().isSupportMergeDropColumns()) {
result.addAll(mergeDropColumnStatement(dropColumnTokens, alterTableOption.get().isContainsParenthesesOnMergeDropColumns()));
@@ -220,11 +222,7 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
}
private List<SQLToken> getDropColumnTokens(final EncryptTable encryptTable, final Collection<DropColumnDefinitionSegment> segments) {
- List<SQLToken> result = new ArrayList<>();
- for (DropColumnDefinitionSegment each : segments) {
- result.addAll(getDropColumnTokens(encryptTable, each));
- }
- return result;
+ return segments.stream().flatMap(each -> getDropColumnTokens(encryptTable, each).stream()).collect(Collectors.toList());
}
private Collection<SQLToken> getDropColumnTokens(final EncryptTable encryptTable, final DropColumnDefinitionSegment segment) {
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGenerator.java
index 12b2beb7f29..e74103380dd 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGenerator.java
@@ -24,12 +24,13 @@ import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import org.apache.shardingsphere.encrypt.rule.column.item.CipherColumnItem;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.ColumnDefinitionToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.SubstituteColumnDefinitionToken;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
import java.util.ArrayList;
import java.util.Collection;
@@ -41,21 +42,22 @@ import java.util.Optional;
* Create table token generator for encrypt.
*/
@RequiredArgsConstructor
-public final class EncryptCreateTableTokenGenerator implements CollectionSQLTokenGenerator<CreateTableStatementContext> {
+public final class EncryptCreateTableTokenGenerator implements CollectionSQLTokenGenerator<CommonSQLStatementContext> {
private final EncryptRule rule;
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof CreateTableStatementContext && !(((CreateTableStatementContext) sqlStatementContext).getSqlStatement()).getColumnDefinitions().isEmpty();
+ return sqlStatementContext.getSqlStatement() instanceof CreateTableStatement && !((CreateTableStatement) sqlStatementContext.getSqlStatement()).getColumnDefinitions().isEmpty();
}
@Override
- public Collection<SQLToken> generateSQLTokens(final CreateTableStatementContext sqlStatementContext) {
+ public Collection<SQLToken> generateSQLTokens(final CommonSQLStatementContext sqlStatementContext) {
Collection<SQLToken> result = new LinkedList<>();
- String tableName = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
+ CreateTableStatement sqlStatement = (CreateTableStatement) sqlStatementContext.getSqlStatement();
+ String tableName = sqlStatement.getTable().getTableName().getIdentifier().getValue();
EncryptTable encryptTable = rule.getEncryptTable(tableName);
- List<ColumnDefinitionSegment> columns = new ArrayList<>(sqlStatementContext.getSqlStatement().getColumnDefinitions());
+ List<ColumnDefinitionSegment> columns = new ArrayList<>(sqlStatement.getColumnDefinitions());
for (int index = 0; index < columns.size(); index++) {
ColumnDefinitionSegment each = columns.get(index);
String columnName = each.getColumnName().getIdentifier().getValue();
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java
index 19fc152bdbd..d5c6f3ff835 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java
@@ -26,13 +26,13 @@ import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.SubstitutableColumnNameToken;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import java.util.Collection;
@@ -53,7 +53,7 @@ public final class EncryptIndexColumnTokenGenerator implements CollectionSQLToke
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
return !sqlStatementContext.getTablesContext().getTableNames().isEmpty()
- && sqlStatementContext instanceof IndexContextAvailable && !((IndexContextAvailable) sqlStatementContext).getIndexColumns().isEmpty();
+ && sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class).map(optional -> !optional.getIndexes().isEmpty()).orElse(false);
}
@Override
@@ -61,7 +61,8 @@ public final class EncryptIndexColumnTokenGenerator implements CollectionSQLToke
String tableName = sqlStatementContext.getTablesContext().getTableNames().iterator().next();
EncryptTable encryptTable = rule.getEncryptTable(tableName);
Collection<SQLToken> result = new LinkedList<>();
- for (ColumnSegment each : ((IndexContextAvailable) sqlStatementContext).getIndexColumns()) {
+ for (ColumnSegment each : sqlStatementContext.getSqlStatement().getAttributes()
+ .findAttribute(IndexSQLStatementAttribute.class).map(IndexSQLStatementAttribute::getIndexColumns).orElse(Collections.emptyList())) {
if (encryptTable.isEncryptColumn(each.getIdentifier().getValue())) {
generateSQLToken(encryptTable, each, sqlStatementContext.getDatabaseType()).ifPresent(result::add);
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilderTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilderTest.java
index afd9aa7718e..ea004d6152c 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilderTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilderTest.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.orderby.Ord
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.SQLTokenGenerator;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
@@ -56,6 +57,7 @@ class EncryptTokenGenerateBuilderTest {
when(selectStatementContext.getOrderByContext().getItems()).thenReturn(Collections.singleton(mock(OrderByItem.class)));
when(selectStatementContext.getGroupByContext().getItems()).thenReturn(Collections.emptyList());
when(selectStatementContext.getWhereSegments()).thenReturn(Collections.emptyList());
+ when(selectStatementContext.getSqlStatement()).thenReturn(new SelectStatement());
SQLRewriteContext sqlRewriteContext = mock(SQLRewriteContext.class, RETURNS_DEEP_STUBS);
EncryptTokenGenerateBuilder encryptTokenGenerateBuilder = new EncryptTokenGenerateBuilder(selectStatementContext, Collections.emptyList(), rule, sqlRewriteContext);
Collection<SQLTokenGenerator> sqlTokenGenerators = encryptTokenGenerateBuilder.getSQLTokenGenerators();
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGeneratorTest.java
index c91a30a47cd..364e3ac0795 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptAlterTableTokenGeneratorTest.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.encrypt.rule.column.item.CipherColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.RemoveToken;
@@ -36,6 +36,9 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.al
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DataTypeSegment;
+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.type.ddl.table.AlterTableStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -113,13 +116,15 @@ class EncryptAlterTableTokenGeneratorTest {
assertThat(likeToken.getStopIndex(), is(67));
}
- private AlterTableStatementContext mockAddColumnStatementContext() {
- AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
- when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
+ private CommonSQLStatementContext mockAddColumnStatementContext() {
+ AlterTableStatement sqlStatement = new AlterTableStatement();
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_encrypt"))));
ColumnDefinitionSegment columnDefinitionSegment = new ColumnDefinitionSegment(
33, 67, new ColumnSegment(33, 50, new IdentifierValue("certificate_number")), new DataTypeSegment(), false, false, "");
- when(result.getSqlStatement().getAddColumnDefinitions()).thenReturn(Collections.singleton(new AddColumnDefinitionSegment(22, 67, Collections.singleton(columnDefinitionSegment))));
+ sqlStatement.getAddColumnDefinitions().add(new AddColumnDefinitionSegment(22, 67, Collections.singleton(columnDefinitionSegment)));
+ CommonSQLStatementContext result = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getSqlStatement()).thenReturn(sqlStatement);
+ when(result.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
return result;
}
@@ -128,12 +133,14 @@ class EncryptAlterTableTokenGeneratorTest {
assertThrows(UnsupportedOperationException.class, () -> generator.generateSQLTokens(mockModifyColumnStatementContext()));
}
- private AlterTableStatementContext mockModifyColumnStatementContext() {
- AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
+ private CommonSQLStatementContext mockModifyColumnStatementContext() {
+ AlterTableStatement sqlStatement = new AlterTableStatement();
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_encrypt"))));
ColumnDefinitionSegment columnDefinitionSegment = new ColumnDefinitionSegment(
36, 70, new ColumnSegment(36, 53, new IdentifierValue("certificate_number")), new DataTypeSegment(), false, false, "");
- when(result.getSqlStatement().getModifyColumnDefinitions()).thenReturn(Collections.singleton(new ModifyColumnDefinitionSegment(22, 70, columnDefinitionSegment)));
+ sqlStatement.getModifyColumnDefinitions().add(new ModifyColumnDefinitionSegment(22, 70, columnDefinitionSegment));
+ CommonSQLStatementContext result = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getSqlStatement()).thenReturn(sqlStatement);
return result;
}
@@ -142,14 +149,16 @@ class EncryptAlterTableTokenGeneratorTest {
assertThrows(UnsupportedOperationException.class, () -> generator.generateSQLTokens(mockChangeColumnStatementContext()));
}
- private AlterTableStatementContext mockChangeColumnStatementContext() {
- AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
+ private CommonSQLStatementContext mockChangeColumnStatementContext() {
+ AlterTableStatement sqlStatement = new AlterTableStatement();
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_encrypt"))));
ColumnDefinitionSegment columnDefinitionSegment = new ColumnDefinitionSegment(
55, 93, new ColumnSegment(55, 76, new IdentifierValue("certificate_number_new")), new DataTypeSegment(), false, false, "");
ChangeColumnDefinitionSegment changeColumnDefinitionSegment = new ChangeColumnDefinitionSegment(22, 93, columnDefinitionSegment);
changeColumnDefinitionSegment.setPreviousColumn(new ColumnSegment(36, 53, new IdentifierValue("certificate_number")));
- when(result.getSqlStatement().getChangeColumnDefinitions()).thenReturn(Collections.singleton(changeColumnDefinitionSegment));
+ sqlStatement.getChangeColumnDefinitions().add(changeColumnDefinitionSegment);
+ CommonSQLStatementContext result = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getSqlStatement()).thenReturn(sqlStatement);
return result;
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGeneratorTest.java
index 119bc2ea5ab..370d895adc3 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/ddl/EncryptCreateTableTokenGeneratorTest.java
@@ -24,19 +24,21 @@ import org.apache.shardingsphere.encrypt.rule.column.item.CipherColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.ColumnDefinitionToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.SubstituteColumnDefinitionToken;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DataTypeSegment;
+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.type.ddl.table.CreateTableStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -101,11 +103,13 @@ class EncryptCreateTableTokenGeneratorTest {
assertTrue(((SubstituteColumnDefinitionToken) token).isLastColumn());
}
- private CreateTableStatementContext mockCreateTableStatementContext() {
- CreateTableStatementContext result = mock(CreateTableStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
+ private CommonSQLStatementContext mockCreateTableStatementContext() {
+ CreateTableStatement sqlStatement = new CreateTableStatement();
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_encrypt"))));
ColumnDefinitionSegment segment = new ColumnDefinitionSegment(25, 78, new ColumnSegment(25, 42, new IdentifierValue("certificate_number")), new DataTypeSegment(), false, false, "");
- when(result.getSqlStatement().getColumnDefinitions()).thenReturn(Collections.singleton(segment));
+ sqlStatement.getColumnDefinitions().add(segment);
+ CommonSQLStatementContext result = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getSqlStatement()).thenReturn(sqlStatement);
return result;
}
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedChecker.java
index 450b18c2010..188fe90330b 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedChecker.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import org.apache.shardingsphere.infra.exception.kernel.metadata.DuplicateIndexException;
import org.apache.shardingsphere.infra.exception.kernel.metadata.IndexNotFoundException;
@@ -34,16 +34,16 @@ import java.util.Optional;
/**
* Alter index supported checker for sharding.
*/
-public final class ShardingAlterIndexSupportedChecker implements SupportedSQLChecker<AlterIndexStatementContext, ShardingRule> {
+public final class ShardingAlterIndexSupportedChecker implements SupportedSQLChecker<CommonSQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof AlterIndexStatementContext;
+ return sqlStatementContext.getSqlStatement() instanceof AlterIndexStatement;
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final AlterIndexStatementContext sqlStatementContext) {
- AlterIndexStatement alterIndexStatement = sqlStatementContext.getSqlStatement();
+ public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final CommonSQLStatementContext sqlStatementContext) {
+ AlterIndexStatement alterIndexStatement = (AlterIndexStatement) sqlStatementContext.getSqlStatement();
Optional<IndexSegment> index = alterIndexStatement.getIndex();
ShardingSphereSchema schema = index.flatMap(optional -> optional.getOwner().map(owner -> database.getSchema(owner.getIdentifier().getValue()))).orElse(currentSchema);
if (index.isPresent() && !ShardingSupportedCheckUtils.isSchemaContainsIndex(schema, index.get())) {
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedChecker.java
index ad67d1ccc42..7b217676eff 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedChecker.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSp
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
import java.util.Collection;
import java.util.Optional;
@@ -34,18 +35,19 @@ import java.util.stream.Collectors;
/**
* Alter table supported checker for sharding.
*/
-public final class ShardingAlterTableSupportedChecker implements SupportedSQLChecker<AlterTableStatementContext, ShardingRule> {
+public final class ShardingAlterTableSupportedChecker implements SupportedSQLChecker<CommonSQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof AlterTableStatementContext;
+ return sqlStatementContext.getSqlStatement() instanceof AlterTableStatement;
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final AlterTableStatementContext sqlStatementContext) {
+ public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final CommonSQLStatementContext sqlStatementContext) {
+ AlterTableStatement sqlStatement = (AlterTableStatement) sqlStatementContext.getSqlStatement();
Collection<String> tableNames = sqlStatementContext.getTablesContext().getSimpleTables().stream()
.map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList());
- Optional<SimpleTableSegment> renameTable = sqlStatementContext.getSqlStatement().getRenameTable();
+ Optional<SimpleTableSegment> renameTable = sqlStatement.getRenameTable();
ShardingSpherePreconditions.checkState(!renameTable.isPresent() || !rule.containsShardingTable(tableNames),
() -> new UnsupportedShardingOperationException("ALTER TABLE ... RENAME TO ...", renameTable.map(optional -> optional.getTableName().getIdentifier().getValue()).orElse("")));
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedChecker.java
index 26017e06493..07686dc231f 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedChecker.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.kernel.metadata.DuplicateIndexException;
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.checker.sql.common.ShardingSupportedCommonChecker;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.CreateIndexStatement;
import java.util.Collections;
@@ -33,23 +34,24 @@ import java.util.Collections;
/**
* Create index supported checker for sharding.
*/
-public final class ShardingCreateIndexSupportedChecker implements SupportedSQLChecker<CreateIndexStatementContext, ShardingRule> {
+public final class ShardingCreateIndexSupportedChecker implements SupportedSQLChecker<CommonSQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof CreateIndexStatementContext;
+ return sqlStatementContext.getSqlStatement() instanceof CreateIndexStatement;
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final CreateIndexStatementContext sqlStatementContext) {
- CreateIndexStatement createIndexStatement = sqlStatementContext.getSqlStatement();
+ public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final CommonSQLStatementContext sqlStatementContext) {
+ CreateIndexStatement createIndexStatement = (CreateIndexStatement) sqlStatementContext.getSqlStatement();
if (createIndexStatement.isIfNotExists()) {
return;
}
ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(database::getSchema).orElse(currentSchema);
ShardingSupportedCommonChecker.checkTableExist(schema, Collections.singleton(createIndexStatement.getTable()));
String tableName = createIndexStatement.getTable().getTableName().getIdentifier().getValue();
- String indexName = sqlStatementContext.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).findFirst().orElse(null);
+ String indexName = createIndexStatement.getAttributes().getAttribute(IndexSQLStatementAttribute.class).getIndexes()
+ .stream().map(each -> each.getIndexName().getIdentifier().getValue()).findFirst().orElse(null);
ShardingSpherePreconditions.checkState(!schema.containsIndex(tableName, indexName), () -> new DuplicateIndexException(indexName));
}
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedChecker.java
index 6f9f657b944..65f29e280da 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedChecker.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -31,16 +31,16 @@ import java.util.Collections;
/**
* Create table supported checker for sharding.
*/
-public final class ShardingCreateTableSupportedChecker implements SupportedSQLChecker<CreateTableStatementContext, ShardingRule> {
+public final class ShardingCreateTableSupportedChecker implements SupportedSQLChecker<CommonSQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof CreateTableStatementContext;
+ return sqlStatementContext.getSqlStatement() instanceof CreateTableStatement;
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final CreateTableStatementContext sqlStatementContext) {
- CreateTableStatement createTableStatement = sqlStatementContext.getSqlStatement();
+ public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final CommonSQLStatementContext sqlStatementContext) {
+ CreateTableStatement createTableStatement = (CreateTableStatement) sqlStatementContext.getSqlStatement();
if (!createTableStatement.isIfNotExists()) {
ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(database::getSchema).orElse(currentSchema);
ShardingSupportedCommonChecker.checkTableNotExist(schema, Collections.singleton(createTableStatement.getTable()));
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedChecker.java
index 6a8bbdd367e..4f6c20ffd3e 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedChecker.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.kernel.metadata.IndexNotFoundException;
@@ -32,16 +32,16 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.in
/**
* Drop index supported checker for sharding.
*/
-public final class ShardingDropIndexSupportedChecker implements SupportedSQLChecker<DropIndexStatementContext, ShardingRule> {
+public final class ShardingDropIndexSupportedChecker implements SupportedSQLChecker<CommonSQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof DropIndexStatementContext;
+ return sqlStatementContext.getSqlStatement() instanceof DropIndexStatement;
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final DropIndexStatementContext sqlStatementContext) {
- DropIndexStatement dropIndexStatement = sqlStatementContext.getSqlStatement();
+ public void check(final ShardingRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final CommonSQLStatementContext sqlStatementContext) {
+ DropIndexStatement dropIndexStatement = (DropIndexStatement) sqlStatementContext.getSqlStatement();
if (dropIndexStatement.isIfExists()) {
return;
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
index b67ce363cf2..f46ed2daf3f 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
@@ -19,8 +19,6 @@ package org.apache.shardingsphere.sharding.rewrite.context;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterIndexStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator;
@@ -34,6 +32,8 @@ import org.apache.shardingsphere.sharding.rewrite.token.ShardingTokenGenerateBui
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.CursorSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.AlterIndexStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.DropIndexStatement;
import java.util.Collection;
@@ -58,7 +58,7 @@ public final class ShardingSQLRewriteContextDecorator implements SQLRewriteConte
}
private boolean isAlterOrDropIndexStatement(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof AlterIndexStatementContext || sqlStatementContext instanceof DropIndexStatementContext;
+ return sqlStatementContext.getSqlStatement() instanceof AlterIndexStatement || sqlStatementContext.getSqlStatement() instanceof DropIndexStatement;
}
private boolean isCursorContextAvailableStatement(final SQLStatementContext sqlStatementContext) {
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGenerator.java
index cd955693c15..25349e8bf5c 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGenerator.java
@@ -21,7 +21,6 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
@@ -30,8 +29,10 @@ import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.sharding.rewrite.token.pojo.IndexToken;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
@@ -51,18 +52,17 @@ public final class ShardingIndexTokenGenerator implements CollectionSQLTokenGene
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof IndexContextAvailable && !((IndexContextAvailable) sqlStatementContext).getIndexes().isEmpty()
+ return sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class).map(optional -> !optional.getIndexes().isEmpty()).orElse(false)
&& new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDialectDatabaseMetaData().getIndexOption().isSchemaUniquenessLevel();
}
@Override
public Collection<SQLToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
Collection<SQLToken> result = new LinkedList<>();
- if (sqlStatementContext instanceof IndexContextAvailable) {
- for (IndexSegment each : ((IndexContextAvailable) sqlStatementContext).getIndexes()) {
- ShardingSphereSchema schema = each.getOwner().isPresent() ? schemas.get(each.getOwner().get().getIdentifier().getValue()) : defaultSchema;
- result.add(new IndexToken(each.getIndexName().getStartIndex(), each.getStopIndex(), each.getIndexName().getIdentifier(), sqlStatementContext, rule, schema));
- }
+ for (IndexSegment each : sqlStatementContext.getSqlStatement().getAttributes()
+ .findAttribute(IndexSQLStatementAttribute.class).map(IndexSQLStatementAttribute::getIndexes).orElse(Collections.emptyList())) {
+ ShardingSphereSchema schema = each.getOwner().isPresent() ? schemas.get(each.getOwner().get().getIdentifier().getValue()) : defaultSchema;
+ result.add(new IndexToken(each.getIndexName().getStartIndex(), each.getStopIndex(), each.getIndexName().getIdentifier(), sqlStatementContext, rule, schema));
}
return result;
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java
index cb2ac94ca47..f0f2051f020 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
-import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorHeldSQLStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.RouteContextAware;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
@@ -48,7 +48,7 @@ public final class ShardingTableTokenGenerator implements CollectionSQLTokenGene
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
- return !(sqlStatementContext instanceof CursorAware) && (isAllBindingTables(sqlStatementContext) || routeContext.containsTableSharding());
+ return !(sqlStatementContext instanceof CursorHeldSQLStatementContext) && (isAllBindingTables(sqlStatementContext) || routeContext.containsTableSharding());
}
private boolean isAllBindingTables(final SQLStatementContext sqlStatementContext) {
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexToken.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexToken.java
index 86473c0bdba..7c14604f2af 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexToken.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexToken.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.rewrite.token.pojo;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
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.metadata.database.schema.util.IndexMetaDataUtils;
@@ -28,6 +27,7 @@ import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Substitutable;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.CreateIndexStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import java.util.Map;
@@ -55,7 +55,7 @@ public final class IndexToken extends SQLToken implements Substitutable, RouteUn
this.stopIndex = stopIndex;
this.identifier = identifier;
this.sqlStatementContext = sqlStatementContext;
- this.rule = shardingRule;
+ rule = shardingRule;
this.schema = schema;
}
@@ -66,7 +66,7 @@ public final class IndexToken extends SQLToken implements Substitutable, RouteUn
}
private boolean isGeneratedIndex() {
- return sqlStatementContext instanceof CreateIndexStatementContext && ((CreateIndexStatementContext) sqlStatementContext).isGeneratedIndex();
+ return sqlStatementContext.getSqlStatement() instanceof CreateIndexStatement && null == ((CreateIndexStatement) sqlStatementContext.getSqlStatement()).getIndex();
}
private String getIndexValue(final RouteUnit routeUnit) {
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextChecker.java
index 483fc49e3af..2860e715fba 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextChecker.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.sharding.checker.sql.util.ShardingSupportedChec
import org.apache.shardingsphere.sharding.exception.connection.ShardingDDLRouteException;
import org.apache.shardingsphere.sharding.route.engine.checker.ShardingRouteContextChecker;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
/**
* Sharding alter table route context checker.
@@ -35,8 +36,8 @@ public final class ShardingAlterTableRouteContextChecker implements ShardingRout
@Override
public void check(final ShardingRule shardingRule, final QueryContext queryContext, final ShardingSphereDatabase database, final ConfigurationProperties props, final RouteContext routeContext) {
- AlterTableStatementContext alterTableStatementContext = (AlterTableStatementContext) queryContext.getSqlStatementContext();
- String primaryTable = alterTableStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
+ CommonSQLStatementContext alterTableStatementContext = (CommonSQLStatementContext) queryContext.getSqlStatementContext();
+ String primaryTable = ((AlterTableStatement) alterTableStatementContext.getSqlStatement()).getTable().getTableName().getIdentifier().getValue();
ShardingSpherePreconditions.checkState(!ShardingSupportedCheckUtils.isRouteUnitDataNodeDifferentSize(shardingRule, routeContext, primaryTable),
() -> new ShardingDDLRouteException("ALTER", "TABLE", alterTableStatementContext.getTablesContext().getTableNames()));
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextChecker.java
index d7421cf6a9e..5117306769e 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextChecker.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -26,6 +25,7 @@ import org.apache.shardingsphere.sharding.checker.sql.util.ShardingSupportedChec
import org.apache.shardingsphere.sharding.exception.connection.ShardingDDLRouteException;
import org.apache.shardingsphere.sharding.route.engine.checker.ShardingRouteContextChecker;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
/**
* Sharding create table route context checker.
@@ -34,10 +34,10 @@ public final class ShardingCreateTableRouteContextChecker implements ShardingRou
@Override
public void check(final ShardingRule shardingRule, final QueryContext queryContext, final ShardingSphereDatabase database, final ConfigurationProperties props, final RouteContext routeContext) {
- CreateTableStatementContext createTableStatementContext = (CreateTableStatementContext) queryContext.getSqlStatementContext();
- String primaryTable = (createTableStatementContext.getSqlStatement()).getTable().getTableName().getIdentifier().getValue();
+ CreateTableStatement createTableStatement = (CreateTableStatement) queryContext.getSqlStatementContext().getSqlStatement();
+ String primaryTable = createTableStatement.getTable().getTableName().getIdentifier().getValue();
if (ShardingSupportedCheckUtils.isRouteUnitDataNodeDifferentSize(shardingRule, routeContext, primaryTable)) {
- throw new ShardingDDLRouteException("CREATE", "TABLE", createTableStatementContext.getTablesContext().getTableNames());
+ throw new ShardingDDLRouteException("CREATE", "TABLE", queryContext.getSqlStatementContext().getTablesContext().getTableNames());
}
}
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngine.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngine.java
index 46a935be13e..41960182c94 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngine.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngine.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.route.engine.type.broadcast;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -33,6 +32,7 @@ import org.apache.shardingsphere.sharding.route.engine.type.complex.ShardingCart
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.ShardingTable;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
import java.util.Collection;
import java.util.Collections;
@@ -106,9 +106,8 @@ public final class ShardingTableBroadcastRouteEngine implements ShardingRouteEng
if (!shardingRuleTableNames.isEmpty()) {
return shardingRuleTableNames;
}
- return sqlStatementContext instanceof IndexContextAvailable
- ? getTableNames(database, sqlStatementContext.getDatabaseType(), ((IndexContextAvailable) sqlStatementContext).getIndexes())
- : Collections.emptyList();
+ return sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class)
+ .map(optional -> getTableNames(database, sqlStatementContext.getDatabaseType(), optional.getIndexes())).orElse(Collections.emptyList());
}
private Collection<String> getTableNames(final ShardingSphereDatabase database, final DatabaseType databaseType, final Collection<IndexSegment> indexes) {
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 ddb687cdf21..188ac7bf41a 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.exception.kernel.metadata.DuplicateIndexException;
import org.apache.shardingsphere.infra.exception.kernel.metadata.IndexNotFoundException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -60,7 +60,7 @@ class ShardingAlterIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertDoesNotThrow(() -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -70,7 +70,7 @@ class ShardingAlterIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertThrows(IndexNotFoundException.class, () -> new ShardingAlterIndexSupportedChecker().check(rule, database, mock(), new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -84,6 +84,6 @@ class ShardingAlterIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ () -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), 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 c70ecb98bb9..35077916973 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -30,6 +30,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import java.util.Arrays;
@@ -38,6 +40,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
class ShardingAlterTableSupportedCheckerTest {
@Mock
@@ -51,7 +54,7 @@ class ShardingAlterTableSupportedCheckerTest {
AlterTableStatement sqlStatement = new AlterTableStatement();
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(mock(), sqlStatement);
+ CommonSQLStatementContext sqlStatementContext = new CommonSQLStatementContext(mock(), 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/ShardingCreateIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java
index 1e555a0d511..248a072b762 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException;
import org.apache.shardingsphere.infra.exception.kernel.metadata.DuplicateIndexException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -57,7 +57,7 @@ class ShardingCreateIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -67,7 +67,7 @@ class ShardingCreateIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -78,7 +78,7 @@ class ShardingCreateIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -89,7 +89,7 @@ class ShardingCreateIndexSupportedCheckerTest {
sqlStatement.setGeneratedIndexStartIndex(10);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order")).thenReturn(true);
- assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(mock(), sqlStatement)));
+ assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -100,7 +100,7 @@ class ShardingCreateIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -112,6 +112,6 @@ class ShardingCreateIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
}
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 41af55960af..693423be72a 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -50,7 +50,7 @@ class ShardingCreateTableSupportedCheckerTest {
}
private void assertCheck(final CreateTableStatement sqlStatement) {
- CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(mock(), sqlStatement);
+ CommonSQLStatementContext sqlStatementContext = new CommonSQLStatementContext(mock(), sqlStatement);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("foo_tbl")).thenReturn(true);
@@ -66,7 +66,7 @@ class ShardingCreateTableSupportedCheckerTest {
}
private void assertCheckIfNotExists(final CreateTableStatement sqlStatement) {
- CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(mock(), sqlStatement);
+ CommonSQLStatementContext sqlStatementContext = new CommonSQLStatementContext(mock(), 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 885d80b8804..2193d558b32 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.exception.kernel.metadata.IndexNotFoundException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -59,7 +59,7 @@ class ShardingDropIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertDoesNotThrow(() -> new ShardingDropIndexSupportedChecker().check(rule, database, schema, new CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -70,6 +70,6 @@ class ShardingDropIndexSupportedCheckerTest {
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(mock(), sqlStatement)));
+ assertThrows(IndexNotFoundException.class, () -> new ShardingDropIndexSupportedChecker().check(rule, database, mock(), new CommonSQLStatementContext(mock(), sqlStatement)));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingConstraintTokenGeneratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingConstraintTokenGeneratorTest.java
index 3032a3140e8..547191c53b4 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingConstraintTokenGeneratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingConstraintTokenGeneratorTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.sharding.rewrite.token.pojo.ConstraintToken;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -52,7 +52,7 @@ class ShardingConstraintTokenGeneratorTest {
@Test
void assertIsNotGenerateSQLTokenWithEmptyConstraint() {
- AlterTableStatementContext sqlStatementContext = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
+ CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
ConstraintSQLStatementAttribute constraintAttribute = mock(ConstraintSQLStatementAttribute.class);
when(constraintAttribute.getConstraints()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getSqlStatement().getAttributes()).thenReturn(new SQLStatementAttributes(constraintAttribute));
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGeneratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGeneratorTest.java
index 41d405b8486..0d5e766764f 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGeneratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingIndexTokenGeneratorTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
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.OwnerSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.AlterIndexStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.Test;
import org.mockito.internal.configuration.plugins.Plugins;
@@ -51,26 +52,34 @@ class ShardingIndexTokenGeneratorTest {
@Test
void assertIsNotGenerateSQLTokenWithNotIndexContextAvailable() {
- assertFalse(generator.isGenerateSQLToken(mock(SQLStatementContext.class)));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(new AlterIndexStatement());
+ assertFalse(generator.isGenerateSQLToken(sqlStatementContext));
}
@Test
void assertIsNotGenerateSQLTokenWithEmptyIndex() {
- AlterIndexStatementContext sqlStatementContext = mock(AlterIndexStatementContext.class, RETURNS_DEEP_STUBS);
- when(sqlStatementContext.getIndexes().isEmpty()).thenReturn(true);
+ CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(new AlterIndexStatement());
+ when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
assertFalse(generator.isGenerateSQLToken(sqlStatementContext));
}
@Test
void assertIsGenerateSQLToken() {
- AlterIndexStatementContext sqlStatementContext = mock(AlterIndexStatementContext.class, RETURNS_DEEP_STUBS);
+ CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ AlterIndexStatement sqlStatement = new AlterIndexStatement();
+ sqlStatement.setIndex(mock(IndexSegment.class));
+ when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
assertTrue(generator.isGenerateSQLToken(sqlStatementContext));
}
@Test
void assertGenerateSQLTokensWithNotIndexContextAvailable() {
- Collection<SQLToken> actual = generator.generateSQLTokens(mock(SQLStatementContext.class));
+ CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(new AlterIndexStatement());
+ Collection<SQLToken> actual = generator.generateSQLTokens(sqlStatementContext);
assertTrue(actual.isEmpty());
}
@@ -78,7 +87,7 @@ class ShardingIndexTokenGeneratorTest {
void assertGenerateSQLTokensWithSchemaOwner() throws ReflectiveOperationException {
IndexSegment indexSegment = new IndexSegment(1, 3, new IndexNameSegment(1, 3, mock(IdentifierValue.class)));
indexSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_schema")));
- AlterIndexStatementContext sqlStatementContext = mockAlterIndexStatementContext(indexSegment);
+ CommonSQLStatementContext sqlStatementContext = mockAlterIndexStatementContext(indexSegment);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
generator.setSchemas(Collections.singletonMap("foo_schema", schema));
Collection<SQLToken> actual = generator.generateSQLTokens(sqlStatementContext);
@@ -88,18 +97,20 @@ class ShardingIndexTokenGeneratorTest {
@Test
void assertGenerateSQLTokensWithoutSchemaOwner() throws ReflectiveOperationException {
IndexSegment indexSegment = new IndexSegment(1, 3, new IndexNameSegment(1, 3, mock(IdentifierValue.class)));
- AlterIndexStatementContext sqlStatementContext = mockAlterIndexStatementContext(indexSegment);
+ CommonSQLStatementContext sqlStatementContext = mockAlterIndexStatementContext(indexSegment);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
generator.setDefaultSchema(schema);
Collection<SQLToken> actual = generator.generateSQLTokens(sqlStatementContext);
assertTokens(actual, schema);
}
- private AlterIndexStatementContext mockAlterIndexStatementContext(final IndexSegment indexSegment) {
- AlterIndexStatementContext result = mock(AlterIndexStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getIndexes()).thenReturn(Collections.singleton(indexSegment));
- when(result.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
+ private CommonSQLStatementContext mockAlterIndexStatementContext(final IndexSegment indexSegment) {
+ CommonSQLStatementContext result = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ AlterIndexStatement sqlStatement = new AlterIndexStatement();
+ sqlStatement.setIndex(indexSegment);
+ when(result.getSqlStatement()).thenReturn(sqlStatement);
when(result.getTablesContext().getSchemaName()).thenReturn(Optional.empty());
+ when(result.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
return result;
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java
index f48e6b19073..1d55a666008 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
-import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorHeldSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -46,7 +46,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
@ExtendWith(MockitoExtension.class)
class ShardingTableTokenGeneratorTest {
@@ -62,8 +61,8 @@ class ShardingTableTokenGeneratorTest {
}
@Test
- void assertIsNotGenerateSQLTokenWithCursorAware() {
- assertFalse(generator.isGenerateSQLToken(mock(SQLStatementContext.class, withSettings().extraInterfaces(CursorAware.class))));
+ void assertIsNotGenerateSQLTokenWithCursorHeldSQLStatementContext() {
+ assertFalse(generator.isGenerateSQLToken(mock(CursorHeldSQLStatementContext.class)));
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java
index e0e7ac8f6ee..6f9228bdb24 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java
@@ -17,13 +17,14 @@
package org.apache.shardingsphere.sharding.rewrite.token.pojo;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
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.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.CreateIndexStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.Test;
@@ -58,8 +59,8 @@ class IndexTokenTest {
@Test
void assertToStringWithShardingTableAndGeneratedIndex() {
- CreateIndexStatementContext sqlStatementContext = mock(CreateIndexStatementContext.class, RETURNS_DEEP_STUBS);
- when(sqlStatementContext.isGeneratedIndex()).thenReturn(true);
+ CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(new CreateIndexStatement());
IndexToken indexToken = new IndexToken(0, 0, new IdentifierValue("bar_idx"), sqlStatementContext, mock(ShardingRule.class), mockSchema());
assertThat(indexToken.toString(mockRouteUnit()), is(" bar_idx_foo_tbl_0 "));
}
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 bbed7f118c1..29335ceaa8d 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -72,7 +72,7 @@ class ShardingAlterTableRouteContextCheckerTest {
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(mock(), sqlStatement));
+ when(queryContext.getSqlStatementContext()).thenReturn(new CommonSQLStatementContext(mock(), sqlStatement));
assertDoesNotThrow(() -> new ShardingAlterTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext));
}
@@ -85,7 +85,7 @@ class ShardingAlterTableRouteContextCheckerTest {
Collection<RouteUnit> 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(mock(), sqlStatement));
+ when(queryContext.getSqlStatementContext()).thenReturn(new CommonSQLStatementContext(mock(), 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 e27104f4e79..b06d8122816 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -73,7 +73,7 @@ class ShardingCreateTableRouteContextCheckerTest {
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(mock(), sqlStatement));
+ when(queryContext.getSqlStatementContext()).thenReturn(new CommonSQLStatementContext(mock(), sqlStatement));
assertDoesNotThrow(() -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext));
}
@@ -87,7 +87,7 @@ class ShardingCreateTableRouteContextCheckerTest {
Collection<RouteUnit> 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(mock(), sqlStatement));
+ when(queryContext.getSqlStatementContext()).thenReturn(new CommonSQLStatementContext(mock(), sqlStatement));
assertThrows(ShardingDDLRouteException.class,
() -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext));
}
@@ -97,7 +97,7 @@ class ShardingCreateTableRouteContextCheckerTest {
CreateTableStatement sqlStatement = new CreateTableStatement();
sqlStatement.setIfNotExists(false);
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_config"))));
- when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(mock(), sqlStatement));
+ when(queryContext.getSqlStatementContext()).thenReturn(new CommonSQLStatementContext(mock(), 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 2b1e3d661cb..46a96049388 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -83,7 +83,7 @@ class ShardingDropIndexRouteContextCheckerTest {
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(databaseType, sqlStatement));
+ when(queryContext.getSqlStatementContext()).thenReturn(new CommonSQLStatementContext(databaseType, sqlStatement));
assertDoesNotThrow(() -> new ShardingDropIndexRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext));
}
@@ -102,7 +102,7 @@ class ShardingDropIndexRouteContextCheckerTest {
Collection<RouteUnit> 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(databaseType, sqlStatement));
+ when(queryContext.getSqlStatementContext()).thenReturn(new CommonSQLStatementContext(databaseType, 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/type/broadcast/ShardingTableBroadcastRouteEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
index e97f49a7bf2..ef4f9474ac8 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.sharding.route.engine.type.broadcast;
import org.apache.groovy.util.Maps;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -35,6 +35,9 @@ import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.DropIndexStatement;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.Test;
@@ -90,11 +93,13 @@ class ShardingTableBroadcastRouteEngineTest {
IndexSegment segment = mock(IndexSegment.class, RETURNS_DEEP_STUBS);
when(segment.getIndexName().getIdentifier().getValue()).thenReturn("t_order");
when(segment.getOwner()).thenReturn(Optional.empty());
- DropIndexStatementContext sqlStatementContext = mock(DropIndexStatementContext.class, RETURNS_DEEP_STUBS);
+ CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ DropIndexStatement sqlStatement = new DropIndexStatement();
+ sqlStatement.getIndexes().add(segment);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
Collection<String> tableNames = Collections.emptyList();
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(tableNames);
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
- when(sqlStatementContext.getIndexes()).thenReturn(Collections.singletonList(segment));
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", databaseType, mock(ResourceMetaData.class), mock(RuleMetaData.class), Collections.singleton(schema));
ShardingTableBroadcastRouteEngine shardingTableBroadcastRouteEngine = new ShardingTableBroadcastRouteEngine(database, sqlStatementContext, tableNames);
RouteContext routeContext = shardingTableBroadcastRouteEngine.route(createShardingRule());
@@ -111,12 +116,11 @@ class ShardingTableBroadcastRouteEngineTest {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getName()).thenReturn("foo_db");
when(schema.getTable(anyString()).containsIndex(anyString())).thenReturn(false);
- IndexSegment segment = mock(IndexSegment.class, RETURNS_DEEP_STUBS);
- when(segment.getIndexName().getIdentifier().getValue()).thenReturn("t_order");
- DropIndexStatementContext sqlStatementContext = mock(DropIndexStatementContext.class, RETURNS_DEEP_STUBS);
+ CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
Collection<String> tableNames = Collections.emptyList();
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(tableNames);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(new DropIndexStatement());
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", databaseType, mock(ResourceMetaData.class), mock(RuleMetaData.class), Collections.singleton(schema));
ShardingTableBroadcastRouteEngine shardingTableBroadcastRouteEngine = new ShardingTableBroadcastRouteEngine(database, sqlStatementContext, tableNames);
RouteContext routeContext = shardingTableBroadcastRouteEngine.route(createShardingRule());
@@ -132,6 +136,9 @@ class ShardingTableBroadcastRouteEngineTest {
private SQLStatementContext createSQLStatementContext(final Collection<String> tableNames) {
SQLStatementContext result = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(result.getTablesContext().getTableNames()).thenReturn(tableNames);
+ SQLStatement sqlStatement = mock(SQLStatement.class);
+ when(sqlStatement.getAttributes()).thenReturn(new SQLStatementAttributes());
+ when(result.getSqlStatement()).thenReturn(sqlStatement);
return result;
}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/SQLStatementContextFactory.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/SQLStatementContextFactory.java
index 3c53658f46a..7b89596e7a0 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/SQLStatementContextFactory.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/SQLStatementContextFactory.java
@@ -22,16 +22,11 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dal.ExplainStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterIndexStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterViewStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateProcedureStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateViewStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorHeldSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.DeleteStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
@@ -47,12 +42,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.Ex
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dcl.DCLStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.CursorStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.AlterIndexStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.CreateIndexStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.procedure.CreateProcedureStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.AlterViewStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.CreateViewStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.DMLStatement;
@@ -121,21 +111,6 @@ public final class SQLStatementContextFactory {
private static SQLStatementContext getDDLStatementContext(final ShardingSphereMetaData metaData, final DatabaseType databaseType,
final DDLStatement sqlStatement, final List<Object> params, final String currentDatabaseName) {
- if (sqlStatement instanceof CreateTableStatement) {
- return new CreateTableStatementContext(databaseType, (CreateTableStatement) sqlStatement);
- }
- if (sqlStatement instanceof AlterTableStatement) {
- return new AlterTableStatementContext(databaseType, (AlterTableStatement) sqlStatement);
- }
- if (sqlStatement instanceof CreateIndexStatement) {
- return new CreateIndexStatementContext(databaseType, (CreateIndexStatement) sqlStatement);
- }
- if (sqlStatement instanceof AlterIndexStatement) {
- return new AlterIndexStatementContext(databaseType, (AlterIndexStatement) sqlStatement);
- }
- if (sqlStatement instanceof DropIndexStatement) {
- return new DropIndexStatementContext(databaseType, (DropIndexStatement) sqlStatement);
- }
if (sqlStatement instanceof CreateProcedureStatement) {
return new CreateProcedureStatementContext(databaseType, (CreateProcedureStatement) sqlStatement);
}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/aware/CursorAware.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/aware/CursorAware.java
deleted file mode 100644
index c322bd70779..00000000000
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/aware/CursorAware.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.aware;
-
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
-
-/**
- * Cursor aware.
- */
-public interface CursorAware {
-
- /**
- * Set cursor statement context.
- *
- * @param cursorStatementContext cursor statement context
- */
- void setCursorStatementContext(CursorStatementContext cursorStatementContext);
-}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
index d6f27a9fac2..deb8b595149 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
@@ -20,14 +20,13 @@ package org.apache.shardingsphere.infra.binder.context.extractor;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
+import org.apache.shardingsphere.infra.binder.context.available.WhereContextAvailable;
import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertSelectContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterViewStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateViewStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
-import org.apache.shardingsphere.infra.binder.context.available.WhereContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
@@ -36,6 +35,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.Ind
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.statement.attribute.type.IndexSQLStatementAttribute;
import java.util.ArrayList;
import java.util.Collection;
@@ -63,9 +63,8 @@ public final class SQLStatementContextExtractor {
if (!tableNames.isEmpty()) {
return tableNames;
}
- return sqlStatementContext instanceof IndexContextAvailable
- ? getTableNames(database, sqlStatementContext.getDatabaseType(), ((IndexContextAvailable) sqlStatementContext).getIndexes())
- : Collections.emptyList();
+ return sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class)
+ .map(optional -> getTableNames(database, sqlStatementContext.getDatabaseType(), optional.getIndexes())).orElse(Collections.emptyList());
}
private static Collection<String> getTableNames(final ShardingSphereDatabase database, final DatabaseType databaseType, final Collection<IndexSegment> indexes) {
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContext.java
deleted file mode 100644
index 87020fd08af..00000000000
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContext.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import lombok.Getter;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
-import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.AlterIndexStatement;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-
-/**
- * Alter index statement context.
- */
-@Getter
-public final class AlterIndexStatementContext implements SQLStatementContext, IndexContextAvailable {
-
- private final DatabaseType databaseType;
-
- private final AlterIndexStatement sqlStatement;
-
- private final TablesContext tablesContext;
-
- public AlterIndexStatementContext(final DatabaseType databaseType, final AlterIndexStatement sqlStatement) {
- this.databaseType = databaseType;
- this.sqlStatement = sqlStatement;
- tablesContext = new TablesContext(sqlStatement.getSimpleTable().orElse(null));
- }
-
- @Override
- public Collection<IndexSegment> getIndexes() {
- Collection<IndexSegment> result = new LinkedList<>();
- if (sqlStatement.getIndex().isPresent()) {
- result.add(sqlStatement.getIndex().get());
- }
- sqlStatement.getRenameIndex().ifPresent(result::add);
- return result;
- }
-
- @Override
- public Collection<ColumnSegment> getIndexColumns() {
- return Collections.emptyList();
- }
-}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContext.java
deleted file mode 100644
index 8788dcd7ece..00000000000
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContext.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import lombok.Getter;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
-import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.AddColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.DropIndexDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.RenameIndexDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.stream.Collectors;
-
-/**
- * Alter table statement context.
- */
-@Getter
-public final class AlterTableStatementContext implements SQLStatementContext, IndexContextAvailable {
-
- private final DatabaseType databaseType;
-
- private final AlterTableStatement sqlStatement;
-
- private final TablesContext tablesContext;
-
- public AlterTableStatementContext(final DatabaseType databaseType, final AlterTableStatement sqlStatement) {
- this.databaseType = databaseType;
- this.sqlStatement = sqlStatement;
- tablesContext = new TablesContext(getTables(sqlStatement));
- }
-
- private Collection<SimpleTableSegment> getTables(final AlterTableStatement sqlStatement) {
- Collection<SimpleTableSegment> result = new LinkedList<>();
- result.add(sqlStatement.getTable());
- if (sqlStatement.getRenameTable().isPresent()) {
- result.add(sqlStatement.getRenameTable().get());
- }
- for (AddColumnDefinitionSegment each : sqlStatement.getAddColumnDefinitions()) {
- for (ColumnDefinitionSegment columnDefinition : each.getColumnDefinitions()) {
- result.addAll(columnDefinition.getReferencedTables());
- }
- }
- for (ModifyColumnDefinitionSegment each : sqlStatement.getModifyColumnDefinitions()) {
- result.addAll(each.getColumnDefinition().getReferencedTables());
- }
- for (AddConstraintDefinitionSegment each : sqlStatement.getAddConstraintDefinitions()) {
- each.getConstraintDefinition().getReferencedTable().ifPresent(result::add);
- }
- return result;
- }
-
- @Override
- public Collection<IndexSegment> getIndexes() {
- Collection<IndexSegment> result = new LinkedList<>();
- for (AddConstraintDefinitionSegment each : sqlStatement.getAddConstraintDefinitions()) {
- each.getConstraintDefinition().getIndexName().ifPresent(result::add);
- }
- sqlStatement.getDropIndexDefinitions().stream().map(DropIndexDefinitionSegment::getIndexSegment).forEach(result::add);
- for (RenameIndexDefinitionSegment each : sqlStatement.getRenameIndexDefinitions()) {
- result.add(each.getIndexSegment());
- result.add(each.getRenameIndexSegment());
- }
- return result;
- }
-
- @Override
- public Collection<ColumnSegment> getIndexColumns() {
- return sqlStatement.getAddConstraintDefinitions().stream().flatMap(each -> each.getConstraintDefinition().getIndexColumns().stream()).collect(Collectors.toList());
- }
-}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContext.java
deleted file mode 100644
index 2c018708042..00000000000
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContext.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import lombok.Getter;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
-import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtils;
-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.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.CreateIndexStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * Create index statement context.
- */
-@Getter
-public final class CreateIndexStatementContext implements SQLStatementContext, IndexContextAvailable {
-
- private final DatabaseType databaseType;
-
- private final CreateIndexStatement sqlStatement;
-
- private final TablesContext tablesContext;
-
- private final boolean generatedIndex;
-
- public CreateIndexStatementContext(final DatabaseType databaseType, final CreateIndexStatement sqlStatement) {
- this.databaseType = databaseType;
- this.sqlStatement = sqlStatement;
- tablesContext = new TablesContext(sqlStatement.getTable());
- generatedIndex = null == sqlStatement.getIndex();
- }
-
- @Override
- public Collection<IndexSegment> getIndexes() {
- if (null != sqlStatement.getIndex()) {
- return Collections.singleton(sqlStatement.getIndex());
- }
- return sqlStatement.getGeneratedIndexStartIndex().map(optional -> Collections.singletonList(new IndexSegment(optional, optional,
- new IndexNameSegment(optional, optional, new IdentifierValue(IndexMetaDataUtils.getGeneratedLogicIndexName(sqlStatement.getColumns())))))).orElseGet(Collections::emptyList);
- }
-
- @Override
- public Collection<ColumnSegment> getIndexColumns() {
- return sqlStatement.getColumns();
- }
-}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContext.java
deleted file mode 100644
index 75a1ede5921..00000000000
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContext.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import lombok.Getter;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
-import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.stream.Collectors;
-
-/**
- * Create table statement context.
- */
-@Getter
-public final class CreateTableStatementContext implements SQLStatementContext, IndexContextAvailable {
-
- private final DatabaseType databaseType;
-
- private final CreateTableStatement sqlStatement;
-
- private final TablesContext tablesContext;
-
- public CreateTableStatementContext(final DatabaseType databaseType, final CreateTableStatement sqlStatement) {
- this.databaseType = databaseType;
- this.sqlStatement = sqlStatement;
- tablesContext = new TablesContext(getTables(sqlStatement));
- }
-
- private Collection<SimpleTableSegment> getTables(final CreateTableStatement sqlStatement) {
- Collection<SimpleTableSegment> result = new LinkedList<>();
- result.add(sqlStatement.getTable());
- for (ColumnDefinitionSegment each : sqlStatement.getColumnDefinitions()) {
- result.addAll(each.getReferencedTables());
- }
- for (ConstraintDefinitionSegment each : sqlStatement.getConstraintDefinitions()) {
- if (each.getReferencedTable().isPresent()) {
- result.add(each.getReferencedTable().get());
- }
- }
- return result;
- }
-
- @Override
- public Collection<IndexSegment> getIndexes() {
- Collection<IndexSegment> result = new LinkedList<>();
- for (ConstraintDefinitionSegment each : sqlStatement.getConstraintDefinitions()) {
- each.getIndexName().ifPresent(result::add);
- }
- return result;
- }
-
- @Override
- public Collection<ColumnSegment> getIndexColumns() {
- return sqlStatement.getConstraintDefinitions().stream().flatMap(each -> each.getIndexColumns().stream()).collect(Collectors.toList());
- }
-}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorHeldSQLStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorHeldSQLStatementContext.java
index 567bd87161b..2a3fdc99d12 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorHeldSQLStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorHeldSQLStatementContext.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.available.WhereContextAvailable;
-import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -35,7 +34,7 @@ import java.util.Collections;
* Cursor held SQL statement context.
*/
@Getter
-public final class CursorHeldSQLStatementContext implements SQLStatementContext, WhereContextAvailable, CursorAware {
+public final class CursorHeldSQLStatementContext implements SQLStatementContext, WhereContextAvailable {
private final DatabaseType databaseType;
@@ -51,7 +50,11 @@ public final class CursorHeldSQLStatementContext implements SQLStatementContext,
tablesContext = new TablesContext(Collections.emptyList());
}
- @Override
+ /**
+ * Set cursor statement context.
+ *
+ * @param cursorStatementContext cursor statement context
+ */
public void setCursorStatementContext(final CursorStatementContext cursorStatementContext) {
this.cursorStatementContext = cursorStatementContext;
tablesContext = cursorStatementContext.getTablesContext();
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContext.java
deleted file mode 100644
index 7839882ec19..00000000000
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContext.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import lombok.Getter;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
-import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.DropIndexStatement;
-
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * Drop index statement context.
- */
-@Getter
-public final class DropIndexStatementContext implements SQLStatementContext, IndexContextAvailable {
-
- private final DatabaseType databaseType;
-
- private final DropIndexStatement sqlStatement;
-
- private final TablesContext tablesContext;
-
- public DropIndexStatementContext(final DatabaseType databaseType, final DropIndexStatement sqlStatement) {
- this.databaseType = databaseType;
- this.sqlStatement = sqlStatement;
- tablesContext = new TablesContext(sqlStatement.getSimpleTable().orElse(null));
- }
-
- @Override
- public Collection<IndexSegment> getIndexes() {
- return sqlStatement.getIndexes();
- }
-
- @Override
- public Collection<ColumnSegment> getIndexColumns() {
- return Collections.emptyList();
- }
-}
diff --git a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContextTest.java b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContextTest.java
deleted file mode 100644
index d9ae38ebbb3..00000000000
--- a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContextTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-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.statement.type.ddl.index.AlterIndexStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class AlterIndexStatementContextTest {
-
- @Test
- void assertNewInstance() {
- AlterIndexStatement alterIndexStatement = mock(AlterIndexStatement.class);
- 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(mock(), alterIndexStatement);
- assertThat(actual.getSqlStatement(), is(alterIndexStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.emptyList()));
- assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_1")));
- }
-}
diff --git a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContextTest.java b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContextTest.java
deleted file mode 100644
index d67d18e399e..00000000000
--- a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContextTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.AddColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
-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.type.ddl.table.AlterTableStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class AlterTableStatementContextTest {
-
- @Test
- void assertNewInstance() {
- AlterTableStatement alterTableStatement = new AlterTableStatement();
- SimpleTableSegment table = new SimpleTableSegment(createTableNameSegment("foo_tbl"));
- alterTableStatement.setTable(table);
- alterTableStatement.setRenameTable(new SimpleTableSegment(createTableNameSegment("rename_foo_tbl")));
- Collection<SimpleTableSegment> referencedTables = Collections.singletonList(table);
- ColumnDefinitionSegment columnDefinition = mock(ColumnDefinitionSegment.class);
- when(columnDefinition.getReferencedTables()).thenReturn(referencedTables);
- AddColumnDefinitionSegment addColumnDefinition = mock(AddColumnDefinitionSegment.class);
- when(addColumnDefinition.getColumnDefinitions()).thenReturn(Collections.singletonList(columnDefinition));
- alterTableStatement.getAddColumnDefinitions().add(addColumnDefinition);
- ModifyColumnDefinitionSegment modifyColumnDefinition = mock(ModifyColumnDefinitionSegment.class);
- when(modifyColumnDefinition.getColumnDefinition()).thenReturn(columnDefinition);
- alterTableStatement.getModifyColumnDefinitions().add(modifyColumnDefinition);
- ConstraintDefinitionSegment constraintDefinition = mock(ConstraintDefinitionSegment.class);
- when(constraintDefinition.getReferencedTable()).thenReturn(Optional.of(table));
- when(constraintDefinition.getIndexName()).thenReturn(Optional.of(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index")))));
- AddConstraintDefinitionSegment addConstraintDefinition = mock(AddConstraintDefinitionSegment.class);
- when(addConstraintDefinition.getConstraintDefinition()).thenReturn(constraintDefinition);
- ConstraintSegment constraint = new ConstraintSegment(0, 0, new IdentifierValue("constraint"));
- when(addConstraintDefinition.getConstraintDefinition().getConstraintName()).thenReturn(Optional.of(constraint));
- alterTableStatement.getAddConstraintDefinitions().add(addConstraintDefinition);
- ValidateConstraintDefinitionSegment validateConstraintDefinition = mock(ValidateConstraintDefinitionSegment.class);
- when(validateConstraintDefinition.getConstraintName()).thenReturn(constraint);
- alterTableStatement.getValidateConstraintDefinitions().add(validateConstraintDefinition);
- DropConstraintDefinitionSegment dropConstraintDefinition = mock(DropConstraintDefinitionSegment.class);
- when(dropConstraintDefinition.getConstraintName()).thenReturn(constraint);
- alterTableStatement.getDropConstraintDefinitions().add(dropConstraintDefinition);
- 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(mock(), alterTableStatement);
- assertThat(actual.getSqlStatement(), is(alterTableStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
- is(Arrays.asList("foo_tbl", "rename_foo_tbl", "foo_tbl", "foo_tbl", "foo_tbl")));
- assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("index", "drop_index")));
- }
-
- private TableNameSegment createTableNameSegment(final String tableName) {
- TableNameSegment result = new TableNameSegment(0, 0, new IdentifierValue(tableName));
- result.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- return result;
- }
-}
diff --git a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContextTest.java b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContextTest.java
deleted file mode 100644
index 739869bbb25..00000000000
--- a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContextTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-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.statement.type.ddl.index.CreateIndexStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class CreateIndexStatementContextTest {
-
- @Test
- void assertNewInstance() {
- CreateIndexStatement createIndexStatement = mock(CreateIndexStatement.class);
- CreateIndexStatementContext actual = new CreateIndexStatementContext(mock(), createIndexStatement);
- 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(mock(), createIndexStatement);
- assertThat(actual2.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_2")));
- }
-}
diff --git a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContextTest.java b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContextTest.java
deleted file mode 100644
index fc1dde30703..00000000000
--- a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContextTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintSegment;
-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.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class CreateTableStatementContextTest {
-
- @Test
- void assertNewInstance() {
- CreateTableStatement sqlStatement = new CreateTableStatement();
- SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
- sqlStatement.setTable(table);
- ColumnDefinitionSegment columnDefinition = mock(ColumnDefinitionSegment.class);
- when(columnDefinition.getReferencedTables()).thenReturn(Collections.singletonList(table));
- sqlStatement.getColumnDefinitions().add(columnDefinition);
- ConstraintDefinitionSegment constraintDefinition = mock(ConstraintDefinitionSegment.class);
- when(constraintDefinition.getConstraintName()).thenReturn(Optional.of(new ConstraintSegment(0, 0, new IdentifierValue("foo_fk"))));
- when(constraintDefinition.getReferencedTable()).thenReturn(Optional.of(table));
- sqlStatement.getConstraintDefinitions().add(constraintDefinition);
- CreateTableStatementContext actual = new CreateTableStatementContext(mock(), sqlStatement);
- assertThat(actual.getSqlStatement(), is(sqlStatement));
- when(constraintDefinition.getIndexName()).thenReturn(Optional.of(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("foo_idx")))));
- assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("foo_idx")));
- }
-}
diff --git a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContextTest.java b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContextTest.java
deleted file mode 100644
index fb1a798400a..00000000000
--- a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContextTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-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.statement.type.ddl.index.DropIndexStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class DropIndexStatementContextTest {
-
- @Test
- void assertNewInstance() {
- DropIndexStatement dropIndexStatement = mock(DropIndexStatement.class);
- Collection<IndexSegment> indexes = Arrays.asList(
- new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("foo_idx"))),
- new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("bar_idx"))));
- when(dropIndexStatement.getIndexes()).thenReturn(indexes);
- DropIndexStatementContext actual = new DropIndexStatementContext(mock(), dropIndexStatement);
- assertThat(actual.getSqlStatement(), is(dropIndexStatement));
- assertThat(actual.getTablesContext().getSimpleTables(), is(Collections.emptyList()));
- assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("foo_idx", "bar_idx")));
- }
-}
diff --git a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
index 708222937f5..09e9564a3a0 100644
--- a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
+++ b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
@@ -61,23 +61,23 @@ class KernelProcessorTest {
DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
- when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SelectStatement.class));
+ when(sqlStatementContext.getSqlStatement()).thenReturn(new SelectStatement());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
ConnectionContext connectionContext = mock(ConnectionContext.class);
when(connectionContext.getCurrentDatabaseName()).thenReturn(Optional.of("foo_db"));
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS);
when(resourceMetaData.getStorageUnits()).thenReturn(Collections.singletonMap("ds_0", mock(StorageUnit.class)));
- ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", databaseType, resourceMetaData, new RuleMetaData(mockShardingSphereRule()), Collections.emptyList());
+ ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", databaseType, resourceMetaData, new RuleMetaData(mockRule()), Collections.emptyList());
when(metaData.containsDatabase("foo_db")).thenReturn(true);
when(metaData.getDatabase("foo_db")).thenReturn(database);
QueryContext queryContext = new QueryContext(sqlStatementContext, "SELECT * FROM tbl", Collections.emptyList(), new HintValueContext(), connectionContext, metaData);
ConfigurationProperties props = new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString())));
- ExecutionContext actual = new KernelProcessor().generateExecutionContext(queryContext, new RuleMetaData(mockShardingSphereRule()), props);
+ ExecutionContext actual = new KernelProcessor().generateExecutionContext(queryContext, new RuleMetaData(mockRule()), props);
assertThat(actual.getExecutionUnits().size(), is(1));
}
- private Collection<ShardingSphereRule> mockShardingSphereRule() {
+ private Collection<ShardingSphereRule> mockRule() {
Collection<ShardingSphereRule> result = new LinkedList<>();
SQLTranslatorRule sqlTranslatorRule = mock(SQLTranslatorRule.class);
when(sqlTranslatorRule.getAttributes()).thenReturn(new RuleAttributes());
diff --git a/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java b/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
index 2bffb9a6be0..beb777d9ab1 100644
--- a/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
+++ b/infra/rewrite/core/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.generic;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.DialectDatabaseMetaData;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -30,6 +29,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
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.statement.attribute.type.IndexSQLStatementAttribute;
import java.util.Collection;
import java.util.Collections;
@@ -50,7 +50,7 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<S
if (!sqlStatementContext.getTablesContext().getSimpleTables().isEmpty()) {
return true;
}
- return sqlStatementContext instanceof IndexContextAvailable && !((IndexContextAvailable) sqlStatementContext).getIndexes().isEmpty();
+ return sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class).map(optional -> !optional.getIndexes().isEmpty()).orElse(false);
}
@Override
@@ -64,8 +64,8 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<S
if (!sqlStatementContext.getTablesContext().getSimpleTables().isEmpty()) {
result.addAll(generateTableAvailableSQLTokens(sqlStatementContext, sqlStatementContext.getDatabaseType()));
}
- if (sqlStatementContext instanceof IndexContextAvailable && !((IndexContextAvailable) sqlStatementContext).getIndexes().isEmpty()) {
- result.addAll(generateIndexContextAvailableSQLTokens((IndexContextAvailable) sqlStatementContext));
+ if (sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class).map(optional -> !optional.getIndexes().isEmpty()).orElse(false)) {
+ result.addAll(generateIndexContextAvailableSQLTokens(sqlStatementContext));
}
return result;
}
@@ -91,9 +91,10 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<S
return result;
}
- private Collection<RemoveToken> generateIndexContextAvailableSQLTokens(final IndexContextAvailable indexContextAvailable) {
+ private Collection<RemoveToken> generateIndexContextAvailableSQLTokens(final SQLStatementContext sqlStatementContext) {
Collection<RemoveToken> result = new LinkedList<>();
- for (IndexSegment each : indexContextAvailable.getIndexes()) {
+ for (IndexSegment each : sqlStatementContext.getSqlStatement().getAttributes()
+ .findAttribute(IndexSQLStatementAttribute.class).map(IndexSQLStatementAttribute::getIndexes).orElse(Collections.emptyList())) {
if (!each.getOwner().isPresent()) {
continue;
}
diff --git a/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java b/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java
index ff800ca263a..166dc69fcca 100644
--- a/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java
+++ b/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java
@@ -33,6 +33,8 @@ import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
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.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
import org.apache.shardingsphere.sqltranslator.context.SQLTranslatorContext;
import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule;
import org.apache.shardingsphere.sqltranslator.rule.builder.DefaultSQLTranslatorRuleConfigurationBuilder;
@@ -73,6 +75,9 @@ class SQLRewriteEntryTest {
when(result.getParameters()).thenReturn(Collections.singletonList(1));
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ SQLStatement sqlStatement = mock(SQLStatement.class);
+ when(sqlStatement.getAttributes()).thenReturn(new SQLStatementAttributes());
+ when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
when(result.getSqlStatementContext()).thenReturn(sqlStatementContext);
when(result.getHintValueContext()).thenReturn(new HintValueContext());
diff --git a/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java b/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
index f4c11f2d139..eb3203e305a 100644
--- a/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
+++ b/infra/rewrite/core/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.Collec
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.OptionalSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.session.query.QueryContext;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -75,6 +77,9 @@ class SQLRewriteContextTest {
@BeforeEach
void setUp() {
when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ SQLStatement sqlStatement = mock(SQLStatement.class);
+ when(sqlStatement.getAttributes()).thenReturn(new SQLStatementAttributes());
+ when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
when(optionalSQLTokenGenerator.generateSQLToken(sqlStatementContext)).thenReturn(sqlToken);
when(collectionSQLTokenGenerator.generateSQLTokens(sqlStatementContext)).thenReturn(Collections.singleton(sqlToken));
when(database.getName()).thenReturn("foo_db");
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
index 68df871b9c8..ee146c1148a 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
@@ -19,11 +19,7 @@ package org.apache.shardingsphere.data.pipeline.core.metadata.generator;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
@@ -37,7 +33,11 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.ConstraintSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.CommentStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.CreateIndexStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
import java.util.Collections;
import java.util.Comparator;
@@ -83,18 +83,18 @@ public final class PipelineDDLDecorator {
private String decorateActualSQL(final String databaseName, final String targetTableName, final SQLParserEngine parserEngine, final DatabaseType databaseType, final String sql) {
SQLStatementContext sqlStatementContext = parseSQL(databaseName, parserEngine, databaseType, sql);
Map<SQLSegment, String> replaceMap = new TreeMap<>(Comparator.comparing(SQLSegment::getStartIndex));
- if (sqlStatementContext instanceof CreateTableStatementContext) {
+ if (sqlStatementContext.getSqlStatement() instanceof CreateTableStatement) {
appendFromIndexAndConstraint(replaceMap, targetTableName, sqlStatementContext);
appendFromTable(replaceMap, targetTableName, sqlStatementContext);
}
if (sqlStatementContext.getSqlStatement() instanceof CommentStatement) {
appendFromTable(replaceMap, targetTableName, sqlStatementContext);
}
- if (sqlStatementContext instanceof CreateIndexStatementContext) {
+ if (sqlStatementContext.getSqlStatement() instanceof CreateIndexStatement) {
appendFromTable(replaceMap, targetTableName, sqlStatementContext);
appendFromIndexAndConstraint(replaceMap, targetTableName, sqlStatementContext);
}
- if (sqlStatementContext instanceof AlterTableStatementContext) {
+ if (sqlStatementContext.getSqlStatement() instanceof AlterTableStatement) {
appendFromIndexAndConstraint(replaceMap, targetTableName, sqlStatementContext);
appendFromTable(replaceMap, targetTableName, sqlStatementContext);
}
@@ -112,11 +112,9 @@ public final class PipelineDDLDecorator {
TableNameSegment tableNameSegment = sqlStatementContext.getTablesContext().getSimpleTables().iterator().next().getTableName();
if (!tableNameSegment.getIdentifier().getValue().equals(targetTableName)) {
SQLStatementAttributes attributes = sqlStatementContext.getSqlStatement().getAttributes();
- if (sqlStatementContext instanceof IndexContextAvailable) {
- for (IndexSegment each : ((IndexContextAvailable) sqlStatementContext).getIndexes()) {
- String logicIndexName = IndexMetaDataUtils.getLogicIndexName(each.getIndexName().getIdentifier().getValue(), tableNameSegment.getIdentifier().getValue());
- replaceMap.put(each.getIndexName(), logicIndexName);
- }
+ for (IndexSegment each : attributes.findAttribute(IndexSQLStatementAttribute.class).map(IndexSQLStatementAttribute::getIndexes).orElse(Collections.emptyList())) {
+ String logicIndexName = IndexMetaDataUtils.getLogicIndexName(each.getIndexName().getIdentifier().getValue(), tableNameSegment.getIdentifier().getValue());
+ replaceMap.put(each.getIndexName(), logicIndexName);
}
for (ConstraintSegment each : attributes.findAttribute(ConstraintSQLStatementAttribute.class).map(ConstraintSQLStatementAttribute::getConstraints).orElse(Collections.emptyList())) {
String logicConstraint = IndexMetaDataUtils.getLogicIndexName(each.getIdentifier().getValue(), tableNameSegment.getIdentifier().getValue());
@@ -158,8 +156,8 @@ public final class PipelineDDLDecorator {
private String replaceTableNameWithPrefix(final String sql, final String schemaName, final String databaseName, final SQLParserEngine parserEngine, final DatabaseType databaseType) {
SQLStatementContext sqlStatementContext = parseSQL(databaseName, parserEngine, databaseType, sql);
- if (sqlStatementContext instanceof CreateTableStatementContext || sqlStatementContext.getSqlStatement() instanceof CommentStatement
- || sqlStatementContext instanceof CreateIndexStatementContext || sqlStatementContext instanceof AlterTableStatementContext) {
+ if (sqlStatementContext.getSqlStatement() instanceof CreateTableStatement || sqlStatementContext.getSqlStatement() instanceof CreateIndexStatement
+ || sqlStatementContext.getSqlStatement() instanceof AlterTableStatement || sqlStatementContext.getSqlStatement() instanceof CommentStatement) {
if (sqlStatementContext.getTablesContext().getSimpleTables().isEmpty()) {
return sql;
}
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
index 53c65869d4c..001085bf547 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.single.rule;
import com.cedarsoftware.util.CaseInsensitiveSet;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.available.IndexContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -37,6 +36,7 @@ import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.constant.SingleOrder;
import org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
import javax.sql.DataSource;
import java.util.ArrayList;
@@ -173,10 +173,11 @@ public final class SingleRule implements DatabaseRule {
public Collection<QualifiedTable> getQualifiedTables(final SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database) {
Collection<SimpleTableSegment> tables = sqlStatementContext.getTablesContext().getSimpleTables();
Collection<QualifiedTable> result = getQualifiedTables(database, protocolType, tables);
- if (result.isEmpty() && sqlStatementContext instanceof IndexContextAvailable) {
- result = IndexMetaDataUtils.getTableNames(database, protocolType, ((IndexContextAvailable) sqlStatementContext).getIndexes());
+ if (!result.isEmpty()) {
+ return result;
}
- return result;
+ return sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class)
+ .map(optional -> IndexMetaDataUtils.getTableNames(database, protocolType, optional.getIndexes())).orElse(result);
}
private Collection<QualifiedTable> getQualifiedTables(final ShardingSphereDatabase database, final DatabaseType databaseType, final Collection<SimpleTableSegment> tableSegments) {
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 29a90b96608..032ed691bea 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
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.single.route;
import org.apache.groovy.util.Maps;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -224,6 +224,6 @@ class SingleSQLRouterTest {
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(databaseType, createTableStatement), "CREATE TABLE", new LinkedList<>(), new HintValueContext(), connectionContext, metaData);
+ return new QueryContext(new CommonSQLStatementContext(databaseType, createTableStatement), "CREATE TABLE", new LinkedList<>(), new HintValueContext(), connectionContext, metaData);
}
}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/available/IndexContextAvailable.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/attribute/type/IndexSQLStatementAttribute.java
similarity index 81%
rename from infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/available/IndexContextAvailable.java
rename to parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/attribute/type/IndexSQLStatementAttribute.java
index d58d65923f9..860fe95da0e 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/available/IndexContextAvailable.java
+++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/attribute/type/IndexSQLStatementAttribute.java
@@ -15,17 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.binder.context.available;
+package org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttribute;
import java.util.Collection;
/**
- * Index context available.
+ * Index SQL statement attribute.
*/
-public interface IndexContextAvailable {
+public interface IndexSQLStatementAttribute extends SQLStatementAttribute {
/**
* Get index segments.
diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/AlterIndexStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/AlterIndexStatement.java
index 84d4e85c86c..49cd3510d1a 100644
--- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/AlterIndexStatement.java
+++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/AlterIndexStatement.java
@@ -19,9 +19,16 @@ package org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.i
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TableSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
import java.util.Optional;
/**
@@ -62,4 +69,27 @@ public final class AlterIndexStatement extends DDLStatement {
public Optional<SimpleTableSegment> getSimpleTable() {
return Optional.ofNullable(simpleTable);
}
+
+ @Override
+ public SQLStatementAttributes getAttributes() {
+ return new SQLStatementAttributes(new TableSQLStatementAttribute(simpleTable), new AlterIndexIndexSQLStatementAttribute());
+ }
+
+ private class AlterIndexIndexSQLStatementAttribute implements IndexSQLStatementAttribute {
+
+ @Override
+ public Collection<IndexSegment> getIndexes() {
+ Collection<IndexSegment> result = new LinkedList<>();
+ if (getIndex().isPresent()) {
+ result.add(getIndex().get());
+ }
+ getRenameIndex().ifPresent(result::add);
+ return result;
+ }
+
+ @Override
+ public Collection<ColumnSegment> getIndexColumns() {
+ return Collections.emptyList();
+ }
+ }
}
diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/CreateIndexStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/CreateIndexStatement.java
index c8a104e7ebf..436c1cf02ba 100644
--- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/CreateIndexStatement.java
+++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/CreateIndexStatement.java
@@ -19,16 +19,23 @@ package org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.i
import lombok.Getter;
import lombok.Setter;
+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.ddl.table.AlgorithmTypeSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.LockTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TableSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Create index statement.
@@ -77,4 +84,39 @@ public final class CreateIndexStatement extends DDLStatement {
public Optional<LockTableSegment> getLockTable() {
return Optional.ofNullable(lockTable);
}
+
+ @Override
+ public SQLStatementAttributes getAttributes() {
+ return new SQLStatementAttributes(new TableSQLStatementAttribute(table), new CreateIndexIndexSQLStatementAttribute());
+ }
+
+ private class CreateIndexIndexSQLStatementAttribute implements IndexSQLStatementAttribute {
+
+ private static final String UNDERLINE = "_";
+
+ private static final String GENERATED_LOGIC_INDEX_NAME_SUFFIX = "idx";
+
+ @Override
+ public Collection<IndexSegment> getIndexes() {
+ if (null != index) {
+ return Collections.singleton(index);
+ }
+ if (getGeneratedIndexStartIndex().isPresent()) {
+ int generatedIndexStartIndex = getGeneratedIndexStartIndex().get();
+ IndexNameSegment generatedIndexNameSegment = new IndexNameSegment(generatedIndexStartIndex, generatedIndexStartIndex,
+ new IdentifierValue(getGeneratedLogicIndexName(columns)));
+ return Collections.singleton(new IndexSegment(generatedIndexStartIndex, generatedIndexStartIndex, generatedIndexNameSegment));
+ }
+ return Collections.emptyList();
+ }
+
+ private String getGeneratedLogicIndexName(final Collection<ColumnSegment> columns) {
+ return columns.stream().map(each -> each.getIdentifier().getValue() + UNDERLINE).collect(Collectors.joining("", "", GENERATED_LOGIC_INDEX_NAME_SUFFIX));
+ }
+
+ @Override
+ public Collection<ColumnSegment> getIndexColumns() {
+ return columns;
+ }
+ }
}
diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/DropIndexStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/DropIndexStatement.java
index 9404dbd56ee..5ff36ebee3e 100644
--- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/DropIndexStatement.java
+++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/DropIndexStatement.java
@@ -22,10 +22,15 @@ import lombok.Setter;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.AlgorithmTypeSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.LockTableSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TableSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.Optional;
@@ -72,4 +77,22 @@ public final class DropIndexStatement extends DDLStatement {
public Optional<LockTableSegment> getLockTable() {
return Optional.ofNullable(lockTable);
}
+
+ @Override
+ public SQLStatementAttributes getAttributes() {
+ return new SQLStatementAttributes(new TableSQLStatementAttribute(simpleTable), new DropIndexIndexSQLStatementAttribute());
+ }
+
+ private class DropIndexIndexSQLStatementAttribute implements IndexSQLStatementAttribute {
+
+ @Override
+ public Collection<IndexSegment> getIndexes() {
+ return indexes;
+ }
+
+ @Override
+ public Collection<ColumnSegment> getIndexColumns() {
+ return Collections.emptyList();
+ }
+ }
}
diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/AlterTableStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/AlterTableStatement.java
index 79897d66651..e42f92f62c2 100644
--- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/AlterTableStatement.java
+++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/AlterTableStatement.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.t
import lombok.Getter;
import lombok.Setter;
+import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.AddColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.ChangeColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.DropColumnDefinitionSegment;
@@ -31,18 +32,23 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constrain
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.DropIndexDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.RenameIndexDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.AlgorithmTypeSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.ConvertTableDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.LockTableSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.ConstraintSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TableSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Alter table statement.
@@ -132,10 +138,30 @@ public final class AlterTableStatement extends DDLStatement {
@Override
public SQLStatementAttributes getAttributes() {
- return new SQLStatementAttributes(new CreateTableConstraintSQLStatementAttribute());
+ return new SQLStatementAttributes(new TableSQLStatementAttribute(getTables()), new AlterTableConstraintSQLStatementAttribute(), new AlterTableIndexSQLStatementAttribute());
}
- private class CreateTableConstraintSQLStatementAttribute implements ConstraintSQLStatementAttribute {
+ private Collection<SimpleTableSegment> getTables() {
+ Collection<SimpleTableSegment> result = new LinkedList<>();
+ result.add(table);
+ if (getRenameTable().isPresent()) {
+ result.add(getRenameTable().get());
+ }
+ for (AddColumnDefinitionSegment each : addColumnDefinitions) {
+ for (ColumnDefinitionSegment columnDefinition : each.getColumnDefinitions()) {
+ result.addAll(columnDefinition.getReferencedTables());
+ }
+ }
+ for (ModifyColumnDefinitionSegment each : modifyColumnDefinitions) {
+ result.addAll(each.getColumnDefinition().getReferencedTables());
+ }
+ for (AddConstraintDefinitionSegment each : addConstraintDefinitions) {
+ each.getConstraintDefinition().getReferencedTable().ifPresent(result::add);
+ }
+ return result;
+ }
+
+ private class AlterTableConstraintSQLStatementAttribute implements ConstraintSQLStatementAttribute {
@Override
public Collection<ConstraintSegment> getConstraints() {
@@ -148,4 +174,26 @@ public final class AlterTableStatement extends DDLStatement {
return result;
}
}
+
+ private class AlterTableIndexSQLStatementAttribute implements IndexSQLStatementAttribute {
+
+ @Override
+ public Collection<IndexSegment> getIndexes() {
+ Collection<IndexSegment> result = new LinkedList<>();
+ for (AddConstraintDefinitionSegment each : addConstraintDefinitions) {
+ each.getConstraintDefinition().getIndexName().ifPresent(result::add);
+ }
+ dropIndexDefinitions.stream().map(DropIndexDefinitionSegment::getIndexSegment).forEach(result::add);
+ for (RenameIndexDefinitionSegment each : getRenameIndexDefinitions()) {
+ result.add(each.getIndexSegment());
+ result.add(each.getRenameIndexSegment());
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<ColumnSegment> getIndexColumns() {
+ return addConstraintDefinitions.stream().flatMap(each -> each.getConstraintDefinition().getIndexColumns().stream()).collect(Collectors.toList());
+ }
+ }
}
diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/CreateTableStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/CreateTableStatement.java
index 97c4d620e31..a216ad24566 100644
--- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/CreateTableStatement.java
+++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/table/CreateTableStatement.java
@@ -22,11 +22,14 @@ import lombok.Setter;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.CreateTableOptionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.ConstraintSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TableSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
@@ -34,6 +37,7 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Create table statement.
@@ -87,7 +91,21 @@ public final class CreateTableStatement extends DDLStatement {
@Override
public SQLStatementAttributes getAttributes() {
- return new SQLStatementAttributes(new CreateTableConstraintSQLStatementAttribute());
+ return new SQLStatementAttributes(new TableSQLStatementAttribute(getTables()), new CreateTableConstraintSQLStatementAttribute(), new CreateTableIndexSQLStatementAttribute());
+ }
+
+ private Collection<SimpleTableSegment> getTables() {
+ Collection<SimpleTableSegment> result = new LinkedList<>();
+ result.add(table);
+ for (ColumnDefinitionSegment each : columnDefinitions) {
+ result.addAll(each.getReferencedTables());
+ }
+ for (ConstraintDefinitionSegment each : constraintDefinitions) {
+ if (each.getReferencedTable().isPresent()) {
+ result.add(each.getReferencedTable().get());
+ }
+ }
+ return result;
}
private class CreateTableConstraintSQLStatementAttribute implements ConstraintSQLStatementAttribute {
@@ -101,4 +119,21 @@ public final class CreateTableStatement extends DDLStatement {
return result;
}
}
+
+ private class CreateTableIndexSQLStatementAttribute implements IndexSQLStatementAttribute {
+
+ @Override
+ public Collection<IndexSegment> getIndexes() {
+ Collection<IndexSegment> result = new LinkedList<>();
+ for (ConstraintDefinitionSegment each : constraintDefinitions) {
+ each.getIndexName().ifPresent(result::add);
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<ColumnSegment> getIndexColumns() {
+ return constraintDefinitions.stream().flatMap(each -> each.getIndexColumns().stream()).collect(Collectors.toList());
+ }
+ }
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java
index ce6d8b89325..e3f5ea37fc6 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.proxy.backend.connector;
-import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorHeldSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
@@ -162,10 +162,10 @@ public final class StandardDatabaseConnector implements DatabaseConnector {
if (sqlStatementContext instanceof CursorStatementContext) {
cursorContext.getCursorStatementContexts().put(cursorName, (CursorStatementContext) sqlStatementContext);
}
- if (sqlStatementContext instanceof CursorAware) {
+ if (sqlStatementContext instanceof CursorHeldSQLStatementContext) {
ShardingSpherePreconditions.checkContainsKey(
cursorContext.getCursorStatementContexts(), cursorName, () -> new IllegalArgumentException(String.format("Cursor %s does not exist.", cursorName)));
- ((CursorAware) sqlStatementContext).setCursorStatementContext(cursorContext.getCursorStatementContexts().get(cursorName));
+ ((CursorHeldSQLStatementContext) sqlStatementContext).setCursorStatementContext(cursorContext.getCursorStatementContexts().get(cursorName));
}
if (sqlStatementContext.getSqlStatement() instanceof CloseStatement) {
cursorContext.removeCursor(cursorName);
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
index 1da069ffadb..3ea7354ba85 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
@@ -24,8 +24,8 @@ import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAw
import org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.distsql.statement.rul.sql.PreviewStatement;
-import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorHeldSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
@@ -96,8 +96,9 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem
metaData, currentDatabaseName, hintValueContext).bind(database.getProtocolType(), toBePreviewedStatement, Collections.emptyList());
QueryContext queryContext = new QueryContext(
toBePreviewedStatementContext, toBePreviewedSQL, Collections.emptyList(), hintValueContext, connectionContext.getQueryContext().getConnectionContext(), metaData);
- if (toBePreviewedStatementContext.getSqlStatement().getAttributes().findAttribute(CursorSQLStatementAttribute.class).isPresent() && toBePreviewedStatementContext instanceof CursorAware) {
- setUpCursorDefinition(toBePreviewedStatementContext);
+ if (toBePreviewedStatementContext.getSqlStatement().getAttributes().findAttribute(CursorSQLStatementAttribute.class).isPresent()
+ && toBePreviewedStatementContext instanceof CursorHeldSQLStatementContext) {
+ setUpCursorDefinition((CursorHeldSQLStatementContext) toBePreviewedStatementContext);
}
ShardingSpherePreconditions.checkState(database.isComplete(), () -> new EmptyRuleException(database.getName()));
String schemaName = getSchemaName(queryContext.getSqlStatementContext(), database);
@@ -120,7 +121,7 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem
return new KernelProcessor().generateExecutionContext(queryContext, metaData.getGlobalRuleMetaData(), metaData.getProps()).getExecutionUnits();
}
- private void setUpCursorDefinition(final SQLStatementContext toBePreviewedStatementContext) {
+ private void setUpCursorDefinition(final CursorHeldSQLStatementContext toBePreviewedStatementContext) {
Optional<CursorNameSegment> cursorNameSegment = toBePreviewedStatementContext.getSqlStatement().getAttributes().getAttribute(CursorSQLStatementAttribute.class).getCursorName();
if (!cursorNameSegment.isPresent()) {
return;
@@ -128,7 +129,7 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem
String cursorName = cursorNameSegment.get().getIdentifier().getValue().toLowerCase();
CursorStatementContext cursorStatementContext = connectionContext.getQueryContext().getConnectionContext().getCursorContext().getCursorStatementContexts().get(cursorName);
Preconditions.checkNotNull(cursorStatementContext, "Cursor %s does not exist.", cursorName);
- ((CursorAware) toBePreviewedStatementContext).setCursorStatementContext(cursorStatementContext);
+ toBePreviewedStatementContext.setCursorStatementContext(cursorStatementContext);
}
private Collection<ExecutionUnit> getFederationExecutionUnits(final QueryContext queryContext, final ShardingSphereMetaData metaData, final SQLFederationEngine federationEngine) {
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 bd807c6efb6..41410660c91 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
@@ -19,11 +19,9 @@ package org.apache.shardingsphere.proxy.backend.connector;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.exception.dialect.exception.transaction.TableModifyInTransactionException;
@@ -33,7 +31,6 @@ import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics;
import org.apache.shardingsphere.infra.metadata.statistics.builder.ShardingSphereStatisticsFactory;
@@ -48,8 +45,6 @@ import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
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.attribute.SQLStatementAttributes;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TableSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.TruncateStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.InsertStatement;
@@ -248,15 +243,14 @@ class ProxySQLExecutorTest {
new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class), mockQueryContext()).checkExecutePrerequisites(executionContext);
}
- private CreateTableStatementContext createCreateTableStatementContext(final DatabaseType databaseType) {
- CreateTableStatement sqlStatement = mock(CreateTableStatement.class);
- when(sqlStatement.getTable()).thenReturn(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
- return new CreateTableStatementContext(databaseType, sqlStatement);
+ private CommonSQLStatementContext createCreateTableStatementContext(final DatabaseType databaseType) {
+ CreateTableStatement sqlStatement = new CreateTableStatement();
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
private SQLStatementContext createTruncateStatementContext(final DatabaseType databaseType) {
- TruncateStatement sqlStatement = mock(TruncateStatement.class);
- when(sqlStatement.getAttributes()).thenReturn(new SQLStatementAttributes(new TableSQLStatementAttribute(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))))));
+ TruncateStatement sqlStatement = new TruncateStatement(Collections.singleton(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))));
return new CommonSQLStatementContext(databaseType, sqlStatement);
}
@@ -267,15 +261,11 @@ class ProxySQLExecutorTest {
return result;
}
- private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
- return new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
- }
-
private InsertStatementContext mockInsertStatementContext(final DatabaseType databaseType) {
- InsertStatement sqlStatement = mock(InsertStatement.class);
- when(sqlStatement.getTable()).thenReturn(Optional.of(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))));
+ InsertStatement sqlStatement = new InsertStatement();
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
- return new InsertStatementContext(databaseType, sqlStatement, Collections.emptyList(), createShardingSphereMetaData(database), "foo_db");
+ return new InsertStatementContext(databaseType, sqlStatement, Collections.emptyList(), new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), "foo_db");
}
}
diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java
index be51fd50743..342e129d4fb 100644
--- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java
+++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.test.it.rewrite.engine;
import com.google.common.base.Preconditions;
-import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.aware.ParameterAware;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorHeldSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
@@ -143,8 +143,8 @@ public abstract class SQLRewriterIT {
if (result instanceof ParameterAware) {
((ParameterAware) result).setUpParameters(testParams.getInputParameters());
}
- if (result instanceof CursorAware) {
- ((CursorAware) result).setCursorStatementContext(createCursorDefinition(databaseName, metaData, databaseType, sqlParserEngine));
+ if (result instanceof CursorHeldSQLStatementContext) {
+ ((CursorHeldSQLStatementContext) result).setCursorStatementContext(createCursorDefinition(databaseName, metaData, databaseType, sqlParserEngine));
}
return result;
}