This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 fb3b4893c4f Support parsing ALTER OPERATOR in Oracle (#19119)
fb3b4893c4f is described below
commit fb3b4893c4f4ceafc385897d8cc61a60989e220e
Author: Jiaqi Yan <[email protected]>
AuthorDate: Thu Jul 14 00:58:02 2022 +0800
Support parsing ALTER OPERATOR in Oracle (#19119)
* support ALTER OPERATOR statement for Oracle
* update alterOperator clause
* add end blank line
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 8 +++++
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 37 ++++++++++++++++++++++
.../main/antlr4/imports/oracle/OracleKeyword.g4 | 16 ++++++++++
.../sql/parser/autogen/OracleStatement.g4 | 1 +
.../impl/OracleDDLStatementSQLVisitor.java | 7 ++++
.../oracle/ddl/OracleAlterOperatorStatement.java | 29 +++++++++++++++++
.../src/main/resources/case/ddl/alter-operator.xml | 1 +
.../resources/sql/supported/ddl/alter-operator.xml | 1 +
8 files changed, 100 insertions(+)
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 d0b96917d6f..fc93266f900 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
@@ -1317,3 +1317,11 @@ libraryName
matchString
: IDENTIFIER_ | ASTERISK_
;
+
+parameterType
+ : identifier
+ ;
+
+returnType
+ : 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 c9819ca215f..178d74d1f0d 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
@@ -2744,3 +2744,40 @@ alterCluster
| deallocateUnusedClause
| (CACHE | NOCACHE))+ (parallelClause)?
;
+
+alterOperator
+ : ALTER OPERATOR operatorName (addBindingClause | dropBindingClause |
COMPILE)
+ ;
+
+addBindingClause
+ : ADD BINDING LP_ parameterType (COMMA_ parameterType)* RP_
+ RETURN LP_ returnType RP_ implementationClause? usingFunctionClause
+ ;
+
+implementationClause
+ : (ANCILLARY TO primaryOperatorClause (COMMA_ primaryOperatorClause)*) |
contextClauseWithOpeartor
+ ;
+
+primaryOperatorClause
+ : operatorName LP_ parameterType (COMMA_ parameterType)* RP_
+ ;
+
+contextClauseWithOpeartor
+ : withIndexClause? withColumnClause?
+ ;
+
+withIndexClause
+ : WITH INDEX CONTEXT COMMA_ SCAN CONTEXT implementationType (COMPUTE
ANCILLARY DATA)?
+ ;
+
+withColumnClause
+ : WITH COLUMN CONTEXT
+ ;
+
+usingFunctionClause
+ : USING (packageName DOT_ | typeName DOT_)? functionName
+ ;
+
+dropBindingClause
+ : DROP BINDING LP_ parameterType (COMMA_ parameterType)* RP_ FORCE?
+ ;
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 11b933cb7c9..970231b175a 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
@@ -2858,3 +2858,19 @@ SHARE
EXCLUSIVE
: E X C L U S I V E
;
+
+ANCILLARY
+ : A N C I L L A R Y
+ ;
+
+BINDING
+ : B I N D I N G
+ ;
+
+SCAN
+ : S C A N
+ ;
+
+COMPUTE
+ : C O M P U T E
+ ;
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 5881d18a815..10c8fbcf8c6 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
@@ -113,5 +113,6 @@ execute
| alterJava
| alterAuditPolicy
| alterCluster
+ | alterOperator
) 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 855d899f96c..bc3eb6d75d6 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
@@ -38,6 +38,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.AlterMaterializedZonemapContext;
+import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterOperatorContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterOutlineContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterPackageContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSequenceContext;
@@ -153,6 +154,7 @@ import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.Ora
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.OracleAlterMaterializedZonemapStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterOperatorStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterOutlineStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterPackageStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSequenceStatement;
@@ -884,6 +886,11 @@ public final class OracleDDLStatementSQLVisitor extends
OracleStatementSQLVisito
return new OracleDropRestorePointStatement();
}
+ @Override
+ public ASTNode visitAlterOperator(final AlterOperatorContext ctx) {
+ return new OracleAlterOperatorStatement();
+ }
+
@Override
public ASTNode visitDropOperator(final DropOperatorContext ctx) {
return new OracleDropOperatorStatement();
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterOperatorStatement.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterOperatorStatement.java
new file mode 100644
index 00000000000..92f992b121a
--- /dev/null
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAlterOperatorStatement.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.AlterOperatorStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+
+/**
+ * Oracle alter operator statement.
+ */
+@ToString
+public final class OracleAlterOperatorStatement extends AlterOperatorStatement
implements OracleStatement {
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-operator.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-operator.xml
index 6e561f8b805..c472f58711f 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-operator.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-operator.xml
@@ -21,4 +21,5 @@
<alter-operator sql-case-id="alter_operator_set_schema" />
<alter-operator sql-case-id="alter_operator_set" />
<alter-operator sql-case-id="alter_operator_set_restrict_join" />
+ <alter-operator sql-case-id="alter_operator_compile" />
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-operator.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-operator.xml
index 2312a332415..6d133915790 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-operator.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-operator.xml
@@ -21,4 +21,5 @@
<sql-case id="alter_operator_set_schema" value="ALTER OPERATOR @+@(int4,
int4) SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
<sql-case id="alter_operator_set" value="ALTER OPERATOR === (boolean,
boolean) SET (RESTRICT = non_existent_func);" db-types="PostgreSQL" />
<sql-case id="alter_operator_set_restrict_join" value="ALTER OPERATOR ===
(boolean, boolean) SET (RESTRICT = customcontsel, JOIN = contjoinsel);"
db-types="PostgreSQL" />
+ <sql-case id="alter_operator_compile" value="ALTER OPERATOR eq_op
COMPILE;" db-types="Oracle" />
</sql-cases>