This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 bf03c15 [DistSQL]Add `create database discovery type` statement to
support new API. (#14079)
bf03c15 is described below
commit bf03c153442918335a9662620f669e27c4f1cddd
Author: lanchengx <[email protected]>
AuthorDate: Wed Dec 15 14:30:08 2021 +0800
[DistSQL]Add `create database discovery type` statement to support new API.
(#14079)
* Add `create database discovery type` statement to support new API.
* Add `create database discovery type` statement to support new API.
* Remove method.
* Update MGRDatabaseDiscoveryTypeFixture.java
* Update CreateDatabaseDiscoveryTypeStatementAssert.java
* Update ExpectedDatabaseDiscoveryType.java
* Update CreateDatabaseDiscoveryTypeStatementTestCase.java
---
.../DatabaseDiscoveryRuleStatementConverter.java | 14 +++
...reateDatabaseDiscoveryTypeStatementUpdater.java | 103 +++++++++++++++++++++
...here.infra.distsql.update.RuleDefinitionUpdater | 1 +
.../fixture/MGRDatabaseDiscoveryTypeFixture.java | 58 ++++++++++++
...eDatabaseDiscoveryTypeStatementUpdaterTest.java | 96 +++++++++++++++++++
...ngsphere.dbdiscovery.spi.DatabaseDiscoveryType} | 6 +-
.../antlr4/imports/db-discovery/RDLStatement.g4 | 16 +++-
.../autogen/DatabaseDiscoveryDistSQLStatement.g4 | 1 +
.../DatabaseDiscoveryDistSQLStatementVisitor.java | 28 +++++-
...Type.java => DatabaseDiscoveryTypeSegment.java} | 4 +-
.../CreateDatabaseDiscoveryTypeStatement.java} | 16 ++--
.../rdl/create/CreateRuleStatementAssert.java | 5 +
...CreateDatabaseDiscoveryTypeStatementAssert.java | 63 +++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 5 +
.../distsql/rdl/ExpectedDatabaseDiscoveryType.java | 23 +++--
...eateDatabaseDiscoveryTypeStatementTestCase.java | 23 +++--
.../src/main/resources/case/rdl/create.xml | 15 ++-
.../main/resources/sql/supported/rdl/create.xml | 1 +
18 files changed, 436 insertions(+), 42 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverter.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDisco
[...]
index 943712e..85ab7c1 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverter.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverter.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHe
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.AbstractDatabaseDiscoverySegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryConstructionSegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryDefinitionSegment;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryTypeSegment;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import java.util.Collection;
@@ -79,4 +80,17 @@ public final class DatabaseDiscoveryRuleStatementConverter {
private static String getName(final String ruleName, final String type) {
return String.format("%s_%s", ruleName, type);
}
+
+ /**
+ * Convert database discovery type segment to database discovery type
configuration.
+ *
+ * @param typeSegment database discovery type segments
+ * @return database discovery type configuration
+ */
+ public static DatabaseDiscoveryRuleConfiguration
convertDiscoveryType(final Collection<DatabaseDiscoveryTypeSegment>
typeSegment) {
+ final DatabaseDiscoveryRuleConfiguration result = new
DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(),
new LinkedHashMap<>());
+ typeSegment.forEach(each ->
result.getDiscoveryTypes().put(each.getDiscoveryTypeName(),
+ new
ShardingSphereAlgorithmConfiguration(each.getAlgorithmSegment().getName(),
each.getAlgorithmSegment().getProps())));
+ return result;
+ }
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseD
[...]
new file mode 100644
index 0000000..a91486c
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
@@ -0,0 +1,103 @@
+/*
+ * 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.dbdiscovery.distsql.handler.update;
+
+import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseDiscoveryRuleStatementConverter;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryTypeSegment;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryTypeStatement;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+/**
+ * Create database discovery type statement updater.
+ */
+public final class CreateDatabaseDiscoveryTypeStatementUpdater implements
RuleDefinitionCreateUpdater<CreateDatabaseDiscoveryTypeStatement,
DatabaseDiscoveryRuleConfiguration> {
+
+ private static final String RULE_TYPE = "database discovery";
+
+ static {
+ // TODO consider about register once only
+ ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
+ }
+
+ @Override
+ public void checkSQLStatement(final ShardingSphereMetaData
shardingSphereMetaData, final CreateDatabaseDiscoveryTypeStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration
currentRuleConfig) throws DistSQLException {
+ String schemaName = shardingSphereMetaData.getName();
+ checkDuplicateDiscoveryType(schemaName, sqlStatement,
currentRuleConfig);
+ checkInvalidDiscoverType(sqlStatement);
+ }
+
+ private void checkDuplicateDiscoveryType(final String schemaName, final
CreateDatabaseDiscoveryTypeStatement sqlStatement,
+ final
DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
+ if (null == currentRuleConfig) {
+ return;
+ }
+ Collection<String> existRuleNames =
currentRuleConfig.getDiscoveryTypes().keySet();
+ Collection<String> duplicateRuleNames =
sqlStatement.getTypes().stream().map(DatabaseDiscoveryTypeSegment::getDiscoveryTypeName).filter(existRuleNames::contains).collect(Collectors.toSet());
+
duplicateRuleNames.addAll(getToBeCreatedDuplicateRuleNames(sqlStatement));
+ DistSQLException.predictionThrow(duplicateRuleNames.isEmpty(), new
DuplicateRuleException(RULE_TYPE, schemaName, duplicateRuleNames));
+ }
+
+ private Collection<String> getToBeCreatedDuplicateRuleNames(final
CreateDatabaseDiscoveryTypeStatement sqlStatement) {
+ return
sqlStatement.getTypes().stream().collect(Collectors.toMap(DatabaseDiscoveryTypeSegment::getDiscoveryTypeName,
e -> 1, Integer::sum))
+ .entrySet().stream().filter(entry -> entry.getValue() >
1).map(Entry::getKey).collect(Collectors.toSet());
+ }
+
+ private void checkInvalidDiscoverType(final
CreateDatabaseDiscoveryTypeStatement sqlStatement) throws DistSQLException {
+ List<String> invalidType = sqlStatement.getTypes().stream().map(each
-> each.getAlgorithmSegment().getName()).distinct()
+ .filter(each ->
!TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryType.class, each, new
Properties()).isPresent()).collect(Collectors.toList());
+ DistSQLException.predictionThrow(invalidType.isEmpty(), new
InvalidAlgorithmConfigurationException(RULE_TYPE, invalidType));
+ }
+
+ @Override
+ public RuleConfiguration buildToBeCreatedRuleConfiguration(final
CreateDatabaseDiscoveryTypeStatement sqlStatement) {
+ return
DatabaseDiscoveryRuleStatementConverter.convertDiscoveryType(sqlStatement.getTypes());
+ }
+
+ @Override
+ public void updateCurrentRuleConfiguration(final
DatabaseDiscoveryRuleConfiguration currentRuleConfig, final
DatabaseDiscoveryRuleConfiguration toBeCreatedRuleConfig) {
+ if (null != currentRuleConfig) {
+
currentRuleConfig.getDiscoveryTypes().putAll(toBeCreatedRuleConfig.getDiscoveryTypes());
+ }
+ }
+
+ @Override
+ public Class<DatabaseDiscoveryRuleConfiguration>
getRuleConfigurationClass() {
+ return DatabaseDiscoveryRuleConfiguration.class;
+ }
+
+ @Override
+ public String getType() {
+ return CreateDatabaseDiscoveryTypeStatement.class.getCanonicalName();
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
index 0354bc1..e07aa92 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
@@ -18,3 +18,4 @@
org.apache.shardingsphere.dbdiscovery.distsql.handler.update.CreateDatabaseDiscoveryRuleStatementUpdater
org.apache.shardingsphere.dbdiscovery.distsql.handler.update.AlterDatabaseDiscoveryRuleStatementUpdater
org.apache.shardingsphere.dbdiscovery.distsql.handler.update.DropDatabaseDiscoveryRuleStatementUpdater
+org.apache.shardingsphere.dbdiscovery.distsql.handler.update.CreateDatabaseDiscoveryTypeStatementUpdater
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/MGRDatabaseDiscoveryTypeFixture.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/MGRDatabaseDiscoveryTypeF
[...]
new file mode 100644
index 0000000..782b95c
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/MGRDatabaseDiscoveryTypeFixture.java
@@ -0,0 +1,58 @@
+/*
+ * 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.dbdiscovery.distsql.handler.fixture;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * MGR database discovery type fixture.
+ */
+@Slf4j
+public final class MGRDatabaseDiscoveryTypeFixture implements
DatabaseDiscoveryType {
+
+ @Override
+ public String getType() {
+ return "mgr";
+ }
+
+ @Override
+ public void checkDatabaseDiscoveryConfiguration(final String schemaName,
final Map<String, DataSource> dataSourceMap) throws SQLException {
+
+ }
+
+ @Override
+ public void updatePrimaryDataSource(final String schemaName, final
Map<String, DataSource> dataSourceMap, final Collection<String>
disabledDataSourceNames, final String groupName) {
+
+ }
+
+ @Override
+ public void updateMemberState(final String schemaName, final Map<String,
DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames) {
+
+ }
+
+ @Override
+ public String getPrimaryDataSource() {
+ return null;
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdaterTest.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatab
[...]
new file mode 100644
index 0000000..d75360c
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdaterTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.dbdiscovery.distsql.handler.update;
+
+import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryTypeSegment;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryTypeStatement;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class CreateDatabaseDiscoveryTypeStatementUpdaterTest {
+
+ static {
+ ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
+ }
+
+ @Mock
+ private ShardingSphereMetaData shardingSphereMetaData;
+
+ private final CreateDatabaseDiscoveryTypeStatementUpdater updater = new
CreateDatabaseDiscoveryTypeStatementUpdater();
+
+ @Test(expected = DuplicateRuleException.class)
+ public void assertCheckSQLStatementWithDuplicate() throws DistSQLException
{
+ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig =
new DatabaseDiscoveryDataSourceRuleConfiguration("pr_ds",
Collections.emptyList(), "ha-heartbeat", "test");
+ List<DatabaseDiscoveryTypeSegment> databaseDiscoveryTypeSegments =
Arrays.asList(
+ new DatabaseDiscoveryTypeSegment("discovery_type", new
AlgorithmSegment("mgr", new Properties())),
+ new DatabaseDiscoveryTypeSegment("discovery_type", new
AlgorithmSegment("mgr", new Properties())));
+ updater.checkSQLStatement(shardingSphereMetaData, new
CreateDatabaseDiscoveryTypeStatement(databaseDiscoveryTypeSegments),
+ new
DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig),
Collections.emptyMap(), Collections.emptyMap()));
+ }
+
+ @Test(expected = DuplicateRuleException.class)
+ public void assertCheckSQLStatementWithExist() throws DistSQLException {
+ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig =
new DatabaseDiscoveryDataSourceRuleConfiguration("pr_ds",
Collections.emptyList(), "ha-heartbeat", "test");
+ List<DatabaseDiscoveryTypeSegment> databaseDiscoveryTypeSegments =
Collections.singletonList(new DatabaseDiscoveryTypeSegment("discovery_type",
new AlgorithmSegment("mgr", new Properties())));
+ updater.checkSQLStatement(shardingSphereMetaData, new
CreateDatabaseDiscoveryTypeStatement(databaseDiscoveryTypeSegments),
+ new
DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig),
Collections.emptyMap(),
+ Collections.singletonMap("discovery_type", new
ShardingSphereAlgorithmConfiguration("mgr", new Properties()))));
+ }
+
+ @Test(expected = InvalidAlgorithmConfigurationException.class)
+ public void assertCheckSQLStatementWithDatabaseDiscoveryType() throws
DistSQLException {
+ Set<DatabaseDiscoveryTypeSegment> discoveryTypeSegments =
Collections.singleton(new DatabaseDiscoveryTypeSegment("discovery_type", new
AlgorithmSegment("INVALID_TYPE", new Properties())));
+ updater.checkSQLStatement(shardingSphereMetaData, new
CreateDatabaseDiscoveryTypeStatement(discoveryTypeSegments), null);
+ }
+
+ @Test
+ public void assertBuildAndUpdate() throws DistSQLException {
+ Set<DatabaseDiscoveryTypeSegment> discoveryTypeSegments =
Collections.singleton(new DatabaseDiscoveryTypeSegment("discovery_type", new
AlgorithmSegment("MGR", new Properties())));
+ updater.checkSQLStatement(shardingSphereMetaData, new
CreateDatabaseDiscoveryTypeStatement(discoveryTypeSegments), null);
+ DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfiguration
+ = (DatabaseDiscoveryRuleConfiguration)
updater.buildToBeCreatedRuleConfiguration(new
CreateDatabaseDiscoveryTypeStatement(discoveryTypeSegments));
+ DatabaseDiscoveryRuleConfiguration currentConfiguration = new
DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(),
new LinkedHashMap<>());
+ updater.updateCurrentRuleConfiguration(currentConfiguration,
databaseDiscoveryRuleConfiguration);
+ assertThat(currentConfiguration.getDiscoveryTypes().size(), is(1));
+
assertThat(currentConfiguration.getDiscoveryTypes().get("discovery_type").getType(),
is("MGR"));
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType
similarity index 71%
copy from
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
copy to
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType
index 0354bc1..b43c9e0 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType
@@ -5,7 +5,7 @@
# 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
@@ -15,6 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.dbdiscovery.distsql.handler.update.CreateDatabaseDiscoveryRuleStatementUpdater
-org.apache.shardingsphere.dbdiscovery.distsql.handler.update.AlterDatabaseDiscoveryRuleStatementUpdater
-org.apache.shardingsphere.dbdiscovery.distsql.handler.update.DropDatabaseDiscoveryRuleStatementUpdater
+org.apache.shardingsphere.dbdiscovery.distsql.handler.fixture.MGRDatabaseDiscoveryTypeFixture
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
index 2d46fbf..3cb4151 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
@@ -31,18 +31,26 @@ dropDatabaseDiscoveryRule
: DROP DB_DISCOVERY RULE ruleName (COMMA ruleName)*
;
+createDatabaseDiscoveryType
+ : CREATE DB_DISCOVERY TYPE databaseDiscoveryTypeDefinition (COMMA
databaseDiscoveryTypeDefinition)*
+ ;
+
databaseDiscoveryRule
: (databaseDiscoveryRuleDefinition | databaseDiscoveryRuleConstruction)
;
databaseDiscoveryRuleDefinition
- : ruleName LP resources COMMA discoveryType COMMA discoveryHeartbeat RP
+ : ruleName LP resources COMMA typeDefinition COMMA discoveryHeartbeat RP
;
databaseDiscoveryRuleConstruction
: ruleName LP resources COMMA TYPE EQ discoveryTypeName COMMA HEARTBEAT EQ
discoveryHeartbeatName RP
;
+databaseDiscoveryTypeDefinition
+ : discoveryTypeName LP typeDefinition RP
+ ;
+
ruleName
: IDENTIFIER
;
@@ -55,15 +63,15 @@ resourceName
: IDENTIFIER
;
-discoveryType
- : TYPE LP NAME EQ type (COMMA PROPERTIES LP typeProperties RP)? RP
+typeDefinition
+ : TYPE LP NAME EQ typeName (COMMA PROPERTIES LP typeProperties RP)? RP
;
discoveryHeartbeat
: HEARTBEAT LP PROPERTIES LP typeProperties RP RP
;
-type
+typeName
: IDENTIFIER
;
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryDistSQLStatement.g4
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryDistSQLStatement.g4
index e5c7612..5902702 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryDistSQLStatement.g4
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryDistSQLStatement.g4
@@ -24,5 +24,6 @@ execute
| alterDatabaseDiscoveryRule
| dropDatabaseDiscoveryRule
| showDatabaseDiscoveryRules
+ | createDatabaseDiscoveryType
) SEMI?
;
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLSt
[...]
index cbbaa44..ee90fe6 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
@@ -21,21 +21,25 @@ import org.antlr.v4.runtime.tree.ParseTree;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.AbstractDatabaseDiscoverySegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryConstructionSegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryDefinitionSegment;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryTypeSegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryTypeStatement;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementBaseVisitor;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.AlterDatabaseDiscoveryRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.CreateDatabaseDiscoveryRuleContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.CreateDatabaseDiscoveryTypeContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryRuleConstructionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryRuleDefinitionContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DiscoveryTypeContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryTypeDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ResourcesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.SchemaNameContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryRulesContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.TypeDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.TypePropertiesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.TypePropertyContext;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
@@ -44,6 +48,8 @@ import
org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import java.util.Collection;
+import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -81,7 +87,7 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor
extends DatabaseDisc
@Override
public ASTNode visitDatabaseDiscoveryRuleDefinition(final
DatabaseDiscoveryRuleDefinitionContext ctx) {
return new
DatabaseDiscoveryDefinitionSegment(getIdentifierValue(ctx.ruleName()),
buildResources(ctx.resources()),
- (AlgorithmSegment) visit(ctx.discoveryType()),
getProperties(ctx.discoveryHeartbeat().typeProperties()));
+ (AlgorithmSegment) visit(ctx.typeDefinition()),
getProperties(ctx.discoveryHeartbeat().typeProperties()));
}
@@ -99,6 +105,20 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor
extends DatabaseDisc
return new ShowDatabaseDiscoveryRulesStatement(null ==
ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName()));
}
+ @Override
+ public ASTNode visitCreateDatabaseDiscoveryType(final
CreateDatabaseDiscoveryTypeContext ctx) {
+ return new
CreateDatabaseDiscoveryTypeStatement(buildAlgorithmEntry(ctx.databaseDiscoveryTypeDefinition()));
+ }
+
+ private Collection<DatabaseDiscoveryTypeSegment> buildAlgorithmEntry(final
List<DatabaseDiscoveryTypeDefinitionContext> ctx) {
+ return ctx.stream().map(each -> (DatabaseDiscoveryTypeSegment)
visit(each)).collect(Collectors.toCollection(LinkedList::new));
+ }
+
+ @Override
+ public ASTNode visitDatabaseDiscoveryTypeDefinition(final
DatabaseDiscoveryTypeDefinitionContext ctx) {
+ return new
DatabaseDiscoveryTypeSegment(getIdentifierValue(ctx.discoveryTypeName()),
(AlgorithmSegment) visit(ctx.typeDefinition()));
+ }
+
private String getIdentifierValue(final ParseTree context) {
if (null == context) {
return null;
@@ -112,8 +132,8 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor
extends DatabaseDisc
}
@Override
- public ASTNode visitDiscoveryType(final DiscoveryTypeContext ctx) {
- return new AlgorithmSegment(getIdentifierValue(ctx.type()), null ==
ctx.typeProperties() ? new Properties() : getProperties(ctx.typeProperties()));
+ public ASTNode visitTypeDefinition(final TypeDefinitionContext ctx) {
+ return new AlgorithmSegment(getIdentifierValue(ctx.typeName()), null
== ctx.typeProperties() ? new Properties() :
getProperties(ctx.typeProperties()));
}
private Properties getProperties(final TypePropertiesContext ctx) {
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryTypeSegment.java
similarity index 91%
copy from
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
copy to
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryTypeSegment.java
index 01b7806..58c9f22 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryTypeSegment.java
@@ -27,9 +27,9 @@ import
org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
*/
@RequiredArgsConstructor
@Getter
-public final class DatabaseDiscoveryType implements ASTNode {
+public final class DatabaseDiscoveryTypeSegment implements ASTNode {
- private final String name;
+ private final String discoveryTypeName;
private final AlgorithmSegment algorithmSegment;
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CreateDatabaseDiscoveryTypeStat
[...]
similarity index 65%
copy from
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
copy to
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CreateDatabaseDiscoveryTypeStatement.java
index 01b7806..4ff9680 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CreateDatabaseDiscoveryTypeStatement.java
@@ -15,21 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.dbdiscovery.distsql.parser.segment;
+package org.apache.shardingsphere.dbdiscovery.distsql.parser.statement;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryTypeSegment;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateRuleStatement;
+
+import java.util.Collection;
/**
- * Database discovery type.
+ * Create database discovery type statement.
*/
@RequiredArgsConstructor
@Getter
-public final class DatabaseDiscoveryType implements ASTNode {
-
- private final String name;
+public final class CreateDatabaseDiscoveryTypeStatement extends
CreateRuleStatement {
- private final AlgorithmSegment algorithmSegment;
+ private final Collection<DatabaseDiscoveryTypeSegment> types;
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
index 58b3e86..30da112 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/CreateRuleStatementAssert.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statemen
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryTypeStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateDefaultSingleTableRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateRuleStatement;
import
org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
@@ -35,6 +36,7 @@ import
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardin
import
org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateDatabaseDiscoveryRuleStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateDatabaseDiscoveryTypeStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateDefaultShadowAlgorithmStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateDefaultShardingStrategyStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateDefaultSingleTableRuleStatementAssert;
@@ -48,6 +50,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateShardingKeyGeneratorStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl.CreateShardingTableRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDatabaseDiscoveryTypeStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDefaultShadowAlgorithmStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDefaultShardingStrategyStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDefaultSingleTableRuleStatementTestCase;
@@ -76,6 +79,8 @@ public final class CreateRuleStatementAssert {
public static void assertIs(final SQLCaseAssertContext assertContext,
final CreateRuleStatement actual, final SQLParserTestCase expected) {
if (actual instanceof CreateDatabaseDiscoveryRuleStatement) {
CreateDatabaseDiscoveryRuleStatementAssert.assertIs(assertContext,
(CreateDatabaseDiscoveryRuleStatement) actual, expected);
+ } else if (actual instanceof CreateDatabaseDiscoveryTypeStatement) {
+ CreateDatabaseDiscoveryTypeStatementAssert.assertIs(assertContext,
(CreateDatabaseDiscoveryTypeStatement) actual,
(CreateDatabaseDiscoveryTypeStatementTestCase) expected);
} else if (actual instanceof CreateEncryptRuleStatement) {
CreateEncryptRuleStatementAssert.assertIs(assertContext,
(CreateEncryptRuleStatement) actual, (CreateEncryptRuleStatementTestCase)
expected);
} else if (actual instanceof CreateReadwriteSplittingRuleStatement) {
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/impl/CreateDatabaseDiscoveryTypeStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/impl/CreateDatabaseDiscoveryTypeStatementAssert.java
new file mode 100644
index 0000000..1480de6
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/create/impl/CreateDatabaseDiscoveryTypeStatementAssert.java
@@ -0,0 +1,63 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.statement.distsql.rdl.create.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryTypeSegment;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryTypeStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.distsql.AlgorithmAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDatabaseDiscoveryTypeStatementTestCase;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Create database discovery type statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class CreateDatabaseDiscoveryTypeStatementAssert {
+
+ /**
+ * Assert create database discovery type statement is correct with
expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual create database discovery type statement
+ * @param expected expected create database discovery type statement test
case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final CreateDatabaseDiscoveryTypeStatement actual, final
CreateDatabaseDiscoveryTypeStatementTestCase expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should not
exist."), actual);
+ } else {
+ assertNotNull(assertContext.getText("Actual statement should
exist."), actual);
+ Map<String, DatabaseDiscoveryTypeSegment> actualMap =
actual.getTypes().stream().collect(Collectors.toMap(DatabaseDiscoveryTypeSegment::getDiscoveryTypeName,
each -> each));
+ expected.getTypes().forEach(each -> {
+ DatabaseDiscoveryTypeSegment actualSegment =
actualMap.get(each.getDiscoveryTypeName());
+ assertNotNull(actualSegment);
+ assertThat(actualSegment.getDiscoveryTypeName(),
is(each.getDiscoveryTypeName()));
+ AlgorithmAssert.assertIs(assertContext,
actualSegment.getAlgorithmSegment(), each.getAlgorithmSegment());
+ });
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index 1dabf5d..6b55854 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -170,6 +170,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.AddResourceStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDatabaseDiscoveryConstructionRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDatabaseDiscoveryDefinitionRuleStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDatabaseDiscoveryTypeStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDefaultShadowAlgorithmStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDefaultShardingStrategyStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDefaultSingleTableRuleStatementTestCase;
@@ -556,6 +557,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "create-database-discovery-construction-rule")
private final
List<CreateDatabaseDiscoveryConstructionRuleStatementTestCase>
createDataBaseDiscoveryConstructionRuleTestCase = new LinkedList<>();
+ @XmlElement(name = "create-database-discovery-type")
+ private final List<CreateDatabaseDiscoveryTypeStatementTestCase>
createDatabaseDiscoveryTypeTestCases = new LinkedList<>();
+
@XmlElement(name = "create-encrypt-rule")
private final List<CreateEncryptRuleStatementTestCase>
createEncryptRuleTestCase = new LinkedList<>();
@@ -953,6 +957,7 @@ public final class SQLParserTestCases {
putAll(alterShardingTableRuleTestCase, result);
putAll(createDatabaseDiscoveryDefinitionRuleTestCases, result);
putAll(createDataBaseDiscoveryConstructionRuleTestCase, result);
+ putAll(createDatabaseDiscoveryTypeTestCases, result);
putAll(createEncryptRuleTestCase, result);
putAll(createReadwriteSplittingRuleTestCase, result);
putAll(createShardingBindingTableRulesTestCase, result);
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/rdl/ExpectedDatabaseDiscoveryType.java
similarity index 52%
copy from
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
copy to
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/rdl/ExpectedDatabaseDiscoveryType.java
index 01b7806..f7d03ce 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/rdl/ExpectedDatabaseDiscoveryType.java
@@ -15,21 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.dbdiscovery.distsql.parser.segment;
+package
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.rdl;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.AbstractExpectedIdentifierSQLSegment;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.ExpectedAlgorithm;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
/**
- * Database discovery type.
+ * Expected database discovery type.
*/
-@RequiredArgsConstructor
@Getter
-public final class DatabaseDiscoveryType implements ASTNode {
+@Setter
+public final class ExpectedDatabaseDiscoveryType extends
AbstractExpectedIdentifierSQLSegment {
- private final String name;
+ @XmlAttribute(name = "discovery-type-name")
+ private String discoveryTypeName;
- private final AlgorithmSegment algorithmSegment;
+ @XmlElement(name = "algorithm")
+ private ExpectedAlgorithm algorithmSegment;
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/create/CreateDatabaseDiscoveryTypeStatementTestCase.java
similarity index 53%
rename from
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
rename to
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/create/CreateDatabaseDiscoveryTypeStatementTestCase.java
index 01b7806..e3e7648 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryType.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/create/CreateDatabaseDiscoveryTypeStatementTestCase.java
@@ -15,21 +15,24 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.dbdiscovery.distsql.parser.segment;
+package
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.rdl.ExpectedDatabaseDiscoveryType;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
/**
- * Database discovery type.
+ * Create database discovery type statement test case.
*/
-@RequiredArgsConstructor
@Getter
-public final class DatabaseDiscoveryType implements ASTNode {
-
- private final String name;
+@Setter
+public final class CreateDatabaseDiscoveryTypeStatementTestCase extends
SQLParserTestCase {
- private final AlgorithmSegment algorithmSegment;
+ @XmlElement(name = "type")
+ private final List<ExpectedDatabaseDiscoveryType> types = new
LinkedList<>();
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
index c28cc2f..98fca92 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml
@@ -210,7 +210,20 @@
<data-source>resource1</data-source>
</rule>
</create-database-discovery-construction-rule>
-
+
+ <create-database-discovery-type
sql-case-id="create-database-discovery-type">
+ <type discovery-type-name="primary_replica_ds_mgr">
+ <algorithm algorithm-name="mgr">
+ <properties>
+ <property key="groupName" value="92504d5b-6dec"/>
+ </properties>
+ </algorithm>
+ </type>
+ <type discovery-type-name="primary_replica_ds_mgr_2">
+ <algorithm algorithm-name="mgr"/>
+ </type>
+ </create-database-discovery-type>
+
<create-database-discovery-definition-rule
sql-case-id="create-database-discovery-rule-with-quota">
<rule rule-name="ha_group_0" type="mgr">
<data-source>resource0</data-source>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
index 002b9db..a95ebad 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml
@@ -34,6 +34,7 @@
<distsql-case id="create-dynamic-readwrite-splitting-rule" value="CREATE
READWRITE_SPLITTING RULE ms_group_1(AUTO_AWARE_RESOURCE=group_0,
TYPE(NAME=random,PROPERTIES(read_weight='2:1')))" />
<distsql-case id="create-database-discovery-definition-rule" value="CREATE
DB_DISCOVERY RULE ha_group_0 (RESOURCES(resource0,resource1),
TYPE(NAME=mgr,PROPERTIES(groupName='92504d5b-6dec')),HEARTBEAT(PROPERTIES('keepAliveCron'='0/5
* * * * ?'))), ha_group_1 (RESOURCES(resource2,resource3),
TYPE(NAME=mgr2,PROPERTIES(groupName='92504d5b-6dec-2')),HEARTBEAT(PROPERTIES('keepAliveCron'='0/6
* * * * ?')))" />
<distsql-case id="create-database-discovery-construction-rule"
value="CREATE DB_DISCOVERY RULE ha_group_0 (RESOURCES(resource0,resource1),
TYPE=ha_group_0_mgr,HEARTBEAT=ha_group_0_heartbeat)" />
+ <distsql-case id="create-database-discovery-type" value="CREATE
DB_DISCOVERY TYPE
primary_replica_ds_mgr(TYPE(NAME=mgr,PROPERTIES('groupName'='92504d5b-6dec'))),primary_replica_ds_mgr_2(TYPE(NAME=mgr))"
/>
<distsql-case id="create-encrypt-rule" value="CREATE ENCRYPT RULE
t_encrypt (RESOURCE=ds_1,
COLUMNS((NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))),
(NAME=order_id, CIPHER =order_cipher,TYPE(NAME=MD5))))" />
<distsql-case id="create-encrypt-rule-with-assisted-query-column"
value="CREATE ENCRYPT RULE t_encrypt (RESOURCE=ds_1,
COLUMNS((NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ASSISTED_QUERY_COLUMN=assisted_column,
TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))), (NAME=order_id,
CIPHER =order_cipher,TYPE(NAME=MD5))))" />
<distsql-case id="create-shadow-rule" value="CREATE SHADOW RULE
shadow_rule(SOURCE=demo_ds,SHADOW=demo_ds_shadow,t_order((TYPE(NAME=COLUMN_REGEX_MATCH,PROPERTIES('operation'='insert','column'='user_id','regex'='[1]'))),(simple_note_algorithm,TYPE(NAME=SIMPLE_NOTE,PROPERTIES('shadow'='true',foo='bar')))))"
/>