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/07/15 12:10:16 UTC

[shardingsphere] branch master updated: fix create table generator with no primary key. (#19239)

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 3f3f12f2487 fix create table generator with no primary key. (#19239)
3f3f12f2487 is described below

commit 3f3f12f248749d480114e9d71fcb32e8197c0169
Author: Chuxin Chen <ch...@qq.com>
AuthorDate: Fri Jul 15 20:10:11 2022 +0800

    fix create table generator with no primary key. (#19239)
---
 .../PostgresColumnPropertiesAppender.java          |  2 +-
 .../postgresql/create-table-sql-generator.xml      | 45 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ddlgenerator/PostgresColumnPropertiesAppender.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ddlgenerator/PostgresColumnPropertiesAppe [...]
index fdc70c51e5b..f3d71180ac3 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ddlgenerator/PostgresColumnPropertiesAppender.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ddlgenerator/PostgresColumnPropertiesAppender.java
@@ -147,7 +147,7 @@ public final class PostgresColumnPropertiesAppender extends AbstractPostgresDDLA
     }
     
     private void handlePrimaryColumn(final Map<String, Object> column) {
-        if (column.containsKey("attnum") && column.containsKey("indkey")) {
+        if (null != column.get("attnum") && null != column.get("indkey")) {
             if (Arrays.stream(column.get("indkey").toString().split(" ")).collect(Collectors.toList()).contains(column.get("attnum").toString())) {
                 column.put("is_pk", true);
                 column.put("is_primary_key", true);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/createtablegenerator/postgresql/create-table-sql-generator.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/createtablegenerator/postgresql/create-table-sql-generator.xml
index ea9c4f77d28..cafa99feea2 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/createtablegenerator/postgresql/create-table-sql-generator.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/createtablegenerator/postgresql/create-table-sql-generator.xml
@@ -113,4 +113,49 @@
             </sql>
         </output>
     </create-table-generator-assertion>
+    
+    <create-table-generator-assertion id="t_log">
+        <input table="t_log">
+            <sql>
+                CREATE UNLOGGED TABLE t_log(id int, status varchar(10));
+            </sql>
+        </input>
+        <output version="default">
+            <sql>
+                CREATE UNLOGGED TABLE IF NOT EXISTS public.t_log
+                (
+                id integer
+                ,
+                status character varying(10) COLLATE pg_catalog."default"
+                )
+                TABLESPACE pg_default
+            </sql>
+        </output>
+        <output version="10">
+            <sql>
+                CREATE UNLOGGED TABLE IF NOT EXISTS public.t_log
+                (
+                id integer
+                ,
+                status character varying(10) COLLATE pg_catalog."default"
+                )
+                WITH (
+                OIDS = FALSE)
+                TABLESPACE pg_default
+            </sql>
+        </output>
+        <output version="11">
+            <sql>
+                CREATE UNLOGGED TABLE IF NOT EXISTS public.t_log
+                (
+                id integer
+                ,
+                status character varying(10) COLLATE pg_catalog."default"
+                )
+                WITH (
+                OIDS = FALSE)
+                TABLESPACE pg_default
+            </sql>
+        </output>
+    </create-table-generator-assertion>
 </create-table-generator-assertions>