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 fe837b2  support parsing Postgre sql `DROP CAST` (#16483)
fe837b2 is described below

commit fe837b2107483545c44a53ddda007d410f5a290c
Author: Everly Precia Suresh <[email protected]>
AuthorDate: Fri Apr 1 06:12:43 2022 +0530

    support parsing Postgre sql `DROP CAST` (#16483)
    
    * add drop cast
    
    * remove trailing space
    
    * correct spelling
    
    * remove empty space
    
    * Delete .gitpod.yml
    
    * rearrange sql cases
    
    * change case ids
---
 .../parser/autogen/PostgreSQLStatementParser.g4    |  1 +
 .../impl/PostgreSQLDDLStatementSQLVisitor.java     |  7 ++++++
 .../core/database/visitor/SQLVisitorRule.java      |  2 ++
 .../common/statement/ddl/DropCastStatement.java    | 28 +++++++++++++++++++++
 .../ddl/PostgreSQLDropCastStatement.java           | 29 ++++++++++++++++++++++
 .../jaxb/cases/domain/SQLParserTestCases.java      |  5 ++++
 .../statement/ddl/DropCastStatementTestCase.java   | 26 +++++++++++++++++++
 .../src/main/resources/case/ddl/drop-cast.xml      | 28 +++++++++++++++++++++
 .../main/resources/sql/supported/ddl/drop-cast.xml | 28 +++++++++++++++++++++
 .../main/resources/sql/unsupported/unsupported.xml |  8 ------
 10 files changed, 154 insertions(+), 8 deletions(-)

diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
index fef68ff..e2476a3 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
@@ -123,6 +123,7 @@ execute
     | dropOperator
     | dropMaterializedView
     | dropGroup
+    | dropCast
     | dropEventTrigger
     | dropAggregate
     ) SEMI_?
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
index 3a5be82..d6dae24 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
@@ -64,6 +64,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Cr
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateViewContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DeallocateContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropCastContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropColumnSpecificationContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropConstraintSpecificationContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropConversionContext;
@@ -169,6 +170,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDeallocateStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDeclareStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDiscardStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropCastStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropConversionStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropDatabaseStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropDomainStatement;
@@ -661,6 +663,11 @@ public final class PostgreSQLDDLStatementSQLVisitor 
extends PostgreSQLStatementS
     public ASTNode visitDeallocate(final DeallocateContext ctx) {
         return new PostgreSQLDeallocateStatement();
     }
+
+    @Override
+    public ASTNode visitDropCast(final DropCastContext ctx) {
+        return new PostgreSQLDropCastStatement();
+    }
         
     @Override
     public ASTNode visitCreateTablespace(final CreateTablespaceContext ctx) {
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 b0d4366..10fd9d4 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
@@ -87,6 +87,8 @@ public enum SQLVisitorRule {
     CREATE_FUNCTION("CreateFunction", SQLStatementType.DDL),
     
     ALTER_FUNCTION("AlterFunction", SQLStatementType.DDL),
+
+    DROP_CAST("DropCast", SQLStatementType.DDL),
     
     DROP_FUNCTION("DropFunction", SQLStatementType.DDL),
     
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/DropCastStatement.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/DropCastStatement.java
new file mode 100644
index 0000000..70b5281
--- /dev/null
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/DropCastStatement.java
@@ -0,0 +1,28 @@
+/*
+ * 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.ToString;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+
+/**
+ * Drop cast statement.
+ */
+@ToString
+public abstract class DropCastStatement extends AbstractSQLStatement 
implements DDLStatement {
+}
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLDropCastStatement.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLDropCastStatement.java
new file mode 100644
index 0000000..36b7078
--- /dev/null
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLDropCastStatement.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.postgresql.ddl;
+
+import lombok.ToString;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropCastStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
+
+/**
+ * PostgreSQL drop cast statement.
+ */
+@ToString
+public final class PostgreSQLDropCastStatement extends DropCastStatement 
implements PostgreSQLStatement {
+}
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 1d2086c..a471014 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
@@ -174,6 +174,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.DropOwnedStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.DropOperatorStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.DropMaterializedViewStatementTestCase;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.DropCastStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.DropAggregateStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AddShardingHintDatabaseValueStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AddShardingHintTableValueStatementTestCase;
@@ -1209,6 +1210,9 @@ public final class SQLParserTestCases {
     @XmlElement(name = "drop-materialized-view")
     private final List<DropMaterializedViewStatementTestCase> 
dropMaterializedViewStatementTestCases = new LinkedList<>();
 
+    @XmlElement(name = "drop-cast")
+    private final List<DropCastStatementTestCase> dropCastStatementTestCases = 
new LinkedList<>();
+    
     @XmlElement(name = "drop-aggregate")
     private final List<DropAggregateStatementTestCase> 
dropAggregateStatementTestCases = new LinkedList<>();
     
@@ -1513,6 +1517,7 @@ public final class SQLParserTestCases {
         putAll(dropOwnedStatementTestCases, result);
         putAll(dropOperatorStatementTestCases, result);
         putAll(dropMaterializedViewStatementTestCases, result);
+        putAll(dropCastStatementTestCases, result);
         putAll(dropAggregateStatementTestCases, result);
         return result;
     }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/DropCastStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/DropCastStatementTestCase.java
new file mode 100644
index 0000000..90758ac
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/DropCastStatementTestCase.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;
+
+/**
+ * Drop cast statement test case.
+ */
+public final class DropCastStatementTestCase extends SQLParserTestCase {
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-cast.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-cast.xml
new file mode 100644
index 0000000..674de51
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/drop-cast.xml
@@ -0,0 +1,28 @@
+<?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>
+    <drop-cast sql-case-id="drop_cast_if_exists_integer_as_no_such_schema" />
+    <drop-cast sql-case-id="drop_cast_if_exists_integer_as_no_such_type2" />
+    <drop-cast sql-case-id="drop_cast_if_exists_no_such_schema_as_integer" />
+    <drop-cast sql-case-id="drop_cast_if_exists_no_such_type1_as_integer" />
+    <drop-cast sql-case-id="drop_cast_if_exists_text_as_text" />
+    <drop-cast sql-case-id="drop_cast_int4_as_casttesttype" />
+    <drop-cast sql-case-id="drop_cast_text_as_casttesttype" />
+    <drop-cast sql-case-id="drop_cast_text_as_text" />
+</sql-parser-test-cases>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-cast.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-cast.xml
new file mode 100644
index 0000000..fe7fe5b
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/drop-cast.xml
@@ -0,0 +1,28 @@
+<?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="drop_cast_if_exists_integer_as_no_such_schema" value="DROP 
CAST IF EXISTS (INTEGER AS no_such_schema.bar);" db-types="PostgreSQL"/>
+    <sql-case id="drop_cast_if_exists_integer_as_no_such_type2" value="DROP 
CAST IF EXISTS (INTEGER AS no_such_type2);" db-types="PostgreSQL"/>
+    <sql-case id="drop_cast_if_exists_no_such_schema_as_integer" value="DROP 
CAST IF EXISTS (no_such_schema.foo AS INTEGER);" db-types="PostgreSQL"/>
+    <sql-case id="drop_cast_if_exists_no_such_type1_as_integer" value="DROP 
CAST IF EXISTS (no_such_type1 AS INTEGER);" db-types="PostgreSQL"/>
+    <sql-case id="drop_cast_if_exists_text_as_text" value="DROP CAST IF EXISTS 
(text AS text);" db-types="PostgreSQL"/>
+    <sql-case id="drop_cast_int4_as_casttesttype" value="DROP CAST (int4 AS 
casttesttype);" db-types="PostgreSQL"/>
+    <sql-case id="drop_cast_text_as_casttesttype" value="DROP CAST (text AS 
casttesttype);" db-types="PostgreSQL"/>
+    <sql-case id="drop_cast_text_as_text" value="DROP CAST (text AS text);" 
db-types="PostgreSQL"/>
+</sql-cases>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
index 35659eb..e1834a5 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
@@ -5534,14 +5534,6 @@
     <sql-case id="drop_by_postgresql_source_test_case4" value="DROP ACCESS 
METHOD heap2;" db-types="PostgreSQL"/>
     <sql-case id="drop_by_postgresql_source_test_case5" value="DROP ACCESS 
METHOD heap_psql;" db-types="PostgreSQL"/>
     <sql-case id="drop_by_postgresql_source_test_case6" value="DROP ACCESS 
METHOD no_such_am;" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case16" value="DROP CAST 
(int4 AS casttesttype);" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case17" value="DROP CAST 
(text AS casttesttype);" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case18" value="DROP CAST 
(text AS text);" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case19" value="DROP CAST IF 
EXISTS (INTEGER AS no_such_schema.bar);" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case20" value="DROP CAST IF 
EXISTS (INTEGER AS no_such_type2);" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case21" value="DROP CAST IF 
EXISTS (no_such_schema.foo AS INTEGER);" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case22" value="DROP CAST IF 
EXISTS (no_such_type1 AS INTEGER);" db-types="PostgreSQL"/>
-    <sql-case id="drop_by_postgresql_source_test_case23" value="DROP CAST IF 
EXISTS (text AS text);" db-types="PostgreSQL"/>
     <sql-case id="drop_by_postgresql_source_test_case24" value="DROP COLLATION 
IF EXISTS no_such_schema.foo;" db-types="PostgreSQL"/>
     <sql-case id="drop_by_postgresql_source_test_case25" value="DROP COLLATION 
IF EXISTS test0;" db-types="PostgreSQL"/>
     <sql-case id="drop_by_postgresql_source_test_case26" value="DROP COLLATION 
IF EXISTS test_collation_exists;" db-types="PostgreSQL"/>

Reply via email to