You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/11/08 10:16:27 UTC
[shardingsphere] branch master updated: Add : add result for SQL parser IT (#21999) (#22011)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 7452eb0a045 Add : add result for SQL parser IT (#21999) (#22011)
7452eb0a045 is described below
commit 7452eb0a0459f7b8b93b18c34e978708c5b997ae
Author: 孙念君 Nianjun Sun <su...@apache.org>
AuthorDate: Tue Nov 8 18:16:16 2022 +0800
Add : add result for SQL parser IT (#21999) (#22011)
* Add : add result for SQL parser IT (#21999)
* Refactor : fix a spelling issue (#21999)
---
test/integration-test/sql-parser/pom.xml | 19 +++++++
.../DynamicLoadingSQLParserParameterizedTest.java | 15 ++++--
.../DynamicLoadingMySQLParserParameterizedIT.java | 5 +-
...amicLoadingPostgreSQLParserParameterizedIT.java | 5 +-
.../sql/parser/result/CSVResultGenerator.java | 63 ++++++++++++++++++++++
5 files changed, 98 insertions(+), 9 deletions(-)
diff --git a/test/integration-test/sql-parser/pom.xml b/test/integration-test/sql-parser/pom.xml
index cbba3f5ef6e..85baf0b3c70 100644
--- a/test/integration-test/sql-parser/pom.xml
+++ b/test/integration-test/sql-parser/pom.xml
@@ -27,16 +27,35 @@
<artifactId>shardingsphere-integration-test-sql-parser</artifactId>
<name>${project.artifactId}</name>
+ <properties>
+ <commons-csv.version>1.9.0</commons-csv.version>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-parser-test</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-mysql</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-postgresql</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-csv</artifactId>
+ <version>${commons-csv.version}</version>
+ </dependency>
</dependencies>
<build>
diff --git a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/base/DynamicLoadingSQLParserParameterizedTest.java
similarity index 93%
rename from test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java
rename to test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/base/DynamicLoadingSQLParserParameterizedTest.java
index 57967a928df..dafd769e6b6 100644
--- a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/engine/DynamicLoadingSQLParserParameterizedTest.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/base/DynamicLoadingSQLParserParameterizedTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.sql.parser.parameterized.engine;
+package org.apache.shardingsphere.sql.parser.base;
import com.google.common.collect.ImmutableMap;
import com.jayway.jsonpath.JsonPath;
@@ -27,7 +27,7 @@ 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.Ignore;
+import org.apache.shardingsphere.sql.parser.result.CSVResultGenerator;
import org.junit.Test;
import java.io.BufferedReader;
@@ -36,9 +36,9 @@ import java.io.InputStreamReader;
import java.net.URI;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -52,6 +52,9 @@ public abstract class DynamicLoadingSQLParserParameterizedTest {
private final String databaseType;
+ // TODO this will refactor as an abstract
+ private final CSVResultGenerator resultGenerator;
+
protected static Collection<Object[]> getTestParameters(final String sqlCaseApi, final URI sqlCaseURI) {
Collection<Object[]> result = new LinkedList<>();
if (sqlCaseApi.isEmpty()) {
@@ -104,7 +107,7 @@ public abstract class DynamicLoadingSQLParserParameterizedTest {
try {
InputStreamReader in = new InputStreamReader(casesURI.toURL().openStream());
result = new BufferedReader(in).lines().collect(Collectors.joining(System.lineSeparator()));
- } catch (IOException ingore) {
+ } catch (IOException ignore) {
log.warn("Error: GitHub API rate limit exceeded");
}
return result;
@@ -123,14 +126,16 @@ public abstract class DynamicLoadingSQLParserParameterizedTest {
return result;
}
- @Ignore
@Test
public final void assertParseSQL() {
+ String result = "success";
try {
ParseASTNode parseASTNode = new SQLParserEngine(databaseType, new CacheOption(128, 1024L)).parse(sql, false);
new SQLVisitorEngine(databaseType, "STATEMENT", true, new Properties()).visit(parseASTNode);
} catch (final SQLParsingException | ClassCastException | NullPointerException | SQLASTVisitorException | NumberFormatException | StringIndexOutOfBoundsException ignore) {
+ result = "failed";
log.warn("ParserError: " + sqlCaseId + " value: " + sql + " db-type: " + databaseType);
}
+ resultGenerator.processResult(sqlCaseId, databaseType, result, sql);
}
}
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/mysql/DynamicLoadingMySQLParserParameterizedIT.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/mysql/DynamicLoadingMySQLParserParameterizedIT.java
index 5a081588d27..2909153ac28 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/mysql/DynamicLoadingMySQLParserParameterizedIT.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/mysql/DynamicLoadingMySQLParserParameterizedIT.java
@@ -17,9 +17,10 @@
package org.apache.shardingsphere.sql.parser.mysql;
+import org.apache.shardingsphere.sql.parser.base.DynamicLoadingSQLParserParameterizedTest;
import org.apache.shardingsphere.sql.parser.env.IntegrationTestEnvironment;
+import org.apache.shardingsphere.sql.parser.result.CSVResultGenerator;
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;
@@ -31,7 +32,7 @@ import java.util.Collections;
public final class DynamicLoadingMySQLParserParameterizedIT extends DynamicLoadingSQLParserParameterizedTest {
public DynamicLoadingMySQLParserParameterizedIT(final String sqlCaseId, final String sqlCaseValue) {
- super(sqlCaseId, sqlCaseValue, "MySQL");
+ super(sqlCaseId, sqlCaseValue, "MySQL", new CSVResultGenerator("MySQL"));
}
/**
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/DynamicLoadingPostgreSQLParserParameterizedIT.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/DynamicLoadingPostgreSQLParserParameterizedIT.java
index fc79e0b57fd..0ca20cb18d8 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/DynamicLoadingPostgreSQLParserParameterizedIT.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/DynamicLoadingPostgreSQLParserParameterizedIT.java
@@ -17,9 +17,10 @@
package org.apache.shardingsphere.sql.parser.postgresql;
+import org.apache.shardingsphere.sql.parser.base.DynamicLoadingSQLParserParameterizedTest;
import org.apache.shardingsphere.sql.parser.env.IntegrationTestEnvironment;
+import org.apache.shardingsphere.sql.parser.result.CSVResultGenerator;
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;
@@ -31,7 +32,7 @@ import java.util.Collections;
public final class DynamicLoadingPostgreSQLParserParameterizedIT extends DynamicLoadingSQLParserParameterizedTest {
public DynamicLoadingPostgreSQLParserParameterizedIT(final String sqlCaseId, final String sqlCaseValue) {
- super(sqlCaseId, sqlCaseValue, "PostgreSQL");
+ super(sqlCaseId, sqlCaseValue, "PostgreSQL", new CSVResultGenerator("PostgreSQL"));
}
/**
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/result/CSVResultGenerator.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/result/CSVResultGenerator.java
new file mode 100644
index 00000000000..43b2d72d628
--- /dev/null
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/result/CSVResultGenerator.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.sql.parser.result;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * CSV format result generator.
+ */
+@Slf4j
+public class CSVResultGenerator {
+
+ private final CSVPrinter printer;
+
+ public CSVResultGenerator(final String databaseType) {
+ CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
+ .setHeader("SQLCaseId", "DatabaseType", "Result", "SQL").setSkipHeaderRecord(false).build();
+ try {
+ Writer out = new FileWriter(databaseType + "-result.csv", true);
+ printer = new CSVPrinter(out, csvFormat);
+ } catch (IOException e) {
+ log.error("create sql parser csv file failed");
+ throw new RuntimeException("create sql parser csv file failed", e);
+ }
+ }
+
+ /**
+ * Process the result.
+ *
+ * @param param the content for a row of CSV record
+ */
+ public void processResult(final Object... param) {
+ try {
+ printer.printRecord(param);
+ // TODO this may be optimized in next step.
+ printer.flush();
+ } catch (IOException e) {
+ log.error("write sql parser csv file failed");
+ throw new RuntimeException("write sql parser csv file failed", e);
+ }
+ }
+}