This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 0de3c51fbc0 Dynamic Loading SQL Parser Parameterized Test (#21431)
0de3c51fbc0 is described below
commit 0de3c51fbc0a3b7733e82d65fc9450bf90213e85
Author: Junfeng <[email protected]>
AuthorDate: Fri Nov 4 12:36:52 2022 +0800
Dynamic Loading SQL Parser Parameterized Test (#21431)
* Implement dynamic-loading-test-case for IT
* Implement DynamicLoadingSQLParserParameterizedTest
* Add testng & jsoup, and it.dynamic.loading for test
* Remove jsoup & testng, and Add github-api
* fix: simplify it.yml
* feat: rm jsoup, import commons-io, RestTemplate
* fix: get test cases with github rest api
* feat: get test case name
* fix: rm println(for test)
* feat: add MySQL & Postgre dynamic loading sql test
* fix: re-build DynamicLoadingSQLParserParameterizedTest
* fix: modify code style
* fix: modify test name
* fix: remove unused statement
* fix: re-build test info
* fix: rm workflow
* fix: rm profile
* fix: rm wrong build
* fix: expand memory of jvm
* fix: rm duplicate declaration of jackson.version
* fix: rm duplicate declaration of jackson-databind
* feat: throw no exception
* fix: upgrade caffeine & rm spring-web
* fix: replace type of list
* fix: replace RestTemplate with JsonMapper
* fix: rm common-io & spring-boot-starter
* fix: replace IOUtil with BufferedReader & rm commons-io
* fix: unexpand JVM
* fix: rm jsckson
* fix: rm jackson
* fix: make interface(List) as return type
* fix: catch multi exceptions
---
...DynamicLoadingMySQLParserParameterizedTest.java | 39 +++++++
...icLoadingPostgreSQLParserParameterizedTest.java | 39 +++++++
.../DynamicLoadingSQLParserParameterizedTest.java | 115 +++++++++++++++++++++
3 files changed, 193 insertions(+)
diff --git
a/sql-parser/dialect/mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/DynamicLoadingMySQLParserParameterizedTest.java
b/sql-parser/dialect/mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/DynamicLoadingMySQLParserParameterizedTest.java
new file mode 100644
index 00000000000..4d346172413
--- /dev/null
+++
b/sql-parser/dialect/mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/DynamicLoadingMySQLParserParameterizedTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.sql.parser.mysql;
+
+import
org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.engine.DynamicLoadingSQLParserParameterizedTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.io.IOException;
+import java.util.Collection;
+
+@RunWith(ShardingSphereParallelTestParameterized.class)
+public final class DynamicLoadingMySQLParserParameterizedTest extends
DynamicLoadingSQLParserParameterizedTest {
+
+ public DynamicLoadingMySQLParserParameterizedTest(final String sqlCaseId,
final String sqlCaseValue) {
+ super(sqlCaseId, sqlCaseValue, "MySQL");
+ }
+
+ @Parameters(name = "{0} (MySQL) -> {1}")
+ public static Collection<Object[]> getTestParameters() throws IOException {
+ return
DynamicLoadingSQLParserParameterizedTest.getTestParameters("https://github.com/mysql/mysql-server/tree/8.0/mysql-test/t");
+ }
+}
diff --git
a/sql-parser/dialect/postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/DynamicLoadingPostgreSQLParserParameterizedTest.java
b/sql-parser/dialect/postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/DynamicLoadingPostgreSQLParserParameterizedTest.java
new file mode 100644
index 00000000000..293aaf313c7
--- /dev/null
+++
b/sql-parser/dialect/postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/DynamicLoadingPostgreSQLParserParameterizedTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.sql.parser.postgresql;
+
+import
org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.engine.DynamicLoadingSQLParserParameterizedTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.io.IOException;
+import java.util.Collection;
+
+@RunWith(ShardingSphereParallelTestParameterized.class)
+public final class DynamicLoadingPostgreSQLParserParameterizedTest extends
DynamicLoadingSQLParserParameterizedTest {
+
+ public DynamicLoadingPostgreSQLParserParameterizedTest(final String
sqlCaseId, final String sqlCaseValue) {
+ super(sqlCaseId, sqlCaseValue, "PostgreSQL");
+ }
+
+ @Parameters(name = "{0} (PostgreSQL) -> {1}")
+ public static Collection<Object[]> getTestParameters() throws IOException {
+ return
DynamicLoadingSQLParserParameterizedTest.getTestParameters("https://github.com/postgres/postgres/tree/master/src/test/regress/sql");
+ }
+}
diff --git
a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java
b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java
new file mode 100644
index 00000000000..369d6fa5473
--- /dev/null
+++
b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.engine;
+
+import com.google.common.collect.ImmutableMap;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
+import org.apache.shardingsphere.sql.parser.exception.SQLASTVisitorException;
+import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+public abstract class DynamicLoadingSQLParserParameterizedTest {
+
+ private final String sqlCaseId;
+
+ private final String sqlCaseValue;
+
+ private final String databaseType;
+
+ private static String getContent(final String url) throws IOException {
+ InputStreamReader in = new InputStreamReader(new
URL(url).openStream());
+ return new
BufferedReader(in).lines().collect(Collectors.joining(System.lineSeparator()));
+ }
+
+ private static List<Map<String, String>> getResponse(final String
sqlCaseURL) throws IOException {
+ List<Map<String, String>> result = new LinkedList<>();
+ String[] patches = sqlCaseURL.split("/", 8);
+ String sqlCasesOwner = patches[3];
+ String sqlCasesRepo = patches[4];
+ String sqlCasesDirectory = patches[7];
+ String sqlCasesAPI = "https://api.github.com/repos/" + sqlCasesOwner +
"/" + sqlCasesRepo + "/contents/" + sqlCasesDirectory;
+ String[] lines = getContent(sqlCasesAPI).split("\\,");
+ String nameItem = null;
+ for (String each : lines) {
+ if (each.contains("name")) {
+ nameItem = each.split("\"")[3];
+ } else if (each.contains("download_url")) {
+ String downloadURLItem = each.split("\"")[3];
+ result.add(ImmutableMap.of("name", nameItem, "download_url",
downloadURLItem));
+ }
+ }
+ return result;
+ }
+
+ protected static Collection<Object[]> getTestParameters(final String
sqlCaseURL) throws IOException {
+ Collection<Object[]> result = new LinkedList<>();
+ List<Map<String, String>> response = getResponse(sqlCaseURL);
+ for (Map<String, String> each : response) {
+ result.addAll(getSqlCases(each));
+ }
+ return result;
+ }
+
+ private static Collection<Object[]> getSqlCases(final Map<String, String>
elements) throws IOException {
+ Collection<Object[]> result = new LinkedList<>();
+ String sqlCaseFileName = elements.get("name");
+ String[] lines = getContent(elements.get("download_url")).split("\n");
+ int sqlCaseEnum = 1;
+ for (String each : lines) {
+ if (each.isEmpty()) {
+ continue;
+ }
+ if (Character.isLetter(each.charAt(0)) &&
each.charAt(each.length() - 1) == ';') {
+ String sqlCaseId = sqlCaseFileName.split("\\.")[0] +
sqlCaseEnum;
+ result.add(new Object[]{
+ sqlCaseId, each,
+ });
+ sqlCaseEnum++;
+ }
+ }
+ return result;
+ }
+
+ @Test
+ public final void assertDynamicLoadingSQL() {
+ try {
+ CacheOption cacheOption = new CacheOption(128, 1024L);
+ ParseASTNode parseContext = new SQLParserEngine(databaseType,
cacheOption).parse(sqlCaseValue, false);
+ new SQLVisitorEngine(databaseType, "STATEMENT", true, new
Properties()).visit(parseContext);
+ } catch (SQLParsingException | ClassCastException |
NullPointerException
+ | SQLASTVisitorException | NumberFormatException |
StringIndexOutOfBoundsException ignore) {
+ System.out.println("ParserError: " + sqlCaseId + " value: " +
sqlCaseValue + " db-type: " + databaseType);
+ }
+ }
+}