You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2022/11/13 07:56:56 UTC
[shardingsphere] branch master updated: Rename SQLParseResultReporter (#22136)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 f1031cf606e Rename SQLParseResultReporter (#22136)
f1031cf606e is described below
commit f1031cf606e0cd2239c47e30f8f334c2829c0af8
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Nov 13 15:56:50 2022 +0800
Rename SQLParseResultReporter (#22136)
* Refactor SQLParserResultProcessor
* Refactor SQLParseResultReporter
---
.../parser/engine/SQLParserParameterizedIT.java | 6 ++--
.../engine/dialect/MySQLParserParameterizedIT.java | 4 +--
.../dialect/PostgreSQLParserParameterizedIT.java | 4 +--
...tProcessor.java => SQLParseResultReporter.java} | 10 +++---
...ger.java => SQLParseResultReporterManager.java} | 12 ++++----
...ocessor.java => CsvSQLParseResultReporter.java} | 36 ++++++++++------------
...ocessor.java => LogSQLParseResultReporter.java} | 11 ++++---
7 files changed, 41 insertions(+), 42 deletions(-)
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/SQLParserParameterizedIT.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/SQLParserParameterizedIT.java
index 99f5019d7aa..6ec0a378f6c 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/SQLParserParameterizedIT.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/SQLParserParameterizedIT.java
@@ -24,7 +24,7 @@ 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.test.integration.sql.parser.result.SQLParserResultProcessor;
+import org.apache.shardingsphere.test.integration.sql.parser.result.SQLParseResultReporter;
import org.junit.Test;
import java.util.Properties;
@@ -40,7 +40,7 @@ public abstract class SQLParserParameterizedIT {
private final String databaseType;
// TODO this will refactor as an abstract
- private final SQLParserResultProcessor resultGenerator;
+ private final SQLParseResultReporter resultGenerator;
@Test
public final void assertParseSQL() {
@@ -52,6 +52,6 @@ public abstract class SQLParserParameterizedIT {
result = "failed";
log.warn("ParserError: " + sqlCaseId + " value: " + sql + " db-type: " + databaseType);
}
- resultGenerator.processResult(sqlCaseId, databaseType, result, sql);
+ resultGenerator.printResult(sqlCaseId, databaseType, result, sql);
}
}
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/MySQLParserParameterizedIT.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/MySQLParserParameterizedIT.java
index 078bcc0705a..0a915ccd006 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/MySQLParserParameterizedIT.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/MySQLParserParameterizedIT.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.test.integration.sql.parser.engine.dialect;
import org.apache.shardingsphere.test.integration.sql.parser.engine.SQLParserParameterizedIT;
import org.apache.shardingsphere.test.integration.sql.parser.loader.SQLCaseLoader;
import org.apache.shardingsphere.test.integration.sql.parser.loader.strategy.impl.GitHubSQLCaseLoadStrategy;
-import org.apache.shardingsphere.test.integration.sql.parser.result.SQLParserResultProcessorManager;
+import org.apache.shardingsphere.test.integration.sql.parser.result.SQLParseResultReporterManager;
import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;
@@ -32,7 +32,7 @@ import java.util.Collection;
public final class MySQLParserParameterizedIT extends SQLParserParameterizedIT {
public MySQLParserParameterizedIT(final String sqlCaseId, final String sqlCaseValue) {
- super(sqlCaseId, sqlCaseValue, "MySQL", SQLParserResultProcessorManager.getProcessor("MySQL"));
+ super(sqlCaseId, sqlCaseValue, "MySQL", SQLParseResultReporterManager.getProcessor("MySQL"));
}
@Parameters(name = "{0} (MySQL) -> {1}")
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/PostgreSQLParserParameterizedIT.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/PostgreSQLParserParameterizedIT.java
index b96b90e25f7..644c3ed507b 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/PostgreSQLParserParameterizedIT.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/engine/dialect/PostgreSQLParserParameterizedIT.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.test.integration.sql.parser.engine.dialect;
import org.apache.shardingsphere.test.integration.sql.parser.engine.SQLParserParameterizedIT;
import org.apache.shardingsphere.test.integration.sql.parser.loader.SQLCaseLoader;
import org.apache.shardingsphere.test.integration.sql.parser.loader.strategy.impl.GitHubSQLCaseLoadStrategy;
-import org.apache.shardingsphere.test.integration.sql.parser.result.impl.SQLParserCSVResultProcessor;
+import org.apache.shardingsphere.test.integration.sql.parser.result.impl.CsvSQLParseResultReporter;
import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;
@@ -32,7 +32,7 @@ import java.util.Collection;
public final class PostgreSQLParserParameterizedIT extends SQLParserParameterizedIT {
public PostgreSQLParserParameterizedIT(final String sqlCaseId, final String sqlCaseValue) {
- super(sqlCaseId, sqlCaseValue, "PostgreSQL", new SQLParserCSVResultProcessor("PostgreSQL"));
+ super(sqlCaseId, sqlCaseValue, "PostgreSQL", new CsvSQLParseResultReporter("PostgreSQL"));
}
@Parameters(name = "{0} (PostgreSQL) -> {1}")
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParserResultProcessor.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParseResultReporter.java
similarity index 83%
rename from test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParserResultProcessor.java
rename to test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParseResultReporter.java
index e570ebe2417..79feaa2fece 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParserResultProcessor.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParseResultReporter.java
@@ -18,16 +18,16 @@
package org.apache.shardingsphere.test.integration.sql.parser.result;
/**
- * SQL parser result processor.
+ * SQL parse result reporter.
*/
-public interface SQLParserResultProcessor {
+public interface SQLParseResultReporter {
/**
- * Process the result.
+ * Print result.
*
- * @param params the content for a row of CSV record
+ * @param recordValues record values
*/
- void processResult(Object... params);
+ void printResult(Object... recordValues);
/**
* Get the generator type.
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParserResultProcessorManager.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParseResultReporterManager.java
similarity index 83%
rename from test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParserResultProcessorManager.java
rename to test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParseResultReporterManager.java
index 83ccd73ac62..1eb1cc1d245 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParserResultProcessorManager.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/SQLParseResultReporterManager.java
@@ -29,11 +29,11 @@ import java.net.URL;
import java.util.Objects;
/**
- * Get the corresponding result processor through config.
+ * SQL parse result reporter manager.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
-public final class SQLParserResultProcessorManager {
+public final class SQLParseResultReporterManager {
/**
* Get the SQL parser result processor.
@@ -41,21 +41,21 @@ public final class SQLParserResultProcessorManager {
* @param databaseType database type
* @return the implementation of SQLParserResultProcessor
*/
- public static SQLParserResultProcessor getProcessor(final String databaseType) {
+ public static SQLParseResultReporter getProcessor(final String databaseType) {
String type = SQLParserExternalITEnvironment.getInstance().getResultProcessorType();
try {
- Class<?> interfaceClazz = Class.forName(SQLParserResultProcessor.class.getPackage().getName() + "." + SQLParserResultProcessor.class.getSimpleName());
+ Class<?> interfaceClazz = Class.forName(SQLParseResultReporter.class.getPackage().getName() + "." + SQLParseResultReporter.class.getSimpleName());
String packageName = interfaceClazz.getPackage().getName();
URL packagePath = Thread.currentThread().getContextClassLoader().getResource(packageName.replace(".", "/"));
File[] classFiles = new File(Objects.requireNonNull(packagePath).getFile()).listFiles((dir, name) -> name.endsWith(".class"));
for (File file : Objects.requireNonNull(classFiles)) {
String className = file.getName().replaceAll(".class$", "");
Class<?> clazz = Class.forName(packageName + "." + className);
- if (SQLParserResultProcessor.class.isAssignableFrom(clazz)) {
+ if (SQLParseResultReporter.class.isAssignableFrom(clazz)) {
Field typeField = clazz.getDeclaredField("type");
typeField.setAccessible(true);
Constructor<?> constructor = clazz.getConstructor(String.class);
- SQLParserResultProcessor result = (SQLParserResultProcessor) constructor.newInstance(databaseType);
+ SQLParseResultReporter result = (SQLParseResultReporter) constructor.newInstance(databaseType);
if (type.equalsIgnoreCase(typeField.get(result).toString())) {
return result;
}
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/SQLParserCSVResultProcessor.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/CsvSQLParseResultReporter.java
similarity index 67%
rename from test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/SQLParserCSVResultProcessor.java
rename to test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/CsvSQLParseResultReporter.java
index 7a3c44d6e72..7da6a22a9c5 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/SQLParserCSVResultProcessor.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/CsvSQLParseResultReporter.java
@@ -21,52 +21,48 @@ import lombok.Getter;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.shardingsphere.test.integration.sql.parser.env.SQLParserExternalITEnvironment;
-import org.apache.shardingsphere.test.integration.sql.parser.result.SQLParserResultProcessor;
+import org.apache.shardingsphere.test.integration.sql.parser.result.SQLParseResultReporter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
- * CSV result generator.
+ * SQL parse result reporter for CSV.
*/
-public final class SQLParserCSVResultProcessor implements SQLParserResultProcessor {
+public final class CsvSQLParseResultReporter implements SQLParseResultReporter {
private final CSVPrinter printer;
@Getter
private final String type = "CSV";
- public SQLParserCSVResultProcessor(final String databaseType) {
+ public CsvSQLParseResultReporter(final String databaseType) {
try {
File csvFile = new File(SQLParserExternalITEnvironment.getInstance().getResultPath() + databaseType + "-result.csv");
- createHeader(csvFile);
+ printHeader(csvFile);
printer = new CSVPrinter(new FileWriter(csvFile, true), CSVFormat.DEFAULT.builder().setSkipHeaderRecord(true).build());
} catch (final IOException ex) {
throw new RuntimeException("Create CSV file failed.", ex);
}
}
- private synchronized void createHeader(final File csvFile) {
- if (!csvFile.exists()) {
- try (CSVPrinter printer = new CSVPrinter(new FileWriter(csvFile), CSVFormat.DEFAULT.builder().setSkipHeaderRecord(false).build())) {
- printer.printRecord("SQLCaseId", "DatabaseType", "Result", "SQL");
- printer.flush();
- } catch (final IOException ex) {
- throw new RuntimeException("Create CSV file header failed.", ex);
- }
+ private void printHeader(final File csvFile) {
+ if (csvFile.exists()) {
+ return;
+ }
+ try (CSVPrinter printer = new CSVPrinter(new FileWriter(csvFile), CSVFormat.DEFAULT.builder().setSkipHeaderRecord(false).build())) {
+ printer.printRecord("SQLCaseId", "DatabaseType", "Result", "SQL");
+ printer.flush();
+ } catch (final IOException ex) {
+ throw new RuntimeException("Create CSV file header failed.", ex);
}
}
- /**
- * Process the result.
- *
- * @param params the content for a row of CSV record
- */
@Override
- public void processResult(final Object... params) {
+ public void printResult(final Object... recordValues) {
try {
- printer.printRecord(params);
+ printer.printRecord(recordValues);
printer.flush();
} catch (final IOException ex) {
throw new RuntimeException("Write CSV file failed.", ex);
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/SQLParserLogResultProcessor.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/LogSQLParseResultReporter.java
similarity index 81%
rename from test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/SQLParserLogResultProcessor.java
rename to test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/LogSQLParseResultReporter.java
index 337c37f04af..e53b68cfa4c 100644
--- a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/SQLParserLogResultProcessor.java
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/test/integration/sql/parser/result/impl/LogSQLParseResultReporter.java
@@ -19,20 +19,23 @@ package org.apache.shardingsphere.test.integration.sql.parser.result.impl;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.test.integration.sql.parser.result.SQLParserResultProcessor;
+import org.apache.shardingsphere.test.integration.sql.parser.result.SQLParseResultReporter;
+/**
+ * SQL parse result reporter for log.
+ */
@Slf4j
-public class SQLParserLogResultProcessor implements SQLParserResultProcessor {
+public final class LogSQLParseResultReporter implements SQLParseResultReporter {
@Getter
private final String type = "LOG";
- public SQLParserLogResultProcessor(final String databaseType) {
+ public LogSQLParseResultReporter(final String databaseType) {
}
@Override
- public void processResult(final Object... params) {
+ public void printResult(final Object... recordValues) {
// TODO set up the log format
log.info("Printing the SQL parser process result");
}