You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/08/02 09:43:05 UTC
[shardingsphere] branch master updated: Complete parse result of ResetParameterStatement (#19800)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 f975c006fd9 Complete parse result of ResetParameterStatement (#19800)
f975c006fd9 is described below
commit f975c006fd9f413421b4ab3fee5676736289712d
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Tue Aug 2 17:42:58 2022 +0800
Complete parse result of ResetParameterStatement (#19800)
---
.../impl/OpenGaussDALStatementSQLVisitor.java | 2 +-
.../impl/PostgreSQLDALStatementSQLVisitor.java | 2 +-
.../statement/dal/ResetParameterStatement.java | 6 +++
.../dal/OpenGaussResetParameterStatement.java | 4 ++
.../dal/PostgreSQLResetParameterStatement.java | 4 ++
.../asserts/statement/dal/DALStatementAssert.java | 5 +++
.../dal/impl/ResetParameterStatementAssert.java | 45 ++++++++++++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 4 ++
.../dal/ResetParameterStatementTestCase.java | 20 ++++++----
.../src/main/resources/case/dal/reset.xml | 4 +-
10 files changed, 85 insertions(+), 11 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDALStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDALStatementSQLVisitor.java
index f512d04803a..e5614a20ead 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDALStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDALStatementSQLVisitor.java
@@ -103,7 +103,7 @@ public final class OpenGaussDALStatementSQLVisitor extends OpenGaussStatementSQL
@Override
public ASTNode visitResetParameter(final ResetParameterContext ctx) {
- return new OpenGaussResetParameterStatement();
+ return new OpenGaussResetParameterStatement(null != ctx.ALL() ? "ALL" : ctx.identifier().getText());
}
@SuppressWarnings("unchecked")
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java
index a99ff75cc85..dee67419a8a 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java
@@ -112,7 +112,7 @@ public final class PostgreSQLDALStatementSQLVisitor extends PostgreSQLStatementS
@Override
public ASTNode visitResetParameter(final ResetParameterContext ctx) {
- return new PostgreSQLResetParameterStatement();
+ return new PostgreSQLResetParameterStatement(null != ctx.ALL() ? "ALL" : ctx.identifier().getText());
}
@SuppressWarnings("unchecked")
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/dal/ResetParameterStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/dal/ResetParameterStatement.java
index 8a5229872ec..d321c63c8dc 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/dal/ResetParameterStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/dal/ResetParameterStatement.java
@@ -17,12 +17,18 @@
package org.apache.shardingsphere.sql.parser.sql.common.statement.dal;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
/**
* Reset parameter statement.
*/
+@RequiredArgsConstructor
+@Getter
@ToString(callSuper = true)
public abstract class ResetParameterStatement extends AbstractSQLStatement implements DALStatement {
+
+ private final String configurationParameter;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/dal/OpenGaussResetParameterStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/dal/OpenGaussResetParameterStatement.java
index 7aabb4bc4bf..346dedc5fbc 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/dal/OpenGaussResetParameterStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/dal/OpenGaussResetParameterStatement.java
@@ -26,4 +26,8 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.Open
*/
@ToString(callSuper = true)
public final class OpenGaussResetParameterStatement extends ResetParameterStatement implements OpenGaussStatement {
+
+ public OpenGaussResetParameterStatement(final String configurationParameter) {
+ super(configurationParameter);
+ }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/dal/PostgreSQLResetParameterStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/dal/PostgreSQLResetParameterStatement.java
index eeddec900fd..cc4779bfb7f 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/dal/PostgreSQLResetParameterStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/dal/PostgreSQLResetParameterStatement.java
@@ -26,4 +26,8 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.Pos
*/
@ToString(callSuper = true)
public final class PostgreSQLResetParameterStatement extends ResetParameterStatement implements PostgreSQLStatement {
+
+ public PostgreSQLResetParameterStatement(final String configurationParameter) {
+ super(configurationParameter);
+ }
}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/DALStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/DALStatementAssert.java
index 5f356f66fce..2d3f0cdbe34 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/DALStatementAssert.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/DALStatementAssert.java
@@ -21,6 +21,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ResetParameterStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLAlterResourceGroupStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLBinlogStatement;
@@ -92,6 +93,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.MySQLResetStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.MySQLSetResourceGroupStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.MySQLUseStatementAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.ResetParameterStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.RestartStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.SetParameterStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.ShowBinlogEventsStatementAssert;
@@ -139,6 +141,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.LoadIndexInfoStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.OptimizeTableStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.RepairTableStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ResetParameterStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ResetPersistStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ResetStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.RestartStatementTestCase;
@@ -213,6 +216,8 @@ public final class DALStatementAssert {
ShowStatementAssert.assertIs(assertContext, (PostgreSQLShowStatement) actual, (ShowStatementTestCase) expected);
} else if (actual instanceof SetStatement) {
SetParameterStatementAssert.assertIs(assertContext, (SetStatement) actual, (SetParameterStatementTestCase) expected);
+ } else if (actual instanceof ResetParameterStatement) {
+ ResetParameterStatementAssert.assertIs(assertContext, (ResetParameterStatement) actual, (ResetParameterStatementTestCase) expected);
} else if (actual instanceof MySQLInstallComponentStatement) {
InstallComponentStatementAssert.assertIs(assertContext, (MySQLInstallComponentStatement) actual, (InstallComponentStatementTestCase) expected);
} else if (actual instanceof MySQLFlushStatement) {
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ResetParameterStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ResetParameterStatementAssert.java
new file mode 100644
index 00000000000..2d6022e4a55
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ResetParameterStatementAssert.java
@@ -0,0 +1,45 @@
+/*
+ * 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.asserts.statement.dal.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ResetParameterStatement;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ResetParameterStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Reset parameter statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ResetParameterStatementAssert {
+
+ /**
+ * Assert reset parameter statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual reset parameter statement
+ * @param expected expected reset parameter statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final ResetParameterStatement actual, final ResetParameterStatementTestCase expected) {
+ assertThat(assertContext.getText("Configuration parameter assertion error: "), actual.getConfigurationParameter(), is(expected.getConfigurationParameter()));
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index e1f7bf3a4ce..ba19590001a 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -40,6 +40,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.LoadIndexInfoStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.OptimizeTableStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.RepairTableStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ResetParameterStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ResetPersistStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ResetStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.SetParameterStatementTestCase;
@@ -1209,6 +1210,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "reset-persist")
private final List<ResetPersistStatementTestCase> resetPersistTestCases = new LinkedList<>();
+ @XmlElement(name = "reset-parameter")
+ private final List<ResetParameterStatementTestCase> resetParameterTestCases = new LinkedList<>();
+
@XmlElement(name = "cache-index")
private final List<CacheIndexStatementTestCase> cacheIndexTestCases = new LinkedList<>();
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/dal/PostgreSQLResetParameterStatement.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ResetParameterStatementTestCase.java
similarity index 59%
copy from shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/dal/PostgreSQLResetParameterStatement.java
copy to shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ResetParameterStatementTestCase.java
index eeddec900fd..ed4d92c1514 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/dal/PostgreSQLResetParameterStatement.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ResetParameterStatementTestCase.java
@@ -15,15 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal;
+package org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal;
-import lombok.ToString;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ResetParameterStatement;
-import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlAttribute;
/**
- * PostgreSQL reset parameter statement.
+ * Reset parameter statement test case for PostgreSQL/openGauss.
*/
-@ToString(callSuper = true)
-public final class PostgreSQLResetParameterStatement extends ResetParameterStatement implements PostgreSQLStatement {
+@Getter
+@Setter
+public final class ResetParameterStatementTestCase extends SQLParserTestCase {
+
+ @XmlAttribute(name = "configuration-parameter")
+ private String configurationParameter;
}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml
index b86a59eccdc..f0b6100531c 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/reset.xml
@@ -17,8 +17,8 @@
-->
<sql-parser-test-cases>
- <common sql-case-id="reset_all" />
- <common sql-case-id="reset_timezone" />
+ <reset-parameter sql-case-id="reset_all" configuration-parameter="ALL" />
+ <reset-parameter sql-case-id="reset_timezone" configuration-parameter="timezone" />
<reset sql-case-id="reset_master">
<option master="true" start-index="6" stop-index="11" />
</reset>