Skip to content

Commit

Permalink
Add SQLParserParameterizedArray (#22497)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 29, 2022
1 parent 34c5cba commit e71e94d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Collection<ExternalSQLParserParameterizedArray> 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;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ private Collection<ExternalSQLParserParameterizedArray> 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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

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;

/**
* Internal SQL parser parameterized array.
*/
@RequiredArgsConstructor
@Getter
public final class InternalSQLParserParameterizedArray implements ParameterizedArray {
public final class InternalSQLParserParameterizedArray implements SQLParserParameterizedArray {

private final String sqlCaseId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down

0 comments on commit e71e94d

Please sign in to comment.