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 2022/04/26 12:54:27 UTC
[shardingsphere] branch master updated: Add IndexNameSegment in IndexSegment for schema based index rewrite (#17122)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 35d4ea13c09 Add IndexNameSegment in IndexSegment for schema based index rewrite (#17122)
35d4ea13c09 is described below
commit 35d4ea13c09389ca3b9dda83dc2ae6f762828104
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Tue Apr 26 20:54:15 2022 +0800
Add IndexNameSegment in IndexSegment for schema based index rewrite (#17122)
* Add IndexNameSegment in IndexSegment for schema based index rewrite
* fix unit test
* fix checkstyle
---
.../DatabaseDiscoveryExecutorCallback.java | 2 ++
.../token/generator/impl/IndexTokenGenerator.java | 2 +-
.../ddl/ShardingDDLStatementValidator.java | 2 +-
.../impl/ShardingAlterIndexStatementValidator.java | 4 ++--
.../ShardingCreateIndexStatementValidator.java | 2 +-
.../impl/ShardingDropIndexStatementValidator.java | 4 ++--
.../rewrite/token/IndexTokenGeneratorTest.java | 4 ++--
.../ShardingTableBroadcastRoutingEngineTest.java | 4 ++--
.../ShardingAlterIndexStatementValidatorTest.java | 13 +++++------
.../ShardingCreateIndexStatementValidatorTest.java | 7 +++---
.../ShardingDropIndexStatementValidatorTest.java | 25 +++++++++++-----------
.../statement/ddl/CreateIndexStatementContext.java | 3 ++-
.../ddl/AlterIndexStatementContextTest.java | 5 +++--
.../ddl/AlterTableStatementContextTest.java | 7 +++---
.../ddl/CreateIndexStatementContextTest.java | 5 +++--
.../ddl/CreateTableStatementContextTest.java | 5 +++--
.../ddl/DropIndexStatementContextTest.java | 11 +++++-----
.../metadata/schema/util/IndexMetaDataUtil.java | 2 +-
.../schema/util/IndexMetaDataUtilTest.java | 3 ++-
.../type/AlterIndexStatementSchemaRefresher.java | 4 ++--
.../type/CreateIndexStatementSchemaRefresher.java | 3 ++-
.../type/DropIndexStatementSchemaRefresher.java | 2 +-
.../impl/MySQLDDLStatementSQLVisitor.java | 7 ++++--
.../statement/impl/MySQLStatementSQLVisitor.java | 4 +++-
.../impl/OpenGaussDDLStatementSQLVisitor.java | 4 +++-
.../impl/OpenGaussStatementSQLVisitor.java | 4 +++-
.../statement/impl/OracleStatementSQLVisitor.java | 4 +++-
.../impl/PostgreSQLDDLStatementSQLVisitor.java | 4 +++-
.../impl/PostgreSQLStatementSQLVisitor.java | 8 ++++---
.../impl/SQLServerStatementSQLVisitor.java | 4 +++-
.../{IndexSegment.java => IndexNameSegment.java} | 19 ++++------------
.../sql/common/segment/ddl/index/IndexSegment.java | 3 +--
.../ddl/AlterIndexStatementHandlerTest.java | 3 ++-
.../definition/ConstraintDefinitionAssert.java | 2 +-
.../asserts/segment/index/IndexAssert.java | 2 +-
35 files changed, 103 insertions(+), 84 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryExecutorCallback.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryExecutorCallback.java
index 580c57918dc..13c543f9c81 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryExecutorCallback.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryExecutorCallback.java
@@ -43,7 +43,9 @@ public final class DatabaseDiscoveryExecutorCallback implements ExecutorCallback
databaseDiscoveryProviderAlgorithm.checkEnvironment(databaseName, each);
} catch (final SQLException ex) {
result.add(String.format("Error while loading highly available Status with %s", databaseName));
+ // CHECKSTYLE:OFF
} catch (final Exception ex) {
+ // CHECKSTYLE:ON
result.add(ex.getMessage());
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/IndexTokenGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/IndexTokenGenerator.java
index 78f8568c2c8..676e5872cc4 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/IndexTokenGenerator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/IndexTokenGenerator.java
@@ -56,7 +56,7 @@ public final class IndexTokenGenerator implements CollectionSQLTokenGenerator<SQ
ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(schemas::get).orElse(schemas.get(defaultSchema));
if (sqlStatementContext instanceof IndexAvailable) {
for (IndexSegment each : ((IndexAvailable) sqlStatementContext).getIndexes()) {
- result.add(new IndexToken(each.getStartIndex(), each.getStopIndex(), each.getIdentifier(), sqlStatementContext, shardingRule, schema));
+ result.add(new IndexToken(each.getStartIndex(), each.getStopIndex(), each.getIndexName().getIdentifier(), sqlStatementContext, shardingRule, schema));
}
}
return result;
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
index 68022643d53..e1fb10cacb5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
@@ -101,6 +101,6 @@ public abstract class ShardingDDLStatementValidator<T extends DDLStatement> impl
* @return whether schema contains index or not
*/
protected boolean isSchemaContainsIndex(final ShardingSphereSchema schema, final IndexSegment index) {
- return schema.getAllTableNames().stream().anyMatch(each -> schema.get(each).getIndexes().containsKey(index.getIdentifier().getValue()));
+ return schema.getAllTableNames().stream().anyMatch(each -> schema.get(each).getIndexes().containsKey(index.getIndexName().getIdentifier().getValue()));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java
index 6568143841c..b4a80a02949 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java
@@ -41,11 +41,11 @@ public final class ShardingAlterIndexStatementValidator extends ShardingDDLState
final List<Object> parameters, final ShardingSphereMetaData metaData) {
Optional<IndexSegment> index = sqlStatementContext.getSqlStatement().getIndex();
if (index.isPresent() && !isSchemaContainsIndex(metaData.getDefaultSchema(), index.get())) {
- throw new ShardingSphereException("Index '%s' does not exist.", index.get().getIdentifier().getValue());
+ throw new ShardingSphereException("Index '%s' does not exist.", index.get().getIndexName().getIdentifier().getValue());
}
Optional<IndexSegment> renameIndex = AlterIndexStatementHandler.getRenameIndexSegment(sqlStatementContext.getSqlStatement());
if (renameIndex.isPresent() && isSchemaContainsIndex(metaData.getDefaultSchema(), renameIndex.get())) {
- throw new ShardingSphereException("Index '%s' already exists.", renameIndex.get().getIdentifier().getValue());
+ throw new ShardingSphereException("Index '%s' already exists.", renameIndex.get().getIndexName().getIdentifier().getValue());
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java
index d54cb0394ec..ed1f132069a 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java
@@ -40,7 +40,7 @@ public final class ShardingCreateIndexStatementValidator extends ShardingDDLStat
final List<Object> parameters, final ShardingSphereMetaData metaData) {
validateTableExist(metaData.getDefaultSchema(), Collections.singletonList(sqlStatementContext.getSqlStatement().getTable()));
String tableName = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
- String indexName = ((IndexAvailable) sqlStatementContext).getIndexes().stream().map(each -> each.getIdentifier().getValue()).findFirst().orElse(null);
+ String indexName = ((IndexAvailable) sqlStatementContext).getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).findFirst().orElse(null);
if (metaData.getDefaultSchema().get(tableName).getIndexes().containsKey(indexName)) {
throw new ShardingSphereException("Index '%s' already exists.", indexName);
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java
index 8ee3965adff..38a579ca778 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java
@@ -46,7 +46,7 @@ public final class ShardingDropIndexStatementValidator extends ShardingDDLStatem
}
for (IndexSegment each : sqlStatementContext.getSqlStatement().getIndexes()) {
if (!isSchemaContainsIndex(metaData.getDefaultSchema(), each)) {
- throw new ShardingSphereException("Index '%s' does not exist.", each.getIdentifier().getValue());
+ throw new ShardingSphereException("Index '%s' does not exist.", each.getIndexName().getIdentifier().getValue());
}
}
}
@@ -54,7 +54,7 @@ public final class ShardingDropIndexStatementValidator extends ShardingDDLStatem
@Override
public void postValidate(final ShardingRule shardingRule, final SQLStatementContext<DropIndexStatement> sqlStatementContext, final List<Object> parameters,
final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) {
- Collection<String> indexNames = sqlStatementContext.getSqlStatement().getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());
+ Collection<String> indexNames = sqlStatementContext.getSqlStatement().getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList());
Optional<String> logicTableName = DropIndexStatementHandler.getSimpleTableSegment(sqlStatementContext.getSqlStatement()).map(table -> table.getTableName().getIdentifier().getValue());
if (logicTableName.isPresent()) {
validateDropIndexRouteUnit(shardingRule, routeContext, indexNames, logicTableName.get());
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java
index bdf14b6c2ba..246ad2559fa 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java
@@ -59,13 +59,13 @@ public final class IndexTokenGeneratorTest {
@Test
public void assertGenerateSQLTokens() {
- IndexSegment indexSegment = mock(IndexSegment.class);
+ IndexSegment indexSegment = mock(IndexSegment.class, RETURNS_DEEP_STUBS);
int testStartIndex = 1;
when(indexSegment.getStartIndex()).thenReturn(testStartIndex);
int testStopIndex = 3;
when(indexSegment.getStopIndex()).thenReturn(testStopIndex);
IdentifierValue identifierValue = mock(IdentifierValue.class);
- when(indexSegment.getIdentifier()).thenReturn(identifierValue);
+ when(indexSegment.getIndexName().getIdentifier()).thenReturn(identifierValue);
Collection<IndexSegment> indexSegments = new LinkedList<>();
indexSegments.add(indexSegment);
AlterIndexStatementContext alterIndexStatementContext = mock(AlterIndexStatementContext.class, RETURNS_DEEP_STUBS);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java
index 90d23d4a173..4a19bf8fbab 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java
@@ -92,7 +92,7 @@ public final class ShardingTableBroadcastRoutingEngineTest extends AbstractRouti
when(schema.getAllTableNames()).thenReturn(Collections.singleton("t_order"));
when(schema.get(anyString()).getIndexes().containsKey(anyString())).thenReturn(true);
IndexSegment segment = mock(IndexSegment.class, RETURNS_DEEP_STUBS);
- when(segment.getIdentifier().getValue()).thenReturn("t_order");
+ when(segment.getIndexName().getIdentifier().getValue()).thenReturn("t_order");
SQLStatementContext<DropIndexStatement> sqlStatementContext = mock(DropIndexStatementContext.class, RETURNS_DEEP_STUBS);
Collection<String> tableNames = Collections.emptyList();
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(tableNames);
@@ -112,7 +112,7 @@ public final class ShardingTableBroadcastRoutingEngineTest extends AbstractRouti
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.get(anyString()).getIndexes().containsKey(anyString())).thenReturn(false);
IndexSegment segment = mock(IndexSegment.class, RETURNS_DEEP_STUBS);
- when(segment.getIdentifier().getValue()).thenReturn("t_order");
+ when(segment.getIndexName().getIdentifier().getValue()).thenReturn("t_order");
SQLStatementContext<DropIndexStatement> sqlStatementContext = mock(DropIndexStatementContext.class, RETURNS_DEEP_STUBS);
Collection<String> tableNames = Collections.emptyList();
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(tableNames);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java
index fc6881ddb3c..54d181adb88 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingAlterIndexStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterIndexStatement;
@@ -52,8 +53,8 @@ public final class ShardingAlterIndexStatementValidatorTest {
@Test
public void assertPreValidateAlterIndexWhenIndexExistRenameIndexNotExistForPostgreSQL() {
PostgreSQLAlterIndexStatement sqlStatement = new PostgreSQLAlterIndexStatement();
- sqlStatement.setIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
- sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index_new")));
+ sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
+ sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
@@ -67,8 +68,8 @@ public final class ShardingAlterIndexStatementValidatorTest {
@Test(expected = ShardingSphereException.class)
public void assertPreValidateAlterIndexWhenIndexNotExistRenameIndexNotExistForPostgreSQL() {
PostgreSQLAlterIndexStatement sqlStatement = new PostgreSQLAlterIndexStatement();
- sqlStatement.setIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
- sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index_new")));
+ sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
+ sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
@@ -81,8 +82,8 @@ public final class ShardingAlterIndexStatementValidatorTest {
@Test(expected = ShardingSphereException.class)
public void assertPreValidateAlterIndexWhenIndexExistRenameIndexExistForPostgreSQL() {
PostgreSQLAlterIndexStatement sqlStatement = new PostgreSQLAlterIndexStatement();
- sqlStatement.setIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
- sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index_new")));
+ sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
+ sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java
index c3ab6caa2f7..279c4c29fdb 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.sharding.route.engine.exception.NoSuchTableException;
import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingCreateIndexStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -57,7 +58,7 @@ public final class ShardingCreateIndexStatementValidatorTest {
public void assertPreValidateCreateIndexWhenTableExistIndexNotExistForPostgreSQL() {
PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement();
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
- sqlStatement.setIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
+ sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
when(metaData.getDefaultSchema().containsTable("t_order")).thenReturn(true);
TableMetaData tableMetaData = mock(TableMetaData.class);
when(metaData.getDefaultSchema().get("t_order")).thenReturn(tableMetaData);
@@ -71,7 +72,7 @@ public final class ShardingCreateIndexStatementValidatorTest {
public void assertPreValidateCreateIndexWhenTableNotExistIndexNotExistForPostgreSQL() {
PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement();
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
- sqlStatement.setIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
+ sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
when(metaData.getDefaultSchema().containsTable("t_order")).thenReturn(false);
new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), metaData);
}
@@ -80,7 +81,7 @@ public final class ShardingCreateIndexStatementValidatorTest {
public void assertPreValidateCreateIndexWhenTableExistIndexExistForPostgreSQL() {
PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement();
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
- sqlStatement.setIndex(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
+ sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
when(metaData.getDefaultSchema().containsTable("t_order")).thenReturn(true);
TableMetaData tableMetaData = mock(TableMetaData.class);
when(metaData.getDefaultSchema().get("t_order")).thenReturn(tableMetaData);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java
index 0337a26a373..b76ef833f6b 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java
@@ -29,6 +29,7 @@ import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingDropIndexStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropIndexStatement;
@@ -63,8 +64,8 @@ public final class ShardingDropIndexStatementValidatorTest {
@Test
public void assertPreValidateDropIndexWhenIndexExistForPostgreSQL() {
PostgreSQLDropIndexStatement sqlStatement = new PostgreSQLDropIndexStatement();
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index_new")));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
@@ -78,8 +79,8 @@ public final class ShardingDropIndexStatementValidatorTest {
@Test(expected = ShardingSphereException.class)
public void assertPreValidateDropIndexWhenIndexNotExistForPostgreSQL() {
PostgreSQLDropIndexStatement sqlStatement = new PostgreSQLDropIndexStatement();
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index_new")));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
@@ -92,8 +93,8 @@ public final class ShardingDropIndexStatementValidatorTest {
@Test
public void assertPostValidateDropIndexWithSameRouteResultShardingTableIndexForPostgreSQL() {
PostgreSQLDropIndexStatement sqlStatement = new PostgreSQLDropIndexStatement();
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index_new")));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
@@ -113,8 +114,8 @@ public final class ShardingDropIndexStatementValidatorTest {
@Test(expected = ShardingSphereException.class)
public void assertPostValidateDropIndexWithDifferentRouteResultShardingTableIndexForPostgreSQL() {
PostgreSQLDropIndexStatement sqlStatement = new PostgreSQLDropIndexStatement();
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index")));
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_order_index_new")));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
@@ -133,8 +134,8 @@ public final class ShardingDropIndexStatementValidatorTest {
@Test
public void assertPostValidateDropIndexWithSameRouteResultBroadcastTableIndexForPostgreSQL() {
PostgreSQLDropIndexStatement sqlStatement = new PostgreSQLDropIndexStatement();
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_config_index")));
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_config_index_new")));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_config_index"))));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_config_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
@@ -154,8 +155,8 @@ public final class ShardingDropIndexStatementValidatorTest {
@Test(expected = ShardingSphereException.class)
public void assertPostValidateDropIndexWithDifferentRouteResultBroadcastTableIndexForPostgreSQL() {
PostgreSQLDropIndexStatement sqlStatement = new PostgreSQLDropIndexStatement();
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_config_index")));
- sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IdentifierValue("t_config_index_new")));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_config_index"))));
+ sqlStatement.getIndexes().add(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_config_index_new"))));
TableMetaData tableMetaData = mock(TableMetaData.class);
Map<String, IndexMetaData> indexes = mock(HashMap.class);
when(tableMetaData.getIndexes()).thenReturn(indexes);
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContext.java
index 0f40b81ba84..93c2c768dea 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContext.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContex
import org.apache.shardingsphere.infra.binder.type.IndexAvailable;
import org.apache.shardingsphere.infra.binder.type.TableAvailable;
import org.apache.shardingsphere.infra.metadata.schema.util.IndexMetaDataUtil;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
@@ -59,6 +60,6 @@ public final class CreateIndexStatementContext extends CommonSQLStatementContext
return Collections.singletonList(getSqlStatement().getIndex());
}
return CreateIndexStatementHandler.getGeneratedIndexStartIndex(getSqlStatement()).map(each -> Collections.singletonList(new IndexSegment(each, each,
- new IdentifierValue(IndexMetaDataUtil.getGeneratedLogicIndexName(getSqlStatement().getColumns()))))).orElseGet(Collections::emptyList);
+ new IndexNameSegment(each, each, new IdentifierValue(IndexMetaDataUtil.getGeneratedLogicIndexName(getSqlStatement().getColumns())))))).orElseGet(Collections::emptyList);
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterIndexStatementContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterIndexStatementContextTest.java
index 45240eeb7ff..2fb27c2396b 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterIndexStatementContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterIndexStatementContextTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.binder.statement.ddl;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -54,12 +55,12 @@ public final class AlterIndexStatementContextTest {
}
private void assertNewInstance(final AlterIndexStatement alterIndexStatement) {
- IndexSegment indexSegment = new IndexSegment(0, 0, new IdentifierValue("index_1"));
+ IndexSegment indexSegment = new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index_1")));
when(alterIndexStatement.getIndex()).thenReturn(Optional.of(indexSegment));
AlterIndexStatementContext actual = new AlterIndexStatementContext(alterIndexStatement);
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(alterIndexStatement));
assertThat(actual.getAllTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.emptyList()));
- assertThat(actual.getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_1")));
+ assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_1")));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterTableStatementContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterTableStatementContextTest.java
index 1e9eaa60de5..3eeff137b9a 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterTableStatementContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterTableStatementContextTest.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.al
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.DropIndexDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -95,7 +96,7 @@ public final class AlterTableStatementContextTest {
when(alterTableStatement.getModifyColumnDefinitions()).thenReturn(Collections.singletonList(modifyColumnDefinition));
ConstraintDefinitionSegment constraintDefinition = mock(ConstraintDefinitionSegment.class);
when(constraintDefinition.getReferencedTable()).thenReturn(Optional.of(table));
- when(constraintDefinition.getIndexName()).thenReturn(Optional.of(new IndexSegment(0, 0, new IdentifierValue("index"))));
+ 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"));
@@ -108,14 +109,14 @@ public final class AlterTableStatementContextTest {
when(dropConstraintDefinition.getConstraintName()).thenReturn(constraint);
when(alterTableStatement.getDropConstraintDefinitions()).thenReturn(Collections.singletonList(dropConstraintDefinition));
DropIndexDefinitionSegment dropIndexDefinitionSegment = mock(DropIndexDefinitionSegment.class);
- when(dropIndexDefinitionSegment.getIndexSegment()).thenReturn(new IndexSegment(0, 0, new IdentifierValue("drop_index")));
+ when(dropIndexDefinitionSegment.getIndexSegment()).thenReturn(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("drop_index"))));
when(alterTableStatement.getDropIndexDefinitions()).thenReturn(Collections.singletonList(dropIndexDefinitionSegment));
AlterTableStatementContext actual = new AlterTableStatementContext(alterTableStatement);
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(alterTableStatement));
assertThat(actual.getAllTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Arrays.asList("tbl_1", "rename_tbl_1", "tbl_1", "tbl_1", "tbl_1")));
- assertThat(actual.getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()), is(Lists.newArrayList("index", "drop_index")));
+ assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Lists.newArrayList("index", "drop_index")));
assertThat(actual.getConstraints().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()),
is(Arrays.asList("constraint", "constraint", "constraint")));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContextTest.java
index de511e38ede..9fdf9403190 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContextTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.binder.statement.ddl;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -66,8 +67,8 @@ public final class CreateIndexStatementContextTest {
assertTrue(actual.isGeneratedIndex());
assertThat(actual.getAllTables(), is(Collections.emptyList()));
assertThat(actual.getIndexes(), is(Collections.emptyList()));
- when(createIndexStatement.getIndex()).thenReturn(new IndexSegment(0, 0, new IdentifierValue("index_2")));
+ when(createIndexStatement.getIndex()).thenReturn(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index_2"))));
CreateIndexStatementContext actual2 = new CreateIndexStatementContext(createIndexStatement);
- assertThat(actual2.getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_2")));
+ assertThat(actual2.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_2")));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateTableStatementContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateTableStatementContextTest.java
index 9b84765aaa9..55661cfb72a 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateTableStatementContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateTableStatementContextTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.binder.type.ConstraintAvailable;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.ColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -87,8 +88,8 @@ public final class CreateTableStatementContextTest {
when(createTableStatement.getConstraintDefinitions()).thenReturn(Collections.singletonList(constraintDefinition));
assertThat(actual.getSqlStatement(), is(createTableStatement));
assertThat(actual.getAllTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_1", "tbl_1")));
- when(constraintDefinition.getIndexName()).thenReturn(Optional.of(new IndexSegment(0, 0, new IdentifierValue("index_1"))));
- assertThat(actual.getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_1")));
+ when(constraintDefinition.getIndexName()).thenReturn(Optional.of(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index_1")))));
+ assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_1")));
assertThat(actual.getConstraints().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("fk_1")));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/DropIndexStatementContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/DropIndexStatementContextTest.java
index 8a948fa0a4c..59a0b6fb5b1 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/DropIndexStatementContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/ddl/DropIndexStatementContextTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.binder.statement.ddl;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -27,10 +28,10 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerDropIndexStatement;
import org.junit.Test;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.Collections;
-import java.util.Arrays;
+import java.util.LinkedList;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -63,8 +64,8 @@ public final class DropIndexStatementContextTest {
private void assertNewInstance(final DropIndexStatement dropIndexStatement) {
Collection<IndexSegment> indexes = new LinkedList<>();
- IndexSegment index1 = new IndexSegment(0, 0, new IdentifierValue("idx_1"));
- IndexSegment index2 = new IndexSegment(0, 0, new IdentifierValue("idx_2"));
+ IndexSegment index1 = new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("idx_1")));
+ IndexSegment index2 = new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("idx_2")));
indexes.add(index1);
indexes.add(index2);
when(dropIndexStatement.getIndexes()).thenReturn(indexes);
@@ -72,6 +73,6 @@ public final class DropIndexStatementContextTest {
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(dropIndexStatement));
assertThat(actual.getAllTables(), is(Collections.emptyList()));
- assertThat(actual.getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("idx_1", "idx_2")));
+ assertThat(actual.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("idx_1", "idx_2")));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java
index 160b3ae8dee..7872f1c8211 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java
@@ -85,7 +85,7 @@ public class IndexMetaDataUtil {
public static Collection<String> getTableNamesFromMetaData(final ShardingSphereSchema schema, final Collection<IndexSegment> indexes) {
Collection<String> result = new LinkedList<>();
for (IndexSegment each : indexes) {
- findLogicTableNameFromMetaData(schema, each.getIdentifier().getValue()).ifPresent(result::add);
+ findLogicTableNameFromMetaData(schema, each.getIndexName().getIdentifier().getValue()).ifPresent(result::add);
}
return result;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
index 7297c5a1404..b9637da4d5f 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
@@ -21,6 +21,7 @@ import com.google.common.collect.Lists;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -74,7 +75,7 @@ public final class IndexMetaDataUtilTest {
@Test
public void assertGetTableNamesFromMetaData() {
- IndexSegment indexSegment = new IndexSegment(0, 0, new IdentifierValue(INDEX_NAME));
+ IndexSegment indexSegment = new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue(INDEX_NAME)));
assertThat(IndexMetaDataUtil.getTableNamesFromMetaData(buildSchema(), Lists.newArrayList(indexSegment)), is(Collections.singletonList(TABLE_NAME)));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java
index 3d59bb54a79..bb72a1a9ba9 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java
@@ -51,13 +51,13 @@ public final class AlterIndexStatementSchemaRefresher implements MetaDataRefresh
if (!sqlStatement.getIndex().isPresent() || !renameIndex.isPresent()) {
return;
}
- String indexName = sqlStatement.getIndex().get().getIdentifier().getValue();
+ String indexName = sqlStatement.getIndex().get().getIndexName().getIdentifier().getValue();
Optional<String> logicTableName = findLogicTableName(metaData.getSchemaByName(schemaName), indexName);
if (logicTableName.isPresent()) {
TableMetaData tableMetaData = metaData.getSchemaByName(schemaName).get(logicTableName.get());
Preconditions.checkNotNull(tableMetaData, "Can not get the table '%s' metadata!", logicTableName.get());
tableMetaData.getIndexes().remove(indexName);
- String renameIndexName = renameIndex.get().getIdentifier().getValue();
+ String renameIndexName = renameIndex.get().getIndexName().getIdentifier().getValue();
tableMetaData.getIndexes().put(renameIndexName, new IndexMetaData(renameIndexName));
SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabaseName(), schemaName);
event.getAlteredTables().add(tableMetaData);
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java
index 9085c4f6139..0ae3333d060 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java
@@ -43,7 +43,8 @@ public final class CreateIndexStatementSchemaRefresher implements MetaDataRefres
@Override
public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map<String, OptimizerPlannerContext> optimizerPlanners,
final Collection<String> logicDataSourceNames, final String schemaName, final CreateIndexStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
- String indexName = null != sqlStatement.getIndex() ? sqlStatement.getIndex().getIdentifier().getValue() : IndexMetaDataUtil.getGeneratedLogicIndexName(sqlStatement.getColumns());
+ String indexName = null != sqlStatement.getIndex() ? sqlStatement.getIndex().getIndexName().getIdentifier().getValue()
+ : IndexMetaDataUtil.getGeneratedLogicIndexName(sqlStatement.getColumns());
if (Strings.isNullOrEmpty(indexName)) {
return;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java
index 3b0862c972c..cd4647bb8fc 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java
@@ -66,7 +66,7 @@ public final class DropIndexStatementSchemaRefresher implements MetaDataRefreshe
}
private Collection<String> getIndexNames(final DropIndexStatement dropIndexStatement) {
- return dropIndexStatement.getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());
+ return dropIndexStatement.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList());
}
private void post(final String databaseName, final String schemaName, final TableMetaData tableMetaData) {
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDDLStatementSQLVisitor.java
index 07e0104e317..b3900122a29 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDDLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDDLStatementSQLVisitor.java
@@ -113,6 +113,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.al
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.DropIndexDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.routine.RoutineBodySegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.routine.ValidStatementSegment;
@@ -553,7 +554,8 @@ public final class MySQLDDLStatementSQLVisitor extends MySQLStatementSQLVisitor
public ASTNode visitCreateIndex(final CreateIndexContext ctx) {
MySQLCreateIndexStatement result = new MySQLCreateIndexStatement();
result.setTable((SimpleTableSegment) visit(ctx.tableName()));
- result.setIndex(new IndexSegment(ctx.indexName().start.getStartIndex(), ctx.indexName().stop.getStopIndex(), new IdentifierValue(ctx.indexName().getText())));
+ IndexNameSegment indexName = new IndexNameSegment(ctx.indexName().start.getStartIndex(), ctx.indexName().stop.getStopIndex(), new IdentifierValue(ctx.indexName().getText()));
+ result.setIndex(new IndexSegment(ctx.indexName().start.getStartIndex(), ctx.indexName().stop.getStopIndex(), indexName));
return result;
}
@@ -561,7 +563,8 @@ public final class MySQLDDLStatementSQLVisitor extends MySQLStatementSQLVisitor
public ASTNode visitDropIndex(final DropIndexContext ctx) {
MySQLDropIndexStatement result = new MySQLDropIndexStatement();
result.setTable((SimpleTableSegment) visit(ctx.tableName()));
- result.getIndexes().add(new IndexSegment(ctx.indexName().start.getStartIndex(), ctx.indexName().stop.getStopIndex(), new IdentifierValue(ctx.indexName().getText())));
+ IndexNameSegment indexName = new IndexNameSegment(ctx.indexName().start.getStartIndex(), ctx.indexName().stop.getStopIndex(), new IdentifierValue(ctx.indexName().getText()));
+ result.getIndexes().add(new IndexSegment(ctx.indexName().start.getStartIndex(), ctx.indexName().stop.getStopIndex(), indexName));
return result;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index a4883151745..226bbadeeca 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -137,6 +137,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.UnionType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
@@ -357,7 +358,8 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
@Override
public final ASTNode visitIndexName(final IndexNameContext ctx) {
- return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ IndexNameSegment indexName = new IndexNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexName);
}
@Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDDLStatementSQLVisitor.java
index 2cf68827f52..0a920783e33 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDDLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDDLStatementSQLVisitor.java
@@ -114,6 +114,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.al
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.RenameTableDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -490,7 +491,8 @@ public final class OpenGaussDDLStatementSQLVisitor extends OpenGaussStatementSQL
}
private IndexSegment createIndexSegment(final SimpleTableSegment tableSegment) {
- IndexSegment result = new IndexSegment(tableSegment.getStartIndex(), tableSegment.getStopIndex(), tableSegment.getTableName().getIdentifier());
+ IndexNameSegment indexName = new IndexNameSegment(tableSegment.getTableName().getStartIndex(), tableSegment.getTableName().getStopIndex(), tableSegment.getTableName().getIdentifier());
+ IndexSegment result = new IndexSegment(tableSegment.getStartIndex(), tableSegment.getStopIndex(), indexName);
tableSegment.getOwner().ifPresent(result::setOwner);
return result;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
index 0686519a34c..ae26de21478 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
@@ -107,6 +107,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.UnionType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
@@ -251,7 +252,8 @@ public abstract class OpenGaussStatementSQLVisitor extends OpenGaussStatementBas
@Override
public final ASTNode visitIndexName(final IndexNameContext ctx) {
- return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ IndexNameSegment indexName = new IndexNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexName);
}
@Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
index d897b331769..56d06adcf6a 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
@@ -70,6 +70,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndextypeSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.packages.PackageSegment;
@@ -249,7 +250,8 @@ public abstract class OracleStatementSQLVisitor extends OracleStatementBaseVisit
@Override
public final ASTNode visitIndexName(final IndexNameContext ctx) {
- return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.name()));
+ IndexNameSegment indexName = new IndexNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.name()));
+ return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexName);
}
@Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
index ceeb2b1ed60..1584c55f4a3 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
@@ -140,6 +140,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.al
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.RenameTableDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -582,7 +583,8 @@ public final class PostgreSQLDDLStatementSQLVisitor extends PostgreSQLStatementS
}
private IndexSegment createIndexSegment(final SimpleTableSegment tableSegment) {
- IndexSegment result = new IndexSegment(tableSegment.getStartIndex(), tableSegment.getStopIndex(), tableSegment.getTableName().getIdentifier());
+ IndexNameSegment indexName = new IndexNameSegment(tableSegment.getTableName().getStartIndex(), tableSegment.getTableName().getStopIndex(), tableSegment.getTableName().getIdentifier());
+ IndexSegment result = new IndexSegment(tableSegment.getStartIndex(), tableSegment.getStopIndex(), indexName);
tableSegment.getOwner().ifPresent(result::setOwner);
return result;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index 3883258319c..a674eb52c25 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -29,8 +29,10 @@ import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AExprContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AexprConstContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AliasClauseContext;
+import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AnyNameContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AscDescContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AttrNameContext;
+import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AttrsContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BExprContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CExprContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ColIdContext;
@@ -97,14 +99,13 @@ import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Va
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.WhereClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.WhereOrCurrentClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.WindowClauseContext;
-import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AnyNameContext;
-import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AttrsContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParserBaseVisitor;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.UnionType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
@@ -248,7 +249,8 @@ public abstract class PostgreSQLStatementSQLVisitor extends PostgreSQLStatementP
@Override
public final ASTNode visitIndexName(final IndexNameContext ctx) {
- return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ IndexNameSegment indexName = new IndexNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexName);
}
@Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
index 0f93238a80a..fdfacb9ae1d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
@@ -107,6 +107,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
@@ -312,7 +313,8 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
@Override
public final ASTNode visitIndexName(final IndexNameContext ctx) {
- return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ IndexNameSegment indexName = new IndexNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexName);
}
@Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexNameSegment.java
similarity index 72%
copy from shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
copy to shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexNameSegment.java
index 3789f0a4bbb..3dc9ddeeb39 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexNameSegment.java
@@ -19,32 +19,21 @@ package org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import lombok.Setter;
+import lombok.ToString;
import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerAvailable;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import java.util.Optional;
-
/**
- * Index segment.
+ * Index name segment.
*/
@RequiredArgsConstructor
@Getter
-@Setter
-public final class IndexSegment implements SQLSegment, OwnerAvailable {
+@ToString
+public final class IndexNameSegment implements SQLSegment {
private final int startIndex;
private final int stopIndex;
private final IdentifierValue identifier;
-
- private OwnerSegment owner;
-
- @Override
- public Optional<OwnerSegment> getOwner() {
- return Optional.ofNullable(owner);
- }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
index 3789f0a4bbb..63478c19f47 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
@@ -23,7 +23,6 @@ import lombok.Setter;
import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerAvailable;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import java.util.Optional;
@@ -39,7 +38,7 @@ public final class IndexSegment implements SQLSegment, OwnerAvailable {
private final int stopIndex;
- private final IdentifierValue identifier;
+ private final IndexNameSegment indexName;
private OwnerSegment owner;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/AlterIndexStatementHandlerTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/AlterIndexStatementHandlerTest.java
index b3f036ef69e..f9ab1d173dc 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/AlterIndexStatementHandlerTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/AlterIndexStatementHandlerTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -50,7 +51,7 @@ public final class AlterIndexStatementHandlerTest {
@Test
public void assertGetRenameIndexSegmentWithRenameIndexSegmentForPostgreSQL() {
PostgreSQLAlterIndexStatement alterIndexStatement = new PostgreSQLAlterIndexStatement();
- alterIndexStatement.setRenameIndex(new IndexSegment(0, 0, new IdentifierValue("")));
+ alterIndexStatement.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue(""))));
Optional<IndexSegment> indexSegment = AlterIndexStatementHandler.getRenameIndexSegment(alterIndexStatement);
assertTrue(indexSegment.isPresent());
}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/definition/ConstraintDefinitionAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/definition/ConstraintDefinitionAssert.java
index bce6a33c37b..9ce43cac850 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/definition/ConstraintDefinitionAssert.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/definition/ConstraintDefinitionAssert.java
@@ -64,7 +64,7 @@ public final class ConstraintDefinitionAssert {
}
if (null != expected.getIndexName()) {
assertTrue(assertContext.getText("Actual index name should exist."), actual.getIndexName().isPresent());
- assertThat(assertContext.getText("Actual index name assertion error."), actual.getIndexName().get().getIdentifier().getValue(), is(expected.getIndexName()));
+ assertThat(assertContext.getText("Actual index name assertion error."), actual.getIndexName().get().getIndexName().getIdentifier().getValue(), is(expected.getIndexName()));
} else {
assertFalse(assertContext.getText("Actual index name should not exist."), actual.getIndexName().isPresent());
}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java
index bc4d379c005..d10e7812179 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java
@@ -45,7 +45,7 @@ public final class IndexAssert {
*/
public static void assertIs(final SQLCaseAssertContext assertContext, final IndexSegment actual, final ExpectedIndex expected) {
assertNotNull(assertContext.getText("Index should exist."), expected);
- IdentifierValueAssert.assertIs(assertContext, actual.getIdentifier(), expected, "Index");
+ IdentifierValueAssert.assertIs(assertContext, actual.getIndexName().getIdentifier(), expected, "Index");
if (null != expected.getOwner()) {
assertTrue(assertContext.getText("Actual owner should exist."), actual.getOwner().isPresent());
OwnerAssert.assertIs(assertContext, actual.getOwner().get(), expected.getOwner());