This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 dccc142 Add MySQL show collation SQL parser. (#13878)
dccc142 is described below
commit dccc142916bbff3b0af65e7be2bacaae0eb3f561
Author: Zonglei Dong <[email protected]>
AuthorDate: Wed Dec 1 15:50:08 2021 +0800
Add MySQL show collation SQL parser. (#13878)
* add ShowFilterSegment, refactor MySQL show open tables SQL parser.
* add ShowFilterSegment test case, refactor MySQL show open tables SQL
parser.
* Add MySQL show collation SQL parser.
* Add MySQL show collation SQL parser test case.
* format code style.
---
.../impl/MySQLDALStatementSQLVisitor.java | 8 +++-
.../core/database/visitor/SQLVisitorRule.java | 4 +-
.../mysql/dal/MySQLShowCollationStatement.java | 46 ++++++++++++++++++++++
.../asserts/statement/dal/DALStatementAssert.java | 5 +++
.../dal/impl/ShowCollationStatementAssert.java | 45 +++++++++++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 5 +++
.../dal/ShowCollationStatementTestCase.java | 36 +++++++++++++++++
.../src/main/resources/case/dal/show.xml | 45 +++++++++++++++++++++
.../src/main/resources/sql/supported/dal/show.xml | 4 ++
9 files changed, 196 insertions(+), 2 deletions(-)
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
index befd4a9..9140b78 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
@@ -153,6 +153,7 @@ import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQ
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowBinaryLogsStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowBinlogStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCharacterSetStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCollationStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowColumnsStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateDatabaseStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateEventStatement;
@@ -741,7 +742,12 @@ public final class MySQLDALStatementSQLVisitor extends
MySQLStatementSQLVisitor
@Override
public ASTNode visitShowCollation(final ShowCollationContext ctx) {
- return new MySQLShowOtherStatement();
+ MySQLShowCollationStatement result = new MySQLShowCollationStatement();
+ if (null != ctx.showFilter()) {
+ result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
+ }
+ result.setParameterCount(getCurrentParameterIndex());
+ return result;
}
@Override
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
index 9a96b96..6194742 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
@@ -236,6 +236,8 @@ public enum SQLVisitorRule {
SHOW_CHARACTER_SET("ShowCharacterSet", SQLStatementType.DAL),
+ SHOW_COLLATION("ShowCollation", SQLStatementType.DAL),
+
SHOW_TABLE_STATUS("ShowTableStatus", SQLStatementType.DAL),
SHOW_COLUMNS("ShowColumns", SQLStatementType.DAL),
@@ -245,7 +247,7 @@ public enum SQLVisitorRule {
SHOW_CREATE_TABLE("ShowCreateTable", SQLStatementType.DAL),
SHOW_OTHER("ShowOther", SQLStatementType.DAL),
-
+
SHOW_REPLICAS("ShowReplicas", SQLStatementType.DAL),
SHOW_REPLICA_STATUS("ShowReplicaStatus", SQLStatementType.DAL),
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowCollationStatement.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowCollationStatement.java
new file mode 100644
index 0000000..5a0c180
--- /dev/null
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowCollationStatement.java
@@ -0,0 +1,46 @@
+/*
+ * 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.sql.dialect.statement.mysql.dal;
+
+import lombok.Setter;
+import lombok.ToString;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowFilterSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
+
+import java.util.Optional;
+
+/**
+ * MySQL show collation statement.
+ */
+@Setter
+@ToString
+public final class MySQLShowCollationStatement extends AbstractSQLStatement
implements DALStatement, MySQLStatement {
+
+ private ShowFilterSegment filter;
+
+ /**
+ * Get filter segment.
+ *
+ * @return filter segment
+ */
+ public Optional<ShowFilterSegment> getFilter() {
+ return Optional.ofNullable(filter);
+ }
+}
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 1637f74..4547af1 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
@@ -41,6 +41,7 @@ import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQ
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLResetStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLRestartStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetResourceGroupStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCollationStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowColumnsStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateTableStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateTriggerStatement;
@@ -89,6 +90,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
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.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.ShowCollationStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.ShowColumnsStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.ShowCreateTableStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.ShowCreateTriggerStatementAssert;
@@ -135,6 +137,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.RestartStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.SetParameterStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.SetResourceGroupStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCollationStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowColumnsStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCreateTableStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCreateTriggerStatementTestCase;
@@ -267,6 +270,8 @@ public final class DALStatementAssert {
MySQLAlterResourceGroupStatementAssert.assertIs(assertContext,
(MySQLAlterResourceGroupStatement) actual,
(AlterResourceGroupStatementTestCase) expected);
} else if (actual instanceof MySQLChecksumTableStatement) {
MySQLChecksumTableStatementAssert.assertIs(assertContext,
(MySQLChecksumTableStatement) actual, (ChecksumTableStatementTestCase)
expected);
+ } else if (actual instanceof MySQLShowCollationStatement) {
+ ShowCollationStatementAssert.assertIs(assertContext,
(MySQLShowCollationStatement) actual, (ShowCollationStatementTestCase)
expected);
}
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowCollationStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowCollationStatementAssert.java
new file mode 100644
index 0000000..0e43112
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowCollationStatementAssert.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.dialect.statement.mysql.dal.MySQLShowCollationStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.show.ShowFilterAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCollationStatementTestCase;
+
+/**
+ * Show collation statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowCollationStatementAssert {
+
+ /**
+ * Assert show collation statement is correct with expected show procedure
code statement test case.
+ *
+ * @param assertContext assert context
+ * @param actual actual show collation statement
+ * @param expected expected show collation statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final MySQLShowCollationStatement actual, final ShowCollationStatementTestCase
expected) {
+ if (actual.getFilter().isPresent()) {
+ ShowFilterAssert.assertIs(assertContext, actual.getFilter().get(),
expected.getFilter());
+ }
+ }
+}
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 3d84ae2..efcb476 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
@@ -42,6 +42,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.SetParameterStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.SetResourceGroupStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCharacterSetStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCollationStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowColumnsStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCreateTableStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowCreateTriggerStatementTestCase;
@@ -812,6 +813,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "show-character-set")
private final List<ShowCharacterSetStatementTestCase>
showCharacterSetStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "show-collation")
+ private final List<ShowCollationStatementTestCase>
showCollationStatementTestCases = new LinkedList<>();
+
/**
* Get all SQL parser test cases.
*
@@ -1014,6 +1018,7 @@ public final class SQLParserTestCases {
putAll(refreshTableMetadataStatementTestCases, result);
putAll(showEventsStatementTestCases, result);
putAll(showCharacterSetStatementTestCases, result);
+ putAll(showCollationStatementTestCases, result);
return result;
}
// CHECKSTYLE:ON
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowCollationStatementTestCase.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowCollationStatementTestCase.java
new file mode 100644
index 0000000..76f7ae5
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowCollationStatementTestCase.java
@@ -0,0 +1,36 @@
+/*
+ * 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.jaxb.cases.domain.statement.dal;
+
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.show.ExpectedShowFilter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * MySQL show collation statement test case.
+ */
+@Getter
+@Setter
+public final class ShowCollationStatementTestCase extends SQLParserTestCase {
+
+ @XmlElement
+ private ExpectedShowFilter filter;
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
index b2d12e4..9952da1 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
@@ -698,4 +698,49 @@
</where>
</filter>
</show-character-set>
+
+ <show-collation sql-case-id="show_collation" />
+
+ <show-collation sql-case-id="show_collation_with_like_pattern">
+ <filter start-index="15" stop-index="27">
+ <like pattern="latin%" start-delimiter="'" end-delimiter="'"
start-index="15" stop-index="27"/>
+ </filter>
+ </show-collation>
+
+ <show-collation sql-case-id="show_collation_with_where_expr"
parameters="'latin1'">
+ <filter start-index="15" stop-index="31" literal-start-index="15"
literal-stop-index="38">
+ <where start-index="15" stop-index="31" literal-start-index="15"
literal-stop-index="38">
+ <expr>
+ <binary-operation-expression start-index="21"
stop-index="31" literal-start-index="21" literal-stop-index="38">
+ <left>
+ <column name="Charset" start-index="21"
stop-index="27" />
+ </left>
+ <operator>=</operator>
+ <right>
+ <literal-expression value="latin1"
start-index="31" stop-index="38" />
+ <parameter-marker-expression value="0"
start-index="31" stop-index="31" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </filter>
+ </show-collation>
+
+ <show-collation sql-case-id="show_collation_with_where_expr_no_parameter">
+ <filter start-index="15" stop-index="38">
+ <where start-index="15" stop-index="38">
+ <expr>
+ <binary-operation-expression start-index="21"
stop-index="38">
+ <left>
+ <column name="Charset" start-index="21"
stop-index="27" />
+ </left>
+ <operator>=</operator>
+ <right>
+ <literal-expression value="latin1"
start-index="31" stop-index="38" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </filter>
+ </show-collation>
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
index afc1769..36523c2 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
@@ -98,4 +98,8 @@
<sql-case id="show_character_set_with_like_pattern" value="SHOW CHARACTER
SET LIKE 'latin%'" db-types="MySQL" />
<sql-case id="show_character_set_with_where_expr" value="SHOW CHARACTER
SET WHERE `Charset` = ?" db-types="MySQL" />
<sql-case id="show_character_set_with_where_expr_no_parameter" value="SHOW
CHARACTER SET WHERE `Charset` = 'latin1'" db-types="MySQL" />
+ <sql-case id="show_collation" value="SHOW COLLATION" db-types="MySQL" />
+ <sql-case id="show_collation_with_like_pattern" value="SHOW COLLATION LIKE
'latin%'" db-types="MySQL" />
+ <sql-case id="show_collation_with_where_expr" value="SHOW COLLATION WHERE
Charset = ?" db-types="MySQL" />
+ <sql-case id="show_collation_with_where_expr_no_parameter" value="SHOW
COLLATION WHERE Charset = 'latin1'" db-types="MySQL" />
</sql-cases>