diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 index ce03a2599b1c6..327a850c566ef 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 @@ -2058,3 +2058,7 @@ multisetOperator | INTERSECT | UNION ; + +superview + : identifier + ; 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 8078460809a1a..a87aa7a94aa41 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 @@ -19,6 +19,15 @@ grammar DDLStatement; import BaseRule, DCLStatement, DMLStatement; +createView + : CREATE (OR REPLACE)? (NO? FORCE)? (EDITIONING | EDITIONABLE EDITIONING? | NONEDITIONABLE)? VIEW viewName + ( SHARING EQ_ (METADATA | DATA | EXTENDED DATA | NONE))? + ( LP_ (alias (VISIBLE | INVISIBLE)? inlineConstraint* (COMMA_ alias (VISIBLE | INVISIBLE)? inlineConstraint*)* + | outOfLineConstraint) RP_ | objectViewClause | xmlTypeViewClause)? + ( DEFAULT COLLATION collationName)? (BEQUEATH (CURRENT_USER | DEFINER))? AS select subqueryRestrictionClause? + ( CONTAINER_MAP | CONTAINERS_DEFAULT)? + ; + createTable : CREATE createTableSpecification TABLE tableName createSharingClause createDefinitionClause createMemOptimizeClause createParentClause ; @@ -47,6 +56,11 @@ objectTypeDef : OBJECT LP_ dataTypeDefinition (COMMA_ dataTypeDefinition)* RP_ finalClause? instantiableClause? persistableClause? ; +objectViewClause + : OF typeName (WITH OBJECT (IDENTIFIER | ID) (DEFAULT | LP_ attribute (COMMA_ attribute)* RP_) | UNDER (schemaName DOT_)? superview) + ( LP_ outOfLineConstraint | attribute inlineConstraint* (COMMA_ outOfLineConstraint | attribute inlineConstraint*)* RP_)? + ; + finalClause : NOT? FINAL ; @@ -215,6 +229,15 @@ xmlTypeVirtualColumnsClause : VIRTUAL COLUMNS LP_ (columnName AS LP_ expr RP_ (COMMA_ columnName AS LP_ expr RP_)+) RP_ ; +xmlTypeViewClause + : OF XMLTYPE xmlSchemaSpec? WITH OBJECT (IDENTIFIER | ID) (DEFAULT | LP_ expr (COMMA_ expr)* RL_) + ; + +xmlSchemaSpec + : (XMLSCHEMA xmlSchemaURLName)? ELEMENT (elementName | xmlSchemaURLName POUND_ elementName) + ( STORE ALL VARRAYS AS (LOBS | TABLES))? ((ALLOW | DISALLOW) NONSCHEMA)? ((ALLOW | DISALLOW) ANYSCHEMA)? + ; + oidClause : OBJECT IDENTIFIER IS (SYSTEM GENERATED | PRIMARY KEY) ; diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 index 265f7060e62fa..f9d6f4ca486f8 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 @@ -19,6 +19,10 @@ lexer grammar OracleKeyword; import Alphabet; +BEQUEATH + : B E Q U E A T H + ; + BINARY : B I N A R Y ; 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 91b12da4461d4..c8a8306d1238c 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 @@ -24,6 +24,7 @@ execute | insert | update | delete + | createView | createTable | alterTable | dropTable 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 28518b273c850..84357ff0e2a73 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 @@ -95,6 +95,7 @@ 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.CreateViewContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DisassociateStatisticsContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropClusterContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropColumnClauseContext; @@ -179,6 +180,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement; import org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue; import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterAnalyticViewStatement; @@ -248,6 +250,7 @@ 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.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; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropClusterStatement; @@ -301,6 +304,18 @@ */ public final class OracleDDLStatementVisitor extends OracleStatementVisitor implements DDLStatementVisitor { + @Override + public ASTNode visitCreateView(final CreateViewContext ctx) { + OracleCreateViewStatement result = new OracleCreateViewStatement(); + OracleDMLStatementVisitor visitor = new OracleDMLStatementVisitor(); + visitor.getParameterMarkerSegments().addAll(getParameterMarkerSegments()); + result.setView((SimpleTableSegment) visit(ctx.viewName())); + result.setSelect((SelectStatement) visitor.visit(ctx.select())); + result.setViewDefinition(getOriginalText(ctx.select())); + result.addParameterMarkerSegments(getParameterMarkerSegments()); + return result; + } + @SuppressWarnings("unchecked") @Override public ASTNode visitCreateTable(final CreateTableContext ctx) { diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateViewStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateViewStatement.java new file mode 100644 index 0000000000000..603aaa554ba45 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleCreateViewStatement.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.CreateViewStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement; + +/** + * Oracle create view statement. + */ +public final class OracleCreateViewStatement extends CreateViewStatement implements OracleStatement { +} diff --git a/test/it/parser/src/main/resources/case/ddl/create-view.xml b/test/it/parser/src/main/resources/case/ddl/create-view.xml index 5a329c5245555..0d6972b547baf 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-view.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-view.xml @@ -167,4 +167,79 @@ + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-view.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-view.xml index 2a366f0410fff..eec620e4abf10 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/create-view.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-view.xml @@ -24,4 +24,5 @@ +