From e71e94d7e1b71694402829ea0074cb085129069e Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 29 Nov 2022 15:13:26 +0800 Subject: [PATCH] Add SQLParserParameterizedArray (#22497) --- .../parser/SQLParserParameterizedArray.java | 40 +++++++++++++++++++ .../ExternalSQLParserParameterizedArray.java | 8 ++-- .../parser/external/loader/SQLCaseLoader.java | 4 +- .../InternalSQLParserParameterizedArray.java | 4 +- .../test/runner/param/RunnerParameters.java | 6 +-- 5 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/SQLParserParameterizedArray.java diff --git a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/SQLParserParameterizedArray.java b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/SQLParserParameterizedArray.java new file mode 100644 index 0000000000000..2da1184adff08 --- /dev/null +++ b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/SQLParserParameterizedArray.java @@ -0,0 +1,40 @@ +/* + * 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; + +import org.apache.shardingsphere.test.runner.param.ParameterizedArray; + +/** + * SQL parser parameterized array. + */ +public interface SQLParserParameterizedArray extends ParameterizedArray { + + /** + * Get SQL case ID. + * + * @return SQL case ID + */ + String getSqlCaseId(); + + /** + * Get database type. + * + * @return database type + */ + String getDatabaseType(); +} diff --git a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/engine/param/ExternalSQLParserParameterizedArray.java b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/engine/param/ExternalSQLParserParameterizedArray.java index eeb846fca3975..8c8dd26e56784 100644 --- a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/engine/param/ExternalSQLParserParameterizedArray.java +++ b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/engine/param/ExternalSQLParserParameterizedArray.java @@ -19,21 +19,21 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.test.runner.param.ParameterizedArray; +import org.apache.shardingsphere.test.sql.parser.SQLParserParameterizedArray; /** * External SQL parser parameterized array. */ @RequiredArgsConstructor @Getter -public final class ExternalSQLParserParameterizedArray implements ParameterizedArray { +public final class ExternalSQLParserParameterizedArray implements SQLParserParameterizedArray { private final String sqlCaseId; - private final String sql; - private final String databaseType; + private final String sql; + private final String reportType; @Override diff --git a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/loader/SQLCaseLoader.java b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/loader/SQLCaseLoader.java index 9ddf1505123c5..8fbf63a30913d 100644 --- a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/loader/SQLCaseLoader.java +++ b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/external/loader/SQLCaseLoader.java @@ -68,7 +68,7 @@ public Collection load(final URI sqlCaseURI result.addAll(createSQLCases(fileName, sqlCaseFileContent, resultFileContent, databaseType, reportType)); } if (result.isEmpty()) { - result.add(new ExternalSQLParserParameterizedArray("", "", databaseType, reportType)); + result.add(new ExternalSQLParserParameterizedArray("", databaseType, "", reportType)); } return result; } @@ -102,7 +102,7 @@ private Collection createSQLCases(final Str resultIndex = searchInResultContent(resultIndex, rawResultLines, completedSQL, statementLines); if (resultIndex >= rawResultLines.length || !rawResultLines[resultIndex].contains("ERROR")) { String sqlCaseId = sqlCaseFileName + sqlCaseEnum; - result.add(new ExternalSQLParserParameterizedArray(sqlCaseId, completedSQL, databaseType, reportType)); + result.add(new ExternalSQLParserParameterizedArray(sqlCaseId, databaseType, completedSQL, reportType)); sqlCaseEnum++; } completedSQL = ""; diff --git a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/engine/param/InternalSQLParserParameterizedArray.java b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/engine/param/InternalSQLParserParameterizedArray.java index 3551a97f1fe98..55039e04e373f 100644 --- a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/engine/param/InternalSQLParserParameterizedArray.java +++ b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/engine/param/InternalSQLParserParameterizedArray.java @@ -19,7 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.test.runner.param.ParameterizedArray; +import org.apache.shardingsphere.test.sql.parser.SQLParserParameterizedArray; import org.apache.shardingsphere.test.sql.parser.internal.cases.sql.type.SQLCaseType; /** @@ -27,7 +27,7 @@ */ @RequiredArgsConstructor @Getter -public final class InternalSQLParserParameterizedArray implements ParameterizedArray { +public final class InternalSQLParserParameterizedArray implements SQLParserParameterizedArray { private final String sqlCaseId; diff --git a/test/runner/src/main/java/org/apache/shardingsphere/test/runner/param/RunnerParameters.java b/test/runner/src/main/java/org/apache/shardingsphere/test/runner/param/RunnerParameters.java index 40b727cd2e333..99138118efea0 100644 --- a/test/runner/src/main/java/org/apache/shardingsphere/test/runner/param/RunnerParameters.java +++ b/test/runner/src/main/java/org/apache/shardingsphere/test/runner/param/RunnerParameters.java @@ -38,9 +38,9 @@ public final class RunnerParameters { */ @SneakyThrows(ReflectiveOperationException.class) public ParameterizedArray getParameterizedArray() { - Field parametersField = BlockJUnit4ClassRunnerWithParameters.class.getDeclaredField("parameters"); - parametersField.setAccessible(true); - Object[] params = (Object[]) parametersField.get(getRunner()); + Field paramsField = BlockJUnit4ClassRunnerWithParameters.class.getDeclaredField("parameters"); + paramsField.setAccessible(true); + Object[] params = (Object[]) paramsField.get(getRunner()); return (ParameterizedArray) params[0]; }