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 0a4f183d2e8 Support PostgreSQL Open statement parse and small ANTLR 
change for PostgreSQL Declare statement (#31396)
0a4f183d2e8 is described below

commit 0a4f183d2e8bd7912d945c9b96846a3e9cf946dd
Author: Thanoshan MV <[email protected]>
AuthorDate: Sun May 26 10:39:09 2024 +0530

    Support PostgreSQL Open statement parse and small ANTLR change for 
PostgreSQL Declare statement (#31396)
    
    * Support PostgreSQL OPEN and small ANTLR change for DECLARE
    
    * Fix checkstyle issues
---
 .../src/main/antlr4/imports/postgresql/BaseRule.g4 |  6 ++-
 .../main/antlr4/imports/postgresql/DDLStatement.g4 | 31 +++++++++-----
 .../antlr4/imports/postgresql/PostgreSQLKeyword.g4 |  4 ++
 .../parser/autogen/PostgreSQLStatementParser.g4    |  1 +
 .../statement/PostgreSQLStatementVisitor.java      |  6 +++
 .../type/PostgreSQLDDLStatementVisitor.java        | 12 +++++-
 .../core/database/visitor/SQLVisitorRule.java      |  4 +-
 .../sql/common/statement/ddl/OpenStatement.java    | 33 +++++++++++++++
 .../postgresql/ddl/PostgreSQLOpenStatement.java    | 27 ++++++++++++
 .../asserts/statement/ddl/DDLStatementAssert.java  |  5 +++
 .../statement/ddl/impl/OpenStatementAssert.java    | 49 ++++++++++++++++++++++
 .../cases/parser/jaxb/RootSQLParserTestCases.java  |  4 ++
 .../jaxb/statement/ddl/OpenStatementTestCase.java  | 36 ++++++++++++++++
 .../it/parser/src/main/resources/case/ddl/open.xml | 35 ++++++++++++++++
 .../src/main/resources/sql/supported/ddl/open.xml  | 24 +++++++++++
 15 files changed, 264 insertions(+), 13 deletions(-)

diff --git 
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4 
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
index 8774b57574b..3f0834c736b 100644
--- 
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
+++ 
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
@@ -549,7 +549,7 @@ patternMatchingOperator
     ;
 
 cursorName
-    : name
+    : name | hostVariable
     ;
 
 aExpr
@@ -1934,3 +1934,7 @@ ifExists
 booleanValue
     : TRUE | ON | FALSE | OFF | NUMBER_
     ;
+
+hostVariable
+    : (COLON_)? identifier
+    ;
diff --git 
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
 
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
index de2ad41bd01..d8e60f672a8 100644
--- 
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
+++ 
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
@@ -1790,21 +1790,32 @@ importQualificationType
     : LIMIT TO | EXCEPT
     ;
 
-
 declare
-    : DECLARE cursorName cursorOptions CURSOR (WITH HOLD | WITHOUT HOLD)? FOR 
select
+    : DECLARE cursorName cursorOption CURSOR ((WITH | WITHOUT) HOLD)? FOR 
select
     ;
 
-cursorOptions
-    : cursorOption*
+cursorOption
+    : BINARY? (ASENSITIVE | INSENSITIVE)? (NO? SCROLL)?
     ;
 
-cursorOption
-    : NO SCROLL
-    | SCROLL
-    | BINARY
-    | ASENSITIVE
-    | INSENSITIVE
+open
+    : OPEN cursorName (usingValueClause | usingSqlDescriptorClause)?
+    ;
+
+usingValueClause
+    : USING value (COMMA_ value)*
+    ;
+
+value
+    : aexprConst | hostVariable
+    ;
+
+usingSqlDescriptorClause
+    : USING SQL DESCRIPTOR descriptorName
+    ;
+
+descriptorName
+    : identifier | hostVariable
     ;
 
 move
diff --git 
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
 
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
index e4601808f04..1177b2f5b45 100644
--- 
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
+++ 
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
@@ -1460,3 +1460,7 @@ NOBYPASSRLS
 ASENSITIVE
     : A S E N S I T I V E
     ;
+
+DESCRIPTOR
+    : D E S C R I P T O R
+    ;
diff --git 
a/parser/sql/dialect/postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
 
b/parser/sql/dialect/postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
index cbd307fe4fb..cd02b9e7361 100644
--- 
a/parser/sql/dialect/postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
+++ 
b/parser/sql/dialect/postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
@@ -181,5 +181,6 @@ execute
     | alterTrigger
     | createPublication
     | emptyStatement
+    | open
     ) SEMI_? EOF
     ;
diff --git 
a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/PostgreSQLStatementVisitor.java
 
b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/PostgreSQLStatementVisitor.java
index b41878c289f..6ed93432cf3 100644
--- 
a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/PostgreSQLStatementVisitor.java
+++ 
b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/PostgreSQLStatementVisitor.java
@@ -56,6 +56,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Fu
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.GroupByItemContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.GroupClauseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.HavingClauseContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.HostVariableContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IdentifierContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.InExprContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexNameContext;
@@ -1392,6 +1393,11 @@ public abstract class PostgreSQLStatementVisitor extends 
PostgreSQLStatementPars
         return visit(ctx.identifier());
     }
     
+    @Override
+    public ASTNode visitHostVariable(final HostVariableContext ctx) {
+        return visit(ctx.identifier());
+    }
+    
     @Override
     public ASTNode visitSignedIconst(final SignedIconstContext ctx) {
         return new NumberLiteralValue(ctx.getText());
diff --git 
a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java
 
b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java
index 9b1cc6670ea..f6b54c68558 100644
--- 
a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java
+++ 
b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java
@@ -159,6 +159,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Na
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameListContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NextContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NotifyStmtContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.OpenContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.PrepareContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.PriorContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RefreshMatViewStmtContext;
@@ -312,6 +313,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLListenStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLMoveStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLNotifyStmtStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLOpenStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLPrepareStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLRefreshMatViewStmtStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLReindexStatement;
@@ -1233,7 +1235,8 @@ public final class PostgreSQLDDLStatementVisitor extends 
PostgreSQLStatementVisi
     
     @Override
     public ASTNode visitCursorName(final CursorNameContext ctx) {
-        return new CursorNameSegment(ctx.start.getStartIndex(), 
ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.name()));
+        return null != ctx.name() ? new 
CursorNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), 
(IdentifierValue) visit(ctx.name()))
+                : new CursorNameSegment(ctx.start.getStartIndex(), 
ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.hostVariable()));
     }
     
     @Override
@@ -1438,4 +1441,11 @@ public final class PostgreSQLDDLStatementVisitor extends 
PostgreSQLStatementVisi
     public ASTNode visitCreatePublication(final CreatePublicationContext ctx) {
         return new PostgreSQLCreatePublicationStatement();
     }
+    
+    @Override
+    public ASTNode visitOpen(final OpenContext ctx) {
+        PostgreSQLOpenStatement result = new PostgreSQLOpenStatement();
+        result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
+        return result;
+    }
 }
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 9f1693db60a..387cfb86215 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
@@ -711,7 +711,9 @@ public enum SQLVisitorRule {
     
     SPOOL("Spool", SQLStatementType.DAL),
     
-    START_REPLICA("StartReplica", SQLStatementType.RL);
+    START_REPLICA("StartReplica", SQLStatementType.RL),
+    
+    OPEN("Open", SQLStatementType.DDL);
     
     private final String name;
     
diff --git 
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/OpenStatement.java
 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/OpenStatement.java
new file mode 100644
index 00000000000..20800e6ab99
--- /dev/null
+++ 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/OpenStatement.java
@@ -0,0 +1,33 @@
+/*
+ * 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.Getter;
+import lombok.Setter;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.CursorNameSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+
+/**
+ * Open statement.
+ */
+@Getter
+@Setter
+public abstract class OpenStatement extends AbstractSQLStatement implements 
DDLStatement {
+    
+    private CursorNameSegment cursorName;
+}
diff --git 
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLOpenStatement.java
 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLOpenStatement.java
new file mode 100644
index 00000000000..9b53b78320c
--- /dev/null
+++ 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLOpenStatement.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.postgresql.ddl;
+
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.OpenStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
+
+/**
+ * PostgreSQL open statement.
+ */
+public final class PostgreSQLOpenStatement extends OpenStatement implements 
PostgreSQLStatement {
+}
diff --git 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/DDLStatementAssert.java
 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/DDLStatementAssert.java
index b96179642dc..afbc690ee5f 100644
--- 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/DDLStatementAssert.java
+++ 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/DDLStatementAssert.java
@@ -40,6 +40,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.FetchStatem
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.ListenStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.MoveStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.NotifyStmtStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.OpenStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.RefreshMatViewStmtStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.ReindexStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.RenameTableStatement;
@@ -84,6 +85,7 @@ import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.d
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl.MoveStatementAssert;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl.NoAuditStatementAssert;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl.NotifyStmtStatementAssert;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl.OpenStatementAssert;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl.RefreshMatViewStmtStatementAssert;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl.ReindexStatementAssert;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl.RenameTableStatementAssert;
@@ -120,6 +122,7 @@ import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.MoveStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.NoAuditStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.NotifyStmtStatementTestCase;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.OpenStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.RefreshMatViewStmtStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.ReindexStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.RenameTableStatementTestCase;
@@ -212,6 +215,8 @@ public final class DDLStatementAssert {
             CreateSequenceStatementAssert.assertIs(assertContext, 
(CreateSequenceStatement) actual, (CreateSequenceStatementTestCase) expected);
         } else if (actual instanceof SQLServerUpdateStatisticsStatement) {
             SQLServerUpdateStatisticsStatementAssert.assertIs(assertContext, 
(SQLServerUpdateStatisticsStatement) actual, 
(UpdateStatisticsStatementTestCase) expected);
+        } else if (actual instanceof OpenStatement) {
+            OpenStatementAssert.assertIs(assertContext, (OpenStatement) 
actual, (OpenStatementTestCase) expected);
         }
     }
 }
diff --git 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/OpenStatementAssert.java
 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/OpenStatementAssert.java
new file mode 100644
index 00000000000..31ea1c99797
--- /dev/null
+++ 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/OpenStatementAssert.java
@@ -0,0 +1,49 @@
+/*
+ * 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.asserts.statement.ddl.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.OpenStatement;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.SQLSegmentAssert;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.identifier.IdentifierValueAssert;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.OpenStatementTestCase;
+
+/**
+ * Open statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class OpenStatementAssert {
+    
+    /**
+     * Assert open statement is correct with expected parser result.
+     *
+     * @param assertContext assert context
+     * @param actual actual declare statement
+     * @param expected expected declare statement test case
+     */
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final OpenStatement actual, final OpenStatementTestCase expected) {
+        assertCursorName(assertContext, actual, expected);
+    }
+    
+    private static void assertCursorName(final SQLCaseAssertContext 
assertContext, final OpenStatement actual, final OpenStatementTestCase 
expected) {
+        IdentifierValueAssert.assertIs(assertContext, 
actual.getCursorName().getIdentifier(), expected.getCursorName(), "Cursor");
+        SQLSegmentAssert.assertIs(assertContext, actual.getCursorName(), 
expected.getCursorName());
+    }
+}
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 4b3e7ecb78f..17a8bc58e00 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
@@ -282,6 +282,7 @@ import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.MoveStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.NoAuditStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.NotifyStmtStatementTestCase;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.OpenStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.PreparedStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.PurgeStatementTestCase;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.RefreshMatViewStmtStatementTestCase;
@@ -1757,6 +1758,9 @@ public final class RootSQLParserTestCases {
     @XmlElement(name = "create-outline")
     private final List<CreateOutlineStatementTestCase> 
createOutlineStatementTestCases = new LinkedList<>();
     
+    @XmlElement(name = "open")
+    private final List<OpenStatementTestCase> openTestCases = new 
LinkedList<>();
+    
     /**
      * Get all SQL parser test cases.
      *
diff --git 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/OpenStatementTestCase.java
 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/OpenStatementTestCase.java
new file mode 100644
index 00000000000..e8dcb6fe729
--- /dev/null
+++ 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/OpenStatementTestCase.java
@@ -0,0 +1,36 @@
+/*
+ * 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 lombok.Getter;
+import lombok.Setter;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.cursor.ExpectedCursorName;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * Open statement test case.
+ */
+@Getter
+@Setter
+public final class OpenStatementTestCase extends SQLParserTestCase {
+    
+    @XmlElement(name = "cursor-name")
+    private ExpectedCursorName cursorName;
+}
diff --git a/test/it/parser/src/main/resources/case/ddl/open.xml 
b/test/it/parser/src/main/resources/case/ddl/open.xml
new file mode 100644
index 00000000000..4cef3c63db0
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/ddl/open.xml
@@ -0,0 +1,35 @@
+<?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>
+    <open sql-case-id="open_cursor">
+        <cursor-name name="t_order_cursor" start-index="5" stop-index="18" />
+    </open>
+
+    <open sql-case-id="open_cursor_using">
+        <cursor-name name="t_order_cursor" start-index="5" stop-index="18" />
+    </open>
+
+    <open sql-case-id="open_cursor_using_sql">
+        <cursor-name name="t_order_cursor" start-index="5" stop-index="18" />
+    </open>
+
+    <open sql-case-id="open_cursor_with_host_variable">
+        <cursor-name name="t_order_cursor" start-index="5" stop-index="19" />
+    </open>
+</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/open.xml 
b/test/it/parser/src/main/resources/sql/supported/ddl/open.xml
new file mode 100644
index 00000000000..67eaa604869
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/open.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="open_cursor" value="OPEN t_order_cursor" 
db-types="PostgreSQL" />
+    <sql-case id="open_cursor_using" value="OPEN t_order_cursor USING 1, 
'test'" db-types="PostgreSQL" />
+    <sql-case id="open_cursor_using_sql" value="OPEN t_order_cursor USING SQL 
DESCRIPTOR mydesc" db-types="PostgreSQL" />
+    <sql-case id="open_cursor_with_host_variable" value="OPEN :t_order_cursor" 
db-types="PostgreSQL" />
+</sql-cases>

Reply via email to