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 87d1abe [DistSQL] Add `show db_discovery types/heartbeats` statement
to support new API (#14082)
87d1abe is described below
commit 87d1abea1e3618254f9892b9c5047dacfbb882f0
Author: lanchengx <[email protected]>
AuthorDate: Wed Dec 15 15:46:04 2021 +0800
[DistSQL] Add `show db_discovery types/heartbeats` statement to support new
API (#14082)
* Add `show db_discovery types/heartbeats` statement.
* Update RQLStatement.g4
---
.../DatabaseDiscoveryHeartbeatQueryResultSet.java | 68 +++++++++++++++++++++
.../query/DatabaseDiscoveryTypeQueryResultSet.java | 68 +++++++++++++++++++++
...dingsphere.infra.distsql.query.DistSQLResultSet | 2 +
...tabaseDiscoveryHeartbeatQueryResultSetTest.java | 70 +++++++++++++++++++++
.../DatabaseDiscoveryTypeQueryResultSetTest.java | 71 ++++++++++++++++++++++
.../main/antlr4/imports/db-discovery/Keyword.g4 | 8 +++
.../antlr4/imports/db-discovery/RQLStatement.g4 | 10 ++-
.../autogen/DatabaseDiscoveryDistSQLStatement.g4 | 2 +
.../DatabaseDiscoveryDistSQLStatementVisitor.java | 14 +++++
.../ShowDatabaseDiscoveryHeartbeatsStatement.java} | 69 ++++-----------------
.../ShowDatabaseDiscoveryTypesStatement.java} | 21 ++++---
.../distsql/rql/impl/ShowRulesStatementAssert.java | 6 +-
.../ShowDatabaseDiscoveryRulesStatementAssert.java | 4 +-
.../src/main/resources/case/rql/show.xml | 8 +++
.../src/main/resources/sql/supported/rql/show.xml | 2 +
15 files changed, 352 insertions(+), 71 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/query/DatabaseDiscoveryHeartbeatQueryResultSet.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/query/DatabaseDiscoveryHea
[...]
new file mode 100644
index 0000000..54923ee
--- /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/query/DatabaseDiscoveryHeartbeatQueryResultSet.java
@@ -0,0 +1,68 @@
+/*
+ * 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.query;
+
+import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryHeartbeatsStatement;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+/**
+ * Result set for show database discovery heartbeat.
+ */
+public final class DatabaseDiscoveryHeartbeatQueryResultSet implements
DistSQLResultSet {
+
+ private Iterator<Entry<String, DatabaseDiscoveryHeartBeatConfiguration>>
data = Collections.emptyIterator();
+
+ @Override
+ public void init(final ShardingSphereMetaData metaData, final SQLStatement
sqlStatement) {
+ Collection<DatabaseDiscoveryRuleConfiguration> ruleConfiguration =
metaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class);
+ data =
ruleConfiguration.stream().map(DatabaseDiscoveryRuleConfiguration::getDiscoveryHeartbeats)
+ .flatMap(each ->
each.entrySet().stream()).collect(Collectors.toMap(Entry::getKey,
Entry::getValue)).entrySet().iterator();
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList("name", "props");
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ Entry<String, DatabaseDiscoveryHeartBeatConfiguration> entry =
data.next();
+ return Arrays.asList(entry.getKey(), entry.getValue().getProps());
+ }
+
+ @Override
+ public String getType() {
+ return
ShowDatabaseDiscoveryHeartbeatsStatement.class.getCanonicalName();
+ }
+}
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/query/DatabaseDiscoveryTypeQueryResultSet.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/query/DatabaseDiscoveryTypeQuer
[...]
new file mode 100644
index 0000000..e189b59
--- /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/query/DatabaseDiscoveryTypeQueryResultSet.java
@@ -0,0 +1,68 @@
+/*
+ * 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.query;
+
+import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
+import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+/**
+ * Result set for show database discovery type.
+ */
+public final class DatabaseDiscoveryTypeQueryResultSet implements
DistSQLResultSet {
+
+ private Iterator<Entry<String, ShardingSphereAlgorithmConfiguration>> data
= Collections.emptyIterator();
+
+ @Override
+ public void init(final ShardingSphereMetaData metaData, final SQLStatement
sqlStatement) {
+ Collection<DatabaseDiscoveryRuleConfiguration> ruleConfiguration =
metaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class);
+ data =
ruleConfiguration.stream().map(DatabaseDiscoveryRuleConfiguration::getDiscoveryTypes)
+ .flatMap(each ->
each.entrySet().stream()).collect(Collectors.toMap(Entry::getKey,
Entry::getValue)).entrySet().iterator();
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList("name", "type", "props");
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ Entry<String, ShardingSphereAlgorithmConfiguration> entry =
data.next();
+ return Arrays.asList(entry.getKey(), entry.getValue().getType(),
entry.getValue().getProps());
+ }
+
+ @Override
+ public String getType() {
+ return ShowDatabaseDiscoveryTypesStatement.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.query.DistSQLResultSet
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.query.DistSQLResultSet
index 09b4426..7c2f746 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.query.DistSQLResultSet
+++
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.query.DistSQLResultSet
@@ -16,3 +16,5 @@
#
org.apache.shardingsphere.dbdiscovery.distsql.handler.query.DatabaseDiscoveryRuleQueryResultSet
+org.apache.shardingsphere.dbdiscovery.distsql.handler.query.DatabaseDiscoveryTypeQueryResultSet
+org.apache.shardingsphere.dbdiscovery.distsql.handler.query.DatabaseDiscoveryHeartbeatQueryResultSet
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/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.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/query/DatabaseDiscover
[...]
new file mode 100644
index 0000000..b64316f
--- /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/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.query;
+
+import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class DatabaseDiscoveryHeartbeatQueryResultSetTest {
+
+ @Test
+ public void assertGetRowData() {
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class,
RETURNS_DEEP_STUBS);
+
when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration()));
+ DistSQLResultSet resultSet = new
DatabaseDiscoveryHeartbeatQueryResultSet();
+ resultSet.init(metaData,
mock(ShowDatabaseDiscoveryRulesStatement.class));
+ Collection<String> columnNames = resultSet.getColumnNames();
+ ArrayList<Object> actual = new ArrayList<>(resultSet.getRowData());
+ assertThat(columnNames.size(), is(2));
+ assertThat(actual.size(), is(2));
+ assertThat(actual.get(0), is("test_name"));
+ assertThat(actual.get(1).toString(), is("{type_key=type_value}"));
+ }
+
+ private RuleConfiguration createRuleConfiguration() {
+ DatabaseDiscoveryDataSourceRuleConfiguration
databaseDiscoveryDataSourceRuleConfig = new
DatabaseDiscoveryDataSourceRuleConfiguration("ms_group", Arrays.asList("ds_0",
"ds_1"),
+ "ms-heartbeat", "test");
+ Properties discoveryTypeProps = new Properties();
+ discoveryTypeProps.put("type_key", "type_value");
+ DatabaseDiscoveryHeartBeatConfiguration shardingSphereAlgorithmConfig
= new DatabaseDiscoveryHeartBeatConfiguration(discoveryTypeProps);
+ Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoverHeartbeat
= new HashMap<>(1, 1);
+ discoverHeartbeat.put("test_name", shardingSphereAlgorithmConfig);
+ return new
DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfig),
discoverHeartbeat, Collections.emptyMap());
+ }
+}
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/query/DatabaseDiscoveryTypeQueryResultSetTest.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/query/DatabaseDiscoveryType
[...]
new file mode 100644
index 0000000..d1e9983
--- /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/query/DatabaseDiscoveryTypeQueryResultSetTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.query;
+
+import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class DatabaseDiscoveryTypeQueryResultSetTest {
+
+ @Test
+ public void assertGetRowData() {
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class,
RETURNS_DEEP_STUBS);
+
when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration()));
+ DistSQLResultSet resultSet = new DatabaseDiscoveryTypeQueryResultSet();
+ resultSet.init(metaData,
mock(ShowDatabaseDiscoveryRulesStatement.class));
+ Collection<String> columnNames = resultSet.getColumnNames();
+ ArrayList<Object> actual = new ArrayList<>(resultSet.getRowData());
+ assertThat(columnNames.size(), is(3));
+ assertThat(actual.size(), is(3));
+ assertThat(actual.get(0), is("test_name"));
+ assertThat(actual.get(1), is("MGR"));
+ assertThat(actual.get(2).toString(), is("{type_key=type_value}"));
+ }
+
+ private RuleConfiguration createRuleConfiguration() {
+ DatabaseDiscoveryDataSourceRuleConfiguration
databaseDiscoveryDataSourceRuleConfig = new
DatabaseDiscoveryDataSourceRuleConfiguration("ms_group", Arrays.asList("ds_0",
"ds_1"),
+ "ms-heartbeat", "test");
+ Properties discoveryTypeProps = new Properties();
+ discoveryTypeProps.put("type_key", "type_value");
+ ShardingSphereAlgorithmConfiguration shardingSphereAlgorithmConfig =
new ShardingSphereAlgorithmConfiguration("MGR", discoveryTypeProps);
+ Map<String, ShardingSphereAlgorithmConfiguration> discoverTypes = new
HashMap<>(1, 1);
+ discoverTypes.put("test_name", shardingSphereAlgorithmConfig);
+ return new
DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfig),
Collections.emptyMap(), discoverTypes);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/Keyword.g4
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/Keyword.g4
index 5459bab..0038741 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/Keyword.g4
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/Keyword.g4
@@ -67,6 +67,14 @@ RULES
: R U L E S
;
+TYPES
+ : T Y P E S
+ ;
+
+HEARTBEATS
+ : H E A R T B E A T S
+ ;
+
DB_DISCOVERY
: D B UL_ D I S C O V E R Y
;
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
index b87b860..1cc717c 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
@@ -22,7 +22,15 @@ import Keyword, Literals, Symbol;
showDatabaseDiscoveryRules
: SHOW DB_DISCOVERY RULES (FROM schemaName)?
;
-
+
+showDatabaseDiscoveryTypes
+ : SHOW DB_DISCOVERY TYPES (FROM schemaName)?
+ ;
+
+showDatabaseDiscoveryHeartbeats
+ : SHOW DB_DISCOVERY HEARTBEATS (FROM schemaName)?
+ ;
+
schemaName
: 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 5902702..17f8397 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
@@ -23,6 +23,8 @@ execute
: (createDatabaseDiscoveryRule
| alterDatabaseDiscoveryRule
| dropDatabaseDiscoveryRule
+ | showDatabaseDiscoveryTypes
+ | showDatabaseDiscoveryHeartbeats
| 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 ee90fe6..2d9f555 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
@@ -26,7 +26,9 @@ import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatab
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.ShowDatabaseDiscoveryHeartbeatsStatement;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
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;
@@ -38,8 +40,10 @@ import
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQL
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.ShowDatabaseDiscoveryHeartbeatsContext;
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.ShowDatabaseDiscoveryTypesContext;
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;
@@ -119,6 +123,16 @@ public final class
DatabaseDiscoveryDistSQLStatementVisitor extends DatabaseDisc
return new
DatabaseDiscoveryTypeSegment(getIdentifierValue(ctx.discoveryTypeName()),
(AlgorithmSegment) visit(ctx.typeDefinition()));
}
+ @Override
+ public ASTNode visitShowDatabaseDiscoveryTypes(final
ShowDatabaseDiscoveryTypesContext ctx) {
+ return new ShowDatabaseDiscoveryTypesStatement(null ==
ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName()));
+ }
+
+ @Override
+ public ASTNode visitShowDatabaseDiscoveryHeartbeats(final
ShowDatabaseDiscoveryHeartbeatsContext ctx) {
+ return new ShowDatabaseDiscoveryHeartbeatsStatement(null ==
ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName()));
+ }
+
private String getIdentifierValue(final ParseTree context) {
if (null == context) {
return null;
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/Keyword.g4
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/ShowDatabaseDiscoveryHeartbeatsStatement.java
similarity index 61%
copy from
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/Keyword.g4
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/ShowDatabaseDiscoveryHeartbeatsStatement.java
index 5459bab..1b118bd 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/Keyword.g4
+++
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/ShowDatabaseDiscoveryHeartbeatsStatement.java
@@ -15,62 +15,17 @@
* limitations under the License.
*/
-lexer grammar Keyword;
+package org.apache.shardingsphere.dbdiscovery.distsql.parser.statement;
-import Alphabet;
+import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-WS
- : [ \t\r\n] + ->skip
- ;
-
-CREATE
- : C R E A T E
- ;
-
-ALTER
- : A L T E R
- ;
-
-DROP
- : D R O P
- ;
-
-SHOW
- : S H O W
- ;
-
-RESOURCES
- : R E S O U R C E S
- ;
-
-RULE
- : R U L E
- ;
-
-FROM
- : F R O M
- ;
-
-TYPE
- : T Y P E
- ;
-
-NAME
- : N A M E
- ;
-
-PROPERTIES
- : P R O P E R T I E S
- ;
-
-RULES
- : R U L E S
- ;
-
-DB_DISCOVERY
- : D B UL_ D I S C O V E R Y
- ;
-
-HEARTBEAT
- : H E A R T B E A T
- ;
+/**
+ * Show database discovery heartbeats statement.
+ */
+public final class ShowDatabaseDiscoveryHeartbeatsStatement extends
ShowRulesStatement {
+
+ public ShowDatabaseDiscoveryHeartbeatsStatement(final SchemaSegment
schema) {
+ super(schema);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
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/ShowDatabaseDiscoveryTypesStatement.java
similarity index 61%
copy from
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
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/ShowDatabaseDiscoveryTypesStatement.java
index b87b860..1a1549b 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
+++
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/ShowDatabaseDiscoveryTypesStatement.java
@@ -15,14 +15,17 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.dbdiscovery.distsql.parser.statement;
-import Keyword, Literals, Symbol;
+import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-showDatabaseDiscoveryRules
- : SHOW DB_DISCOVERY RULES (FROM schemaName)?
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Show database discovery types statement.
+ */
+public final class ShowDatabaseDiscoveryTypesStatement extends
ShowRulesStatement {
+
+ public ShowDatabaseDiscoveryTypesStatement(final SchemaSegment schema) {
+ super(schema);
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java
index 4d8e691..e8dce80 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java
@@ -19,7 +19,9 @@ package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statemen
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryHeartbeatsStatement;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
+import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowSingleTableRulesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowSingleTableStatement;
@@ -73,8 +75,8 @@ public final class ShowRulesStatementAssert {
* @param expected expected show rule statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext,
final ShowRulesStatement actual, final SQLParserTestCase expected) {
- if (actual instanceof ShowDatabaseDiscoveryRulesStatement) {
- ShowDatabaseDiscoveryRulesStatementAssert.assertIs(assertContext,
(ShowDatabaseDiscoveryRulesStatement) actual,
(ShowDataBaseDiscoveryRulesStatementTestCase) expected);
+ if (actual instanceof ShowDatabaseDiscoveryRulesStatement || actual
instanceof ShowDatabaseDiscoveryTypesStatement || actual instanceof
ShowDatabaseDiscoveryHeartbeatsStatement) {
+ ShowDatabaseDiscoveryRulesStatementAssert.assertIs(assertContext,
actual, (ShowDataBaseDiscoveryRulesStatementTestCase) expected);
} else if (actual instanceof ShowEncryptRulesStatement) {
ShowEncryptRulesStatementAssert.assertIs(assertContext,
(ShowEncryptRulesStatement) actual, (ShowEncryptRulesStatementTestCase)
expected);
} else if (actual instanceof ShowReadwriteSplittingRulesStatement) {
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowDatabaseDiscoveryRulesStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowDatabaseDiscoveryRulesStatementAssert.java
index b0cb9a8..95140d3 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowDatabaseDiscoveryRulesStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowDatabaseDiscoveryRulesStatementAssert.java
@@ -19,7 +19,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.ShowDatabaseDiscoveryRulesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.schema.SchemaAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowDataBaseDiscoveryRulesStatementTestCase;
@@ -40,7 +40,7 @@ public final class ShowDatabaseDiscoveryRulesStatementAssert {
* @param actual actual show database discovery rules statement
* @param expected expected show database discovery rules statement test
case
*/
- public static void assertIs(final SQLCaseAssertContext assertContext,
final ShowDatabaseDiscoveryRulesStatement actual, final
ShowDataBaseDiscoveryRulesStatementTestCase expected) {
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final ShowRulesStatement actual, final
ShowDataBaseDiscoveryRulesStatementTestCase expected) {
if (null != expected.getSchema()) {
assertTrue(assertContext.getText("Actual schema should exist."),
actual.getSchema().isPresent());
SchemaAssert.assertIs(assertContext, actual.getSchema().get(),
expected.getSchema());
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml
index 621a4f0..2dcae0e 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml
@@ -49,6 +49,14 @@
<show-db-discovery-rules sql-case-id="show-db-discovery-rules">
<schema name="db_discovery_db" start-index="29" stop-index="43"/>
</show-db-discovery-rules>
+
+ <show-db-discovery-rules sql-case-id="show-db-discovery-types">
+ <schema name="db_discovery_db" start-index="29" stop-index="43"/>
+ </show-db-discovery-rules>
+
+ <show-db-discovery-rules sql-case-id="show-db-discovery-heartbeats">
+ <schema name="db_discovery_db" start-index="34" stop-index="48"/>
+ </show-db-discovery-rules>
<show-encrypt-rules sql-case-id="show-encrypt-rules">
<schema name="encrypt_db" start-index="24" stop-index="33"/>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml
index 584a23d..5782f0c 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml
@@ -25,6 +25,8 @@
<distsql-case id="show-sharding-algorithms-from" value="SHOW SHARDING
ALGORITHMS FROM schemaName" />
<distsql-case id="show-readwrite-splitting-rules" value="SHOW
READWRITE_SPLITTING RULES FROM readwrite_splitting_db" />
<distsql-case id="show-db-discovery-rules" value="SHOW DB_DISCOVERY RULES
FROM db_discovery_db" />
+ <distsql-case id="show-db-discovery-types" value="SHOW DB_DISCOVERY TYPES
FROM db_discovery_db" />
+ <distsql-case id="show-db-discovery-heartbeats" value="SHOW DB_DISCOVERY
HEARTBEATS FROM db_discovery_db" />
<distsql-case id="show-encrypt-rules" value="SHOW ENCRYPT RULES FROM
encrypt_db" />
<distsql-case id="show-encrypt-table-rules" value="SHOW ENCRYPT TABLE RULE
t_encrypt FROM encrypt_db" />
<distsql-case id="show-shadow-rules" value="SHOW SHADOW RULE shadow_rule
FROM shadow_db" />