You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/06/25 12:45:18 UTC
[shardingsphere] branch master updated: Add PostgreSQL Create Cast Statement (#18581)
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 429dadbd858 Add PostgreSQL Create Cast Statement (#18581)
429dadbd858 is described below
commit 429dadbd8588218c6c3f3fb23f75cf21e0253eff
Author: Thanoshan MV <48...@users.noreply.github.com>
AuthorDate: Sat Jun 25 18:15:11 2022 +0530
Add PostgreSQL Create Cast Statement (#18581)
* Add PostgreSQL Create Cast Statement
* Remove useless blank lines
---
.../parser/autogen/PostgreSQLStatementParser.g4 | 1 +
.../impl/PostgreSQLDDLStatementSQLVisitor.java | 7 ++++++
.../ddl/PostgreSQLCreateCastStatement.java | 29 ++++++++++++++++++++++
.../src/main/resources/case/ddl/create-cast.xml | 6 +++++
.../resources/sql/supported/ddl/create-cast.xml | 6 +++++
.../main/resources/sql/unsupported/unsupported.xml | 19 --------------
6 files changed, 49 insertions(+), 19 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 65dfbc003d0..167a16701c8 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
@@ -154,5 +154,6 @@ execute
| createAccessMethod
| alterPublication
| createAggregate
+ | createCast
) SEMI_? EOF
;
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 5479b917162..1ebd2cdec61 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.Co
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CountContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateAccessMethodContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateAggregateContext;
+import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateCastContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateConversionContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDatabaseContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDefinitionClauseContext;
@@ -211,6 +212,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCommentStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateAccessMethodStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateAggregateStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateCastStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateConversionStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateDomainStatement;
@@ -1235,4 +1237,9 @@ public final class PostgreSQLDDLStatementSQLVisitor extends PostgreSQLStatementS
result.setDirectionType(DirectionType.BACKWARD_ALL);
return result;
}
+
+ @Override
+ public ASTNode visitCreateCast(final CreateCastContext ctx) {
+ return new PostgreSQLCreateCastStatement();
+ }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLCreateCastStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLCreateCastStatement.java
new file mode 100644
index 00000000000..e9d9516cfe7
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/postgresql/ddl/PostgreSQLCreateCastStatement.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.CreateCastStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
+
+/**
+ * PostgreSQL create cast statement.
+ */
+@ToString
+public final class PostgreSQLCreateCastStatement extends CreateCastStatement implements PostgreSQLStatement {
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-cast.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-cast.xml
index c5fae477df1..0a9fd0e4824 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-cast.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-cast.xml
@@ -18,4 +18,10 @@
<sql-parser-test-cases>
<create-cast sql-case-id="create_cast" />
+ <create-cast sql-case-id="create_cast_without_function" />
+ <create-cast sql-case-id="create_cast_with_function" />
+ <create-cast sql-case-id="create_cast_with_function_as_implicit" />
+ <create-cast sql-case-id="create_cast_with_inout" />
+ <create-cast sql-case-id="create_cast_without_function_as_implicit" />
+ <create-cast sql-case-id="create_cast_without" />
</sql-parser-test-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-cast.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-cast.xml
index 35ec7eeb737..4bd39ef2dc5 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-cast.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-cast.xml
@@ -18,4 +18,10 @@
<sql-cases>
<sql-case id="create_cast" value="CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint) AS ASSIGNMENT;" db-types="openGauss" />
+ <sql-case id="create_cast_without_function" value="CREATE CAST (bigint AS xfloat8) WITHOUT FUNCTION;" db-types="PostgreSQL" />
+ <sql-case id="create_cast_with_function" value="CREATE CAST (integer AS date) WITH FUNCTION sql_to_date(integer) AS ASSIGNMENT;" db-types="PostgreSQL" />
+ <sql-case id="create_cast_with_function_as_implicit" value="CREATE CAST (int4 AS casttesttype) WITH FUNCTION int4_casttesttype(int4) AS IMPLICIT;" db-types="PostgreSQL" />
+ <sql-case id="create_cast_with_inout" value="CREATE CAST (int4 AS casttesttype) WITH INOUT;" db-types="PostgreSQL" />
+ <sql-case id="create_cast_without_function_as_implicit" value="CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS IMPLICIT;" db-types="PostgreSQL" />
+ <sql-case id="create_cast_without" value="CREATE CAST (text AS casttesttype) WITHOUT FUNCTION;" 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 093d5364aaa..9ceb008761f 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
@@ -3578,10 +3578,6 @@
<sql-case id="alter_by_postgresql_source_test_case459" value="ALTER TYPE test_typex DROP ATTRIBUTE a;" db-types="PostgreSQL" />
<sql-case id="alter_by_postgresql_source_test_case460" value="ALTER TYPE tt_t0 DROP ATTRIBUTE z;" db-types="PostgreSQL" />
<sql-case id="analyze_by_postgresql_source_test_case1" value="ANALYZE (nonexistent-arg) does_not_exist;" db-types="PostgreSQL" />
- <sql-case id="create_by_postgresql_source_test_case100" value="CREATE CAST (int4 AS casttesttype) WITH FUNCTION int4_casttesttype(int4) AS IMPLICIT;" db-types="PostgreSQL" />
- <sql-case id="create_by_postgresql_source_test_case101" value="CREATE CAST (int4 AS casttesttype) WITH INOUT;" db-types="PostgreSQL" />
- <sql-case id="create_by_postgresql_source_test_case102" value="CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS IMPLICIT;" db-types="PostgreSQL" />
- <sql-case id="create_by_postgresql_source_test_case103" value="CREATE CAST (text AS casttesttype) WITHOUT FUNCTION;" db-types="PostgreSQL" />
<sql-case id="create_by_postgresql_source_test_case104" value="CREATE COLLATION case_insensitive (provider = icu, locale = '@colStrength=secondary', deterministic = false);" db-types="PostgreSQL" />
<sql-case id="create_by_postgresql_source_test_case105" value="CREATE COLLATION case_sensitive (provider = icu, locale = '');" db-types="PostgreSQL" />
<sql-case id="create_by_postgresql_source_test_case106" value="CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";" db-types="PostgreSQL" />
@@ -6226,21 +6222,6 @@
<sql-case id="low_alter_by_postgresql_source_test_case105" value="alter type rewritetype alter attribute a type varchar cascade;" db-types="PostgreSQL" />
<sql-case id="low_alter_by_postgresql_source_test_case106" value="alter type testdomain2 rename to testdomain3;" db-types="PostgreSQL" />
<sql-case id="low_alter_by_postgresql_source_test_case107" value="alter type two_ints add attribute c two_ints_range;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case25" value="create cast (bigint as xfloat8) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case26" value="create cast (float4 as xfloat4) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case27" value="create cast (float8 as xfloat8) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case28" value="create cast (int4 as myint) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case29" value="create cast (int8 as int8alias1) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case30" value="create cast (int8 as int8alias2) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case31" value="create cast (int8alias1 as int8) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case32" value="create cast (int8alias2 as int8) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case33" value="create cast (integer as date) with function sql_to_date(integer) as assignment;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case34" value="create cast (integer as xfloat4) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case35" value="create cast (myint as int4) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case36" value="create cast (xfloat4 as float4) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case37" value="create cast (xfloat4 as integer) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case38" value="create cast (xfloat8 as bigint) without function;" db-types="PostgreSQL" />
- <sql-case id="low_create_by_postgresql_source_test_case39" value="create cast (xfloat8 as float8) without function;" db-types="PostgreSQL" />
<sql-case id="low_create_by_postgresql_source_test_case40" value="create constraint trigger parted_trig after insert on parted_constr_ancestor deferrable for each row execute procedure trigger_notice_ab();" db-types="PostgreSQL" />
<sql-case id="low_create_by_postgresql_source_test_case41" value="create constraint trigger parted_trig_two after insert on parted_constr deferrable initially deferred for each row when (bark(new.b) AND new.a % 2 = 1) execute procedure trigger_notice_ab();" db-types="PostgreSQL" />
<sql-case id="low_create_by_postgresql_source_test_case42" value="create constraint trigger parted_trigger after update on parted_trigger from parted_referenced for each row execute procedure trigger_notice_ab();" db-types="PostgreSQL" />