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 b7ec12de003 Support parsing `ALTER OUTLINE` in Oracle (#17514) b7ec12de003 is described below commit b7ec12de003096ded9c8d0efaa477714c21bb1a2 Author: JackieYan <1301826...@qq.com> AuthorDate: Tue May 10 17:26:32 2022 +0800 Support parsing `ALTER OUTLINE` in Oracle (#17514) * Support parsing ALTER OUTLINE in Oracle * Support parsing ALTER OUTLINE in Oracle * Support parsing ALTER OUTLINE in Oracle --- .../src/main/antlr4/imports/oracle/DDLStatement.g4 | 9 +++++++ .../main/antlr4/imports/oracle/OracleKeyword.g4 | 4 +++ .../sql/parser/autogen/OracleStatement.g4 | 1 + .../impl/OracleDDLStatementSQLVisitor.java | 7 ++++++ .../core/database/visitor/SQLVisitorRule.java | 4 ++- .../statement/ddl/AlterOutlineStatement.java | 28 +++++++++++++++++++++ .../oracle/ddl/OracleAlterOutlineStatement.java | 29 ++++++++++++++++++++++ .../jaxb/cases/domain/SQLParserTestCases.java | 7 +++++- .../ddl/AlterOutlineStatementTestCase.java | 26 +++++++++++++++++++ .../src/main/resources/case/ddl/alter-outline.xml | 24 ++++++++++++++++++ .../resources/sql/supported/ddl/alter-outline.xml | 24 ++++++++++++++++++ 11 files changed, 161 insertions(+), 2 deletions(-) diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 index e5359f872d4..19a350a5cff 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 @@ -84,6 +84,15 @@ dropOutline : DROP OUTLINE outlineName ; +alterOutline + : ALTER OUTLINE (PUBLIC | PRIVATE)? outlineName + ( REBUILD + | RENAME TO outlineName + | CHANGE CATEGORY TO categoryName + | (ENABLE | DISABLE) + )+ + ; + truncateTable : TRUNCATE TABLE tableName materializedViewLogClause? dropReuseClause? CASCADE? ; diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 index 700d736b0ee..f12504d44e4 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 @@ -2714,3 +2714,7 @@ SINGLE_C SYSTIMESTAMP : S Y S T I M E S T A M P ; + +CATEGORY + : C A T E G O R Y + ; diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 index 931740c6797..7a4cb778fd4 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 @@ -82,5 +82,6 @@ execute | dropPackage | dropEdition | dropOutline + | alterOutline ) SEMI_? ; diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java index f8e3843098d..49bceb72a15 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java @@ -46,6 +46,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.Create import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropEditionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropOutlineContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterOutlineContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateIndexContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTableContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateEditionContext; @@ -124,6 +125,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.Ora import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateFunctionStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropEditionStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropOutlineStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterOutlineStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateEditionStatement; @@ -692,4 +694,9 @@ public final class OracleDDLStatementSQLVisitor extends OracleStatementSQLVisito public ASTNode visitDropOutline(final DropOutlineContext ctx) { return new OracleDropOutlineStatement(); } + + @Override + public ASTNode visitAlterOutline(final AlterOutlineContext ctx) { + return new OracleAlterOutlineStatement(); + } } 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 f200f1743e7..ea83d22ffb7 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 @@ -497,7 +497,9 @@ public enum SQLVisitorRule { DROP_ACCESS_METHOD("DropAccessMethod", SQLStatementType.DDL), DROP_OUTLINE("DropOutline", SQLStatementType.DDL), - + + ALTER_OUTLINE("AlterOutline", SQLStatementType.DDL), + DROP_EDITION("DropEdition", SQLStatementType.DDL); private final String name; diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterOutlineStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterOutlineStatement.java new file mode 100644 index 00000000000..87518d7c725 --- /dev/null +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterOutlineStatement.java @@ -0,0 +1,28 @@ +/* + * 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.common.statement.ddl; + +import lombok.ToString; +import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement; + +/** + * Alter outline statement. + */ +@ToString +public abstract class AlterOutlineStatement extends AbstractSQLStatement implements DDLStatement { +} diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterOutlineStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterOutlineStatement.java new file mode 100644 index 00000000000..5d84af4d8f4 --- /dev/null +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterOutlineStatement.java @@ -0,0 +1,29 @@ +/* + * 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.oracle.ddl; + +import lombok.ToString; +import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterOutlineStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; + +/** + * Oracle alter outline statement. + */ +@ToString +public final class OracleAlterOutlineStatement extends AlterOutlineStatement implements OracleStatement { +} 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 e69a5f1d0e9..f2c4715a1b9 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 @@ -201,6 +201,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.TruncateStatementTestCase; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.DropEditionStatementTestCase; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.DropOutlineStatementTestCase; +import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterOutlineStatementTestCase; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AddShardingHintDatabaseValueStatementTestCase; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AddShardingHintTableValueStatementTestCase; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterInstanceStatementTestCase; @@ -394,7 +395,10 @@ public final class SQLParserTestCases { @XmlElement(name = "drop-outline") private final List<DropOutlineStatementTestCase> dropOutlineTestCases = new LinkedList<>(); - + + @XmlElement(name = "alter-outline") + private final List<AlterOutlineStatementTestCase> alterOutlineTestCases = new LinkedList<>(); + @XmlElement(name = "create-index") private final List<CreateIndexStatementTestCase> createIndexTestCases = new LinkedList<>(); @@ -1336,6 +1340,7 @@ public final class SQLParserTestCases { putAll(truncateTestCases, result); putAll(dropEditionTestCases, result); putAll(dropOutlineTestCases, result); + putAll(alterOutlineTestCases, result); putAll(createIndexTestCases, result); putAll(alterIndexTestCases, result); putAll(dropIndexTestCases, result); diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AlterOutlineStatementTestCase.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AlterOutlineStatementTestCase.java new file mode 100644 index 00000000000..c6e19cb529f --- /dev/null +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AlterOutlineStatementTestCase.java @@ -0,0 +1,26 @@ +/* + * 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.ddl; + +import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase; + +/** + * Alter outline test case. + */ +public final class AlterOutlineStatementTestCase extends SQLParserTestCase { +} diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-outline.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-outline.xml new file mode 100644 index 00000000000..2d956beaf4c --- /dev/null +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-outline.xml @@ -0,0 +1,24 @@ +<?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> + <alter-outline sql-case-id="alter_outline_rebuild" /> + <alter-outline sql-case-id="alter_outline_rename" /> + <alter-outline sql-case-id="alter_outline_change_category" /> + <alter-outline sql-case-id="alter_outline_disable" /> +</sql-parser-test-cases> diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-outline.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-outline.xml new file mode 100644 index 00000000000..ea148e0051f --- /dev/null +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-outline.xml @@ -0,0 +1,24 @@ +<?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="alter_outline_rebuild" value="ALTER OUTLINE salaries REBUILD;" db-types="Oracle" /> + <sql-case id="alter_outline_rename" value="ALTER OUTLINE salaries RENAME TO salary;" db-types="Oracle" /> + <sql-case id="alter_outline_change_category" value="ALTER OUTLINE salary CHANGE CATEGORY TO base;" db-types="Oracle" /> + <sql-case id="alter_outline_disable" value="ALTER OUTLINE salaries DISABLE;" db-types="Oracle" /> +</sql-cases>