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 efd5e6999a9 Support parsing ALTER MATERIALIZED VIEW LOG in Oracle
(#19391)
efd5e6999a9 is described below
commit efd5e6999a9b5c2ee57ad213d3b33bdb59d3721a
Author: Jiaqi Yan <[email protected]>
AuthorDate: Wed Jul 20 17:00:14 2022 +0800
Support parsing ALTER MATERIALIZED VIEW LOG in Oracle (#19391)
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 5 +-
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 56 ++++++++++++++++++++++
.../main/antlr4/imports/oracle/OracleKeyword.g4 | 16 +++++++
.../sql/parser/autogen/OracleStatement.g4 | 1 +
.../impl/OracleDDLStatementSQLVisitor.java | 7 +++
.../core/database/visitor/SQLVisitorRule.java | 2 +
.../OracleAlterMaterializedViewLogStatement.java | 29 +++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 4 ++
.../AlterMaterializedViewLogStatementTestCase.java | 26 ++++++++++
.../case/ddl/alter-materialized-view-log.xml | 22 +++++++++
.../supported/ddl/alter-materialized-view-log.xml | 24 ++++++++++
11 files changed, 191 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
index 6313d028156..3f62c54e04e 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
@@ -97,7 +97,7 @@ unreservedWord
| SYSGUID | SYSBACKUP | SYSDBA | SYSDG | SYSKM | SYSOPER | DBA_RECYCLEBIN
|SCHEMA
| DO | DEFINER | CURRENT_USER | CASCADED | CLOSE | OPEN | NEXT | NAME |
NAMES
| COLLATION | REAL | TYPE | FIRST | RANK | SAMPLE | SYSTIMESTAMP |
INTERVAL | MINUTE | ANY
- | LENGTH | SINGLE_C | capacityUnit | TARGET | PUBLIC
+ | LENGTH | SINGLE_C | capacityUnit | TARGET | PUBLIC | ID
;
schemaName
@@ -1439,3 +1439,6 @@ varrayType
: (owner DOT_)? name
;
+stagingLogName
+ : identifier
+ ;
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 daedd8de858..8a3412f2f2f 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
@@ -3158,3 +3158,59 @@ unusableBeginning
: UNUSABLE BEGINNING WITH (CURRENT EDITION | EDITION editionName | NULL
EDITION)
;
+alterMaterializedViewLog
+ : ALTER MATERIALIZED VIEW LOG FORCE? ON tableName
+ ( physicalAttributesClause
+ | addMvLogColumnClause
+ | alterTablePartitioning
+ | parallelClause
+ | loggingClause
+ | allocateExtentClause
+ | shrinkClause
+ | moveMvLogClause
+ | CACHE
+ | NOCACHE)? mvLogAugmentation? mvLogPurgeClause? forRefreshClause?
+ ;
+
+addMvLogColumnClause
+ : ADD LP_ columnName RP_
+ ;
+
+moveMvLogClause
+ : MOVE segmentAttributesClause parallelClause?
+ ;
+
+mvLogAugmentation
+ : ADD addClause (COMMA_ addClause)* newValuesClause?
+ ;
+
+addClause
+ : OBJECT ID columns?
+ | PRIMARY KEY columns?
+ | ROWID columns?
+ | SEQUENCE columns?
+ | columns
+ ;
+
+columns
+ : LP_ columnName (COMMA_ columnName)* RP_
+ ;
+
+newValuesClause
+ : (INCLUDING | EXCLUDING) NEW VALUES
+ ;
+
+mvLogPurgeClause
+ : PURGE IMMEDIATE (SYNCHRONOUS | ASYNCHRONOUS)?
+ | START WITH dateValue nextOrRepeatClause?
+ | (START WITH dateValue)? nextOrRepeatClause
+ ;
+
+nextOrRepeatClause
+ : NEXT dateValue | REPEAT INTERVAL intervalExpression
+ ;
+
+forRefreshClause
+ : FOR ((SYNCHRONOUS REFRESH USING stagingLogName) | (FAST REFRESH))
+ ;
+
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 e70db2b1b78..b21ff1f1e1d 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
@@ -2930,3 +2930,19 @@ ENFORCED
TRUSTED
: T R U S T E D
;
+
+ID
+ : I D
+ ;
+
+SYNCHRONOUS
+ : S Y N C H R O N O U S
+ ;
+
+ASYNCHRONOUS
+ : A S Y N C H R O N O U S
+ ;
+
+REPEAT
+ : R E P E A T
+ ;
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 b74fb2928fc..2c6358e6389 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
@@ -117,5 +117,6 @@ execute
| alterDiskgroup
| alterIndexType
| alterMaterializedView
+ | alterMaterializedViewLog
) 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 307200c6614..034e6d9d952 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
@@ -40,6 +40,7 @@ import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterI
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterLibraryContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterJavaContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterMaterializedViewContext;
+import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterMaterializedViewLogContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterMaterializedZonemapContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterOperatorContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterOutlineContext;
@@ -158,6 +159,7 @@ import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.Ora
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterInmemoryJoinGroupStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterJavaStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterLibraryStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterMaterializedViewLogStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterMaterializedViewStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterMaterializedZonemapStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterOperatorStatement;
@@ -941,4 +943,9 @@ public final class OracleDDLStatementSQLVisitor extends
OracleStatementSQLVisito
public ASTNode visitAlterMaterializedView(final
AlterMaterializedViewContext ctx) {
return new OracleAlterMaterializedViewStatement();
}
+
+ @Override
+ public ASTNode visitAlterMaterializedViewLog(final
AlterMaterializedViewLogContext ctx) {
+ return new OracleAlterMaterializedViewLogStatement();
+ }
}
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 adc8697b29f..797948de6de 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
@@ -72,6 +72,8 @@ public enum SQLVisitorRule {
ALTER_MATERIALIZED_VIEW("AlterMaterializedView", SQLStatementType.DDL),
+ ALTER_MATERIALIZED_VIEW_LOG("AlterMaterializedViewLog",
SQLStatementType.DDL),
+
ALTER_OPERATOR("AlterOperator", SQLStatementType.DDL),
DROP_TABLE("DropTable", SQLStatementType.DDL),
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterMaterializedViewLogStatement.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterMaterializedViewLogStatement.java
new file mode 100644
index 00000000000..e4fd1834820
--- /dev/null
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterMaterializedViewLogStatement.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.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+
+/**
+ * Oracle alter materialized view log statement.
+ */
+@ToString(callSuper = true)
+public final class OracleAlterMaterializedViewLogStatement extends
AbstractSQLStatement 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 fbf4b497c21..81d7d9c1a9d 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
@@ -119,6 +119,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.AlterJavaStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterLanguageStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterLibraryStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterMaterializedViewLogStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterMaterializedViewStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterMaterializedZonemapStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterOperatorStatementTestCase;
@@ -1344,6 +1345,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "alter-materialized-view")
private final List<AlterMaterializedViewStatementTestCase>
alterMaterializedViewTestCases = new LinkedList<>();
+ @XmlElement(name = "alter-materialized-view-log")
+ private final List<AlterMaterializedViewLogStatementTestCase>
alterMaterializedViewLogTestCases = new LinkedList<>();
+
@XmlElement(name = "alter-java")
private final List<AlterJavaStatementTestCase> alterJavaTestCases = new
LinkedList<>();
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AlterMaterializedViewLogStatementTestCase.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AlterMaterializedViewLogStatementTestCase.java
new file mode 100644
index 00000000000..da26aa94b95
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AlterMaterializedViewLogStatementTestCase.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 materialized view log statement test case.
+ */
+public final class AlterMaterializedViewLogStatementTestCase extends
SQLParserTestCase {
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-materialized-view-log.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-materialized-view-log.xml
new file mode 100644
index 00000000000..f3f739a21b3
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-materialized-view-log.xml
@@ -0,0 +1,22 @@
+<?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-materialized-view-log
sql-case-id="alter_materialized_view_log_add_rowId" />
+ <alter-materialized-view-log
sql-case-id="alter_materialized_view_log_excluding_new_value" />
+</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-materialized-view-log.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-materialized-view-log.xml
new file mode 100644
index 00000000000..722efc5e888
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-materialized-view-log.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_materialized_view_log_add_rowId" value="ALTER
MATERIALIZED VIEW LOG ON order_items ADD ROWID;" db-types="Oracle"/>
+ <sql-case id="alter_materialized_view_log_excluding_new_value"
value="ALTER MATERIALIZED VIEW LOG ON employees
+ ADD (commission_pct)
+ EXCLUDING NEW VALUES;"
db-types="Oracle"/>
+</sql-cases>