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 7ea9273 Support binlog statement for mysql. (#13224)
7ea9273 is described below
commit 7ea92732f0195d960b296b3f0fad15abe8d6d5f9
Author: tuichenchuxin <[email protected]>
AuthorDate: Mon Oct 25 08:27:27 2021 +0800
Support binlog statement for mysql. (#13224)
* Support binlog statement.
* Support binlog statement.
* Support binlog statement.
---
.../impl/MySQLDALStatementSQLVisitor.java | 7 ++++
.../core/database/visitor/SQLVisitorRule.java | 2 +
.../statement/mysql/dal/MySQLBinlogStatement.java | 36 +++++++++++++++++
.../asserts/statement/dal/DALStatementAssert.java | 5 +++
.../dal/impl/MySQLBinlogStatementAssert.java | 45 ++++++++++++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 7 +++-
.../statement/dal/BinlogStatementTestCase.java | 33 ++++++++++++++++
.../src/main/resources/case/dal/binlog.xml | 21 ++++++++++
.../main/resources/sql/supported/dal/binlog.xml | 21 ++++++++++
9 files changed, 176 insertions(+), 1 deletion(-)
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 8d495b2..dca7c75 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
@@ -83,6 +83,7 @@ import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.Uninsta
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UseContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UserVariableContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.VariableContext;
+import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BinlogContext;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromSchemaSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowLikeSegment;
@@ -97,6 +98,7 @@ import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.Identifi
import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue;
import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLAnalyzeTableStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLBinlogStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCacheIndexStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLChecksumTableStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCloneStatement;
@@ -453,6 +455,11 @@ public final class MySQLDALStatementSQLVisitor extends
MySQLStatementSQLVisitor
}
@Override
+ public ASTNode visitBinlog(final BinlogContext ctx) {
+ return new MySQLBinlogStatement(((StringLiteralValue)
visit(ctx.stringLiterals())).getValue());
+ }
+
+ @Override
public ASTNode visitFromTable(final FromTableContext ctx) {
FromTableSegment result = new FromTableSegment();
result.setTable((SimpleTableSegment) visit(ctx.tableName()));
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 24315e8..9047392 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
@@ -272,6 +272,8 @@ public enum SQLVisitorRule {
SET_RESOURCE_GROUP("SetResourceGroup", SQLStatementType.DAL),
+ BINLOG("Binlog", SQLStatementType.DAL),
+
OPTIMIZE_TABLE("OptimizeTable", SQLStatementType.DAL),
CLONE("Clone", 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/MySQLBinlogStatement.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLBinlogStatement.java
new file mode 100644
index 0000000..c96d86d
--- /dev/null
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLBinlogStatement.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.sql.parser.sql.dialect.statement.mysql.dal;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+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;
+
+/**
+ * MySQL binlog statement.
+ */
+@Getter
+@ToString
+@RequiredArgsConstructor
+public final class MySQLBinlogStatement extends AbstractSQLStatement
implements DALStatement, MySQLStatement {
+
+ private final String base64Str;
+}
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 3b75f07..7913cee 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
@@ -22,6 +22,7 @@ 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.SetStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLBinlogStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCloneStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCreateResourceGroupStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLFlushStatement;
@@ -48,6 +49,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.FlushStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.InstallComponentStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.InstallPluginStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.MySQLBinlogStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.MySQLCreateResourceGroupStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.MySQLOptimizeTableStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.MySQLRepairTableStatementAssert;
@@ -66,6 +68,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.UninstallComponentStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl.UninstallPluginStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.BinlogStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.CloneStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.CreateResourceGroupStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ExplainStatementTestCase;
@@ -147,6 +150,8 @@ public final class DALStatementAssert {
MySQLOptimizeTableStatementAssert.assertIs(assertContext,
(MySQLOptimizeTableStatement) actual, (OptimizeTableStatementTestCase)
expected);
} else if (actual instanceof MySQLRepairTableStatement) {
MySQLRepairTableStatementAssert.assertIs(assertContext,
(MySQLRepairTableStatement) actual, (RepairTableStatementTestCase) expected);
+ } else if (actual instanceof MySQLBinlogStatement) {
+ MySQLBinlogStatementAssert.assertIs(assertContext,
(MySQLBinlogStatement) actual, (BinlogStatementTestCase) expected);
}
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/MySQLBinlogStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/MySQLBinlogStatementAssert.java
new file mode 100644
index 0000000..e085757
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/MySQLBinlogStatementAssert.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.MySQLBinlogStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.BinlogStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * MySQL binlog statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MySQLBinlogStatementAssert {
+
+ /**
+ * Assert binlog statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual binlog statement
+ * @param expected expected binlog statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final MySQLBinlogStatement actual, final BinlogStatementTestCase expected) {
+ assertThat(assertContext.getText("Binlog statement context does not
match: "), actual.getBase64Str(), is(expected.getBase64Str()));
+ }
+}
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 ab3a5b4..2c9abe4 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
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.CommonStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.BinlogStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.CloneStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.CreateResourceGroupStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ExplainStatementTestCase;
@@ -318,7 +319,10 @@ public final class SQLParserTestCases {
@XmlElement(name = "create-resource-group")
private final List<CreateResourceGroupStatementTestCase>
createResourceGroupStatementTestCases = new LinkedList<>();
-
+
+ @XmlElement(name = "binlog")
+ private final List<BinlogStatementTestCase> binlogStatementTestCases = new
LinkedList<>();
+
@XmlElement(name = "show-create-user")
private final List<ShowCreateUserStatementTestCase>
showCreateUserTestCases = new LinkedList<>();
@@ -822,6 +826,7 @@ public final class SQLParserTestCases {
putAll(showReadwriteSplittingReadResourcesStatementTestCases, result);
putAll(uninstallComponentStatementTestCases, result);
putAll(createResourceGroupStatementTestCases, result);
+ putAll(binlogStatementTestCases, result);
putAll(uninstallPluginStatementTestCases, result);
putAll(showSingleTableRulesStatementTestCases, result);
putAll(setResourceGroupStatementTestCases, result);
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/BinlogStatementTestCase.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/BinlogStatementTestCase.java
new file mode 100644
index 0000000..8138dff
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/BinlogStatementTestCase.java
@@ -0,0 +1,33 @@
+/*
+ * 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
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * Binlog statement test case.
+ */
+@Getter
+public final class BinlogStatementTestCase extends SQLParserTestCase {
+
+ @XmlAttribute
+ private String base64Str;
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/binlog.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/binlog.xml
new file mode 100644
index 0000000..ffb9c73
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/binlog.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<sql-parser-test-cases>
+ <binlog sql-case-id="binlog"
base64Str="kZRKYQ8BAAAAeQAAAH0AAAAAAAQAOC4wLjI1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACRlEphEwANAAgAAAAABAAEAAAAYQAEGggAAAAICAgCAAAACgoKKioAEjQACigBa5E9fA=="
/>
+</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/binlog.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/binlog.xml
new file mode 100644
index 0000000..9a35c69
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/binlog.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<sql-cases>
+ <sql-case id="binlog" value="BINLOG
'kZRKYQ8BAAAAeQAAAH0AAAAAAAQAOC4wLjI1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACRlEphEwANAAgAAAAABAAEAAAAYQAEGggAAAAICAgCAAAACgoKKioAEjQACigBa5E9fA=='"
db-types="MySQL" />
+</sql-cases>