This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 82228358b94 [Fix](nereids) fix create view with nullable column 
(#41234) (#41393)
82228358b94 is described below

commit 82228358b943d42b7775de00c5ead7566393e6b5
Author: feiniaofeiafei <53502832+feiniaofeia...@users.noreply.github.com>
AuthorDate: Fri Sep 27 19:13:54 2024 +0800

    [Fix](nereids) fix create view with nullable column (#41234) (#41393)
    
    cherry-pick from master #41234
---
 .../trees/plans/commands/info/BaseViewInfo.java    |  5 ++-
 .../data/correctness/test_view_varchar_length.out  |  2 +-
 .../data/ddl_p0/test_create_view_nereids.out       | 10 +++++
 .../suites/ddl_p0/test_create_view_nereids.groovy  | 47 ++++++++++++++++++++++
 4 files changed, 61 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
index 0cbaa167fdf..7d24e99b890 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java
@@ -152,7 +152,8 @@ public class BaseViewInfo {
     protected void createFinalCols(List<Slot> outputs) throws 
org.apache.doris.common.AnalysisException {
         if (simpleColumnDefinitions.isEmpty()) {
             for (Slot output : outputs) {
-                Column column = new Column(output.getName(), 
output.getDataType().toCatalogDataType());
+                Column column = new Column(output.getName(), 
output.getDataType().toCatalogDataType(),
+                        output.nullable());
                 finalCols.add(column);
             }
         } else {
@@ -161,7 +162,7 @@ public class BaseViewInfo {
             }
             for (int i = 0; i < simpleColumnDefinitions.size(); ++i) {
                 Column column = new 
Column(simpleColumnDefinitions.get(i).getName(),
-                        outputs.get(i).getDataType().toCatalogDataType());
+                        outputs.get(i).getDataType().toCatalogDataType(), 
outputs.get(i).nullable());
                 column.setComment(simpleColumnDefinitions.get(i).getComment());
                 finalCols.add(column);
             }
diff --git a/regression-test/data/correctness/test_view_varchar_length.out 
b/regression-test/data/correctness/test_view_varchar_length.out
index e53fe9ff97f..dd5128a3118 100644
--- a/regression-test/data/correctness/test_view_varchar_length.out
+++ b/regression-test/data/correctness/test_view_varchar_length.out
@@ -1,4 +1,4 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
 -- !sql --
-name   varchar(32)     No      false   \N      
+name   varchar(32)     Yes     false   \N      
 
diff --git a/regression-test/data/ddl_p0/test_create_view_nereids.out 
b/regression-test/data/ddl_p0/test_create_view_nereids.out
index 8ee98fa7021..4cac00352a9 100644
--- a/regression-test/data/ddl_p0/test_create_view_nereids.out
+++ b/regression-test/data/ddl_p0/test_create_view_nereids.out
@@ -363,3 +363,13 @@ test_having        CREATE VIEW `test_having` AS select 
sum(`internal`.`regression_test_
 -- !complicated_view1_sql --
 test_view_complicated  CREATE VIEW `test_view_complicated` AS SELECT 
`internal`.`regression_test_ddl_p0`.`t`.`id`, 
`internal`.`regression_test_ddl_p0`.`t`.`value3`, `t`.`row_num` FROM (\n        
SELECT `internal`.`regression_test_ddl_p0`.`t1`.`id`, 
`internal`.`regression_test_ddl_p0`.`tt`.`value3`, ROW_NUMBER() OVER (PARTITION 
BY `internal`.`regression_test_ddl_p0`.`t1`.`id` ORDER BY 
`internal`.`regression_test_ddl_p0`.`tt`.`value3` DESC) as `row_num`\n    FROM 
(SELECT `internal`.`regress [...]
 
+-- !nullable --
+1      小区A     10      1       2024-09-01T09:00        2024-09-01T10:00
+2      小区B     11      1       2024-09-01T09:00        2024-09-01T10:00
+3      小区C     \N      1       2024-09-01T09:00        2024-09-01T10:00
+
+-- !nullable_view_with_cols --
+1      小区A     10      1       2024-09-01T09:00        2024-09-01T10:00
+2      小区B     11      1       2024-09-01T09:00        2024-09-01T10:00
+3      小区C     \N      1       2024-09-01T09:00        2024-09-01T10:00
+
diff --git a/regression-test/suites/ddl_p0/test_create_view_nereids.groovy 
b/regression-test/suites/ddl_p0/test_create_view_nereids.groovy
index ad3c84f25ec..38347deffc6 100644
--- a/regression-test/suites/ddl_p0/test_create_view_nereids.groovy
+++ b/regression-test/suites/ddl_p0/test_create_view_nereids.groovy
@@ -390,4 +390,51 @@ suite("test_create_view_nereids") {
     WHERE value3 < 280 AND (id < 3 or id >8);"""
     qt_complicated_view1 "select * from test_view_complicated order by 1,2,3"
     qt_complicated_view1_sql "show create view test_view_complicated;"
+
+    sql "drop table if exists v_t1"
+    sql "drop table if exists v_t2"
+    sql """CREATE TABLE `v_t1` ( `id` VARCHAR(64) NOT NULL, `name` 
VARCHAR(512) NULL , `code` VARCHAR(512) NULL
+    , `hid` INT NULL , `status` VARCHAR(3) NULL, `update_time` DATETIME NULL
+    , `mark` VARCHAR(8) NULL ,
+    `create_by` VARCHAR(64) NULL , `create_time` DATETIME NULL ,
+    `update_by` VARCHAR(64) NULL , `operate_status` INT NULL DEFAULT "0" )
+    ENGINE=OLAP UNIQUE KEY(`id`)  DISTRIBUTED BY HASH(`id`) BUCKETS 1 
PROPERTIES
+    ( "replication_allocation" = "tag.location.default: 1");"""
+    sql """CREATE TABLE `v_t2` ( `id` INT NULL , `name` VARCHAR(500) NULL , 
`hid` INT NULL , 
+    `hname` VARCHAR(200) NULL , `com_id` INT NULL , `com_name` VARCHAR(200) 
NULL , `hsid` INT NULL ,
+    `subcom_name` VARCHAR(255) NULL , `status` VARCHAR(3) NULL, `update_time` 
DATETIME NULL ) ENGINE=OLAP UNIQUE KEY(`id`)
+     DISTRIBUTED BY HASH(`id`) BUCKETS 1 PROPERTIES ( "replication_allocation" 
= "tag.location.default: 1");"""
+
+    sql """drop view if exists t_view_nullable1;"""
+    sql """CREATE VIEW `t_view_nullable1` COMMENT 'VIEW' AS SELECT `t`.`id` AS 
`community_id`, `t`.`name` AS `community_name`, `t2`.`com_id`
+    AS `company_id`, `t`.`status` AS `del_flag`, `t`.`create_time` AS 
`create_time`, `t`.`update_time` AS `update_time`
+    FROM `v_t1` t  LEFT OUTER JOIN `v_t2` t2
+    ON (`t2`.`id` = `t`.`hid`) AND (`t2`.`status` != '0') GROUP BY `t`.`id`, 
`t`.`name`, `t2`.`com_id`, `t`.`status`,
+    `t`.`create_time`, `t`.`update_time`;"""
+
+    sql """INSERT INTO v_t2 (id, name, hid, hname, com_id, com_name, hsid, 
subcom_name, status, update_time)
+    VALUES
+    (100, '中心站A', 1, '供热处A', 10, '分公司A', 1000, '公司A', '1', '2024-09-01 
10:00:00'),
+    (101, '中心站B', 2, '供热处B', 11, '分公司B', 1001, '公司B', '1', '2024-09-01 
10:00:00'),
+    (102, '中心站C', 3, '供热处C', 12, '分公司C', 1002, '公司C', '0', '2024-09-01 
10:00:00');
+    """
+
+    sql """INSERT INTO v_t1 (id, name, code, hid, status, update_time, mark, 
create_by, create_time, update_by, operate_status)
+    VALUES
+    ('1', '小区A', '001', 100, '1', '2024-09-01 10:00:00', '0', 'user1', 
'2024-09-01 09:00:00', 'user2', 1),
+    ('2', '小区B', '002', 101, '1', '2024-09-01 10:00:00', '0', 'user1', 
'2024-09-01 09:00:00', 'user2', 1),
+    ('3', '小区C', '003', NULL, '1', '2024-09-01 10:00:00', '0', 'user1', 
'2024-09-01 09:00:00', 'user2', 0);"""
+    qt_nullable """SELECT * FROM t_view_nullable1 order by community_id;"""
+
+    sql "drop view if exists t_view_nullable2"
+    sql """CREATE VIEW `t_view_nullable2`(a,b,c,d,e,f) COMMENT 'VIEW' AS 
SELECT `t`.`id` AS `community_id`, `t`.`name` AS `community_name`, `t2`.`com_id`
+    AS `company_id`, `t`.`status` AS `del_flag`, `t`.`create_time` AS 
`create_time`, `t`.`update_time` AS `update_time`
+    FROM `v_t1` t  LEFT OUTER JOIN `v_t2` t2
+    ON (`t2`.`id` = `t`.`hid`) AND (`t2`.`status` != '0') GROUP BY `t`.`id`, 
`t`.`name`, `t2`.`com_id`, `t`.`status`,
+    `t`.`create_time`, `t`.`update_time`;"""
+    qt_nullable_view_with_cols "select * from t_view_nullable2 order by a;"
+    def res1 = sql "desc t_view_nullable1"
+    def res2 = sql "desc t_view_nullable2"
+    mustContain(res1[1][2], "Yes")
+    mustContain(res2[1][2], "Yes")
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to