diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 index 7a35c2a437286..568a20d1a74e1 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 @@ -3397,6 +3397,56 @@ arryDMLSubClause : LP_ typeName (COMMA_ varrayType)? RP_ ; +createMaterializedView + : CREATE MATERIALIZED VIEW materializedViewName (OF typeName )? materializedViewColumnClause? materializedViewPrebuiltClause materializedViewUsingClause? createMvRefresh? (FOR UPDATE)? ( (DISABLE | ENABLE) QUERY REWRITE )? AS selectSubquery + ; + +materializedViewColumnClause + : ( LP_ (scopedTableRefConstraint | mvColumnAlias) (COMMA_ (scopedTableRefConstraint | mvColumnAlias))* RP_ ) + ; + +materializedViewPrebuiltClause + : ( ON PREBUILT TABLE ( (WITH | WITHOUT) REDUCED PRECISION)? | physicalProperties? (CACHE | NOCACHE)? parallelClause? buildClause?) + ; + +materializedViewUsingClause + : ( USING INDEX ( (physicalAttributesClause | TABLESPACE tablespaceName)+ )* | USING NO INDEX) + ; + +mvColumnAlias + : (identifier | quotedString) (ENCRYPT encryptionSpecification)? + ; + +createMvRefresh + : ( NEVER REFRESH | REFRESH createMvRefreshOptions+) + ; + +createMvRefreshOptions + : ( (FAST | COMPLETE | FORCE) | ON (DEMAND | COMMIT) | (START WITH | NEXT) | WITH (PRIMARY KEY | ROWID) | USING ( DEFAULT (MASTER LOCAL)? ROLLBACK SEGMENT | (MASTER | LOCAL)? ROLLBACK SEGMENT rb_segment=REGULAR_ID ) | USING (ENFORCED | TRUSTED) CONSTRAINTS) + ; + +quotedString + : variableName + | CHAR_STRING + | NATIONAL_CHAR_STRING_LIT + ; + +buildClause + : BUILD (IMMEDIATE | DEFERRED) + ; + +createMaterializedViewLog + : CREATE MATERIALIZED VIEW LOG ON tableName materializedViewLogAttribute? parallelClause? ( WITH ( COMMA_? ( OBJECT ID | PRIMARY KEY | ROWID | SEQUENCE | COMMIT SCN ) )* (LP_ ( COMMA_? identifier )+ RP_ newViewValuesClause? )? mvLogPurgeClause? )* + ; + +materializedViewLogAttribute + : ( ( physicalAttributesClause | TABLESPACE tablespaceName | loggingClause | (CACHE | NOCACHE))+ ) + ; + +newViewValuesClause + : (INCLUDING | EXCLUDING ) NEW VALUES + ; + alterMaterializedView : ALTER MATERIALIZED VIEW materializedViewName materializedViewAttribute? alterIotClauses? (USING INDEX physicalAttributesClause)? ((MODIFY scopedTableRefConstraint) | alterMvRefresh)? evaluationEditionClause? diff --git a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 index c8a8306d1238c..92800a99bca57 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 @@ -121,6 +121,8 @@ execute | alterRollbackSegment | alterDiskgroup | alterIndexType + | createMaterializedView + | createMaterializedViewLog | alterMaterializedView | alterMaterializedViewLog | alterFunction diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java index 926dba4f3d2b7..20c623fc534ab 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java @@ -94,6 +94,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateSynonymContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTableContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTablespaceContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewLogContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTypeContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateViewContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DataTypeDefinitionContext; @@ -256,6 +258,8 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateSynonymStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTablespaceStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewLogStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateViewStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateVarrayTypeStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDisassociateStatisticsStatement; @@ -1299,6 +1303,16 @@ public ASTNode visitCreateTablespace(final CreateTablespaceContext ctx) { return new OracleCreateTablespaceStatement(); } + @Override + public ASTNode visitCreateMaterializedView(final CreateMaterializedViewContext ctx) { + return new OracleCreateMaterializedViewStatement(); + } + + @Override + public ASTNode visitCreateMaterializedViewLog(final CreateMaterializedViewLogContext ctx) { + return new OracleCreateMaterializedViewLogStatement(); + } + @Override public ASTNode visitCreateCluster(final CreateClusterContext ctx) { return new OracleCreateClusterStatement(); diff --git a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java index 197fcb86fb8ee..14edbebacd0b8 100644 --- a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java +++ b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java @@ -667,6 +667,8 @@ public enum SQLVisitorRule { CREATE_MATERIALIZED_VIEW("CreateMaterializedView", SQLStatementType.DDL), + CREATE_MATERIALIZED_VIEW_LOG("CreateMaterializedViewLog", SQLStatementType.DDL), + CREATE_OPERATOR("CreateOperator", SQLStatementType.DDL), CREATE_POLICY("CreatePolicy", SQLStatementType.DDL), diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateMaterializedViewLogStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateMaterializedViewLogStatement.java new file mode 100644 index 0000000000000..983760bf84a5a --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateMaterializedViewLogStatement.java @@ -0,0 +1,27 @@ +/* + * 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 org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; + +/** + * Oracle create materialized view log statement. + */ +public final class OracleCreateMaterializedViewLogStatement extends AbstractSQLStatement implements OracleStatement { +} diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateMaterializedViewStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateMaterializedViewStatement.java new file mode 100644 index 0000000000000..c3e1c98549cf8 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateMaterializedViewStatement.java @@ -0,0 +1,27 @@ +/* + * 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 org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateMaterializedViewStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; + +/** + * OracleSQL create materialized view statement. + */ +public final class OracleCreateMaterializedViewStatement extends CreateMaterializedViewStatement implements OracleStatement { +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java index 191e946c8c7af..88821886f53f7 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java @@ -183,6 +183,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateInmemoryJoinGroupStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateLanguageStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateLockdownProfileStatementTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateMaterializedViewLogStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateMaterializedViewStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateOperatorStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreatePFileStatementTestCase; @@ -1666,6 +1667,9 @@ public final class RootSQLParserTestCases { @XmlElement(name = "create-materialized-view") private final List createMaterializedViewStatementTestCases = new LinkedList<>(); + @XmlElement(name = "create-materialized-view-log") + private final List createMaterializedViewLogStatementTestCases = new LinkedList<>(); + @XmlElement(name = "create-operator") private final List createOperatorStatementTestCases = new LinkedList<>(); diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/CreateMaterializedViewLogStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/CreateMaterializedViewLogStatementTestCase.java new file mode 100644 index 0000000000000..7366ded65db4c --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/CreateMaterializedViewLogStatementTestCase.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.it.sql.parser.internal.cases.parser.jaxb.statement.ddl; + +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; + +/** + * Create materialized view statement test case. + */ +public final class CreateMaterializedViewLogStatementTestCase extends SQLParserTestCase { +} diff --git a/test/it/parser/src/main/resources/case/ddl/create-materialized-view-log.xml b/test/it/parser/src/main/resources/case/ddl/create-materialized-view-log.xml new file mode 100644 index 0000000000000..71de1e3127844 --- /dev/null +++ b/test/it/parser/src/main/resources/case/ddl/create-materialized-view-log.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + diff --git a/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml b/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml index ffbdfdded5ffc..20e6f11f15959 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml @@ -22,4 +22,6 @@ + + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view-log.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view-log.xml new file mode 100644 index 0000000000000..0baea22fa2a1e --- /dev/null +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view-log.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml index 3bc8aa4d22e00..1db36d160a45a 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml @@ -22,4 +22,15 @@ + +