This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 f0c6fb988fd Add sql parser test of export metadata to file DistSQL
(#32529)
f0c6fb988fd is described below
commit f0c6fb988fd03c554496e45f9e26978a7c34e455
Author: jiangML <[email protected]>
AuthorDate: Thu Aug 15 17:23:19 2024 +0800
Add sql parser test of export metadata to file DistSQL (#32529)
---
.../ral/impl/QueryableRALStatementAssert.java | 3 +-
.../queryable/ExportMetaDataStatementAssert.java | 50 ++++++++++++++++++++++
.../cases/parser/jaxb/RootSQLParserTestCases.java | 4 ++
.../ral/ExportMetaDataToFileStatementTestCase.java | 35 +++++++++++++++
.../src/main/resources/case/ral/queryable.xml | 3 ++
.../main/resources/sql/supported/ral/queryable.xml | 1 +
6 files changed, 95 insertions(+), 1 deletion(-)
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/QueryableRALStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/QueryableRALStatementAssert.java
index 60620724737..e419519d7df 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/QueryableRALStatementAssert.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/QueryableRALStatementAssert.java
@@ -33,6 +33,7 @@ import
org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowTableM
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ExistingAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.queryable.ConvertYamlConfigurationStatementAssert;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.queryable.ExportMetaDataStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.queryable.ShowDistVariableStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.queryable.ShowDistVariablesStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.queryable.ShowTableMetaDataStatementAssert;
@@ -67,7 +68,7 @@ public final class QueryableRALStatementAssert {
} else if (actual instanceof ExportDatabaseConfigurationStatement) {
ExistingAssert.assertIs(assertContext, actual, expected);
} else if (actual instanceof ExportMetaDataStatement) {
- ExistingAssert.assertIs(assertContext, actual, expected);
+ ExportMetaDataStatementAssert.assertIs(assertContext,
(ExportMetaDataStatement) actual, expected);
} else if (actual instanceof ExportStorageNodesStatement) {
ExistingAssert.assertIs(assertContext, actual, expected);
} else if (actual instanceof ShowComputeNodeInfoStatement) {
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/queryable/ExportMetaDataStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/queryable/ExportMetaDataStatementAssert.java
new file mode 100644
index 00000000000..f7bb319eb77
--- /dev/null
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/queryable/ExportMetaDataStatementAssert.java
@@ -0,0 +1,50 @@
+/*
+ * 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.it.sql.parser.internal.asserts.statement.ral.impl.queryable;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.distsql.statement.ral.queryable.export.ExportMetaDataStatement;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ExistingAssert;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ExportMetaDataToFileStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Export meta data statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ExportMetaDataStatementAssert {
+
+ /**
+ * Assert export meta data statement is correct with expected parser
result.
+ *
+ * @param assertContext assert context
+ * @param actual actual export meta data statement
+ * @param expected expected parser result
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final ExportMetaDataStatement actual, final SQLParserTestCase expected) {
+ ExistingAssert.assertIs(assertContext, actual, expected);
+ if (expected instanceof ExportMetaDataToFileStatementTestCase) {
+ assertThat(actual.getFilePath().orElse(null),
is(((ExportMetaDataToFileStatementTestCase) expected).getFilePath()));
+ }
+ }
+}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
index c8a5da7d34b..8b9bebec14d 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
@@ -319,6 +319,7 @@ import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.DiscardDistSQLStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ExportDatabaseConfigurationStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ExportMetaDataStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ExportMetaDataToFileStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ExportStorageNodesStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ImportDatabaseConfigurationStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ImportMetaDataStatementTestCase;
@@ -1452,6 +1453,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "export-metadata")
private final List<ExportMetaDataStatementTestCase>
exportMetaDataStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "export-metadata-to-file")
+ private final List<ExportMetaDataToFileStatementTestCase>
exportMetaDataToFileStatementTestCases = new LinkedList<>();
+
@XmlElement(name = "export-storage-nodes")
private final List<ExportStorageNodesStatementTestCase>
exportStorageNodesStatementTestCases = new LinkedList<>();
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/ExportMetaDataToFileStatementTestCase.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/ExportMetaDataToFileStatementTestCase.java
new file mode 100644
index 00000000000..ec1ba0fffb0
--- /dev/null
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/ExportMetaDataToFileStatementTestCase.java
@@ -0,0 +1,35 @@
+/*
+ * 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.it.sql.parser.internal.cases.parser.jaxb.statement.ral;
+
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.DatabaseContainedTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * Export meta data to file statement test case.
+ */
+@Getter
+@Setter
+public final class ExportMetaDataToFileStatementTestCase extends
DatabaseContainedTestCase {
+
+ @XmlElement(name = "file-path")
+ private String filePath;
+}
diff --git a/test/it/parser/src/main/resources/case/ral/queryable.xml
b/test/it/parser/src/main/resources/case/ral/queryable.xml
index a804109f95f..6a039c78cad 100644
--- a/test/it/parser/src/main/resources/case/ral/queryable.xml
+++ b/test/it/parser/src/main/resources/case/ral/queryable.xml
@@ -42,6 +42,9 @@
<database name="database_name" start-index="28" stop-index="40" />
</export-database-config>
<export-metadata sql-case-id="export-metadata" />
+ <export-metadata-to-file sql-case-id="export-metadata-to-file">
+ <file-path>/tmp/metadata.json</file-path>
+ </export-metadata-to-file>
<export-storage-nodes sql-case-id="export-storage-nodes" />
<convert-yaml-config sql-case-id="convert-yaml-config">
<file-path>/yaml/database-sharding.yaml</file-path>
diff --git a/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml
b/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml
index 0043cf16413..619248f1778 100644
--- a/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml
@@ -37,6 +37,7 @@
<sql-case id="export-database-config" value="EXPORT DATABASE CONFIGURATION
FROM database_name" db-types="ShardingSphere" />
<sql-case id="export-metadata" value="EXPORT METADATA"
db-types="ShardingSphere" />
+ <sql-case id="export-metadata-to-file" value="EXPORT METADATA TO FILE
'/tmp/metadata.json'" db-types="ShardingSphere" />
<sql-case id="export-storage-nodes" value="EXPORT STORAGE NODES"
db-types="ShardingSphere" />
<sql-case id="convert-yaml-config" value="CONVERT YAML CONFIGURATION FROM
FILE '/yaml/database-sharding.yaml'" db-types="ShardingSphere" />
</sql-cases>