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

zhangstar333 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 9bfadb6ae02 [Bug](window) fix window function can't return NULL value 
(#52997)
9bfadb6ae02 is described below

commit 9bfadb6ae02951decef99b5be7a603c796706e01
Author: zhangstar333 <[email protected]>
AuthorDate: Thu Jul 10 16:45:37 2025 +0800

    [Bug](window) fix window function can't return NULL value (#52997)
    
    ### What problem does this PR solve?
    Problem Summary:
    introduce by pr: https://github.com/apache/doris/pull/52138
    when use incremental mode,the null count is not update correctly,
    so it's set_flag wrongly, and couldn't return NULL value.
---
 .../aggregate_functions/aggregate_function_null.h  |   4 +-
 .../sql_functions/window_functions/test_sum.out    | Bin 242 -> 1348 bytes
 .../sql_functions/window_functions/test_sum.groovy |  66 +++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_null.h 
b/be/src/vec/aggregate_functions/aggregate_function_null.h
index 62c2b4ddba1..9bc6f1764f3 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_null.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_null.h
@@ -204,7 +204,9 @@ public:
              Arena* arena) const override {
         const auto* column =
                 assert_cast<const ColumnNullable*, 
TypeCheckOnRelease::DISABLE>(columns[0]);
-        if (!column->is_null_at(row_num)) {
+        if (column->is_null_at(row_num)) {
+            this->null_count++;
+        } else {
             this->set_flag(place);
             const IColumn* nested_column = &column->get_nested_column();
             this->nested_function->add(this->nested_place(place), 
&nested_column, row_num, arena);
diff --git 
a/regression-test/data/query_p0/sql_functions/window_functions/test_sum.out 
b/regression-test/data/query_p0/sql_functions/window_functions/test_sum.out
index 84f4bccb2d1..c43fe830950 100644
Binary files 
a/regression-test/data/query_p0/sql_functions/window_functions/test_sum.out and 
b/regression-test/data/query_p0/sql_functions/window_functions/test_sum.out 
differ
diff --git 
a/regression-test/suites/query_p0/sql_functions/window_functions/test_sum.groovy
 
b/regression-test/suites/query_p0/sql_functions/window_functions/test_sum.groovy
index e61f586181a..9ee65e332f2 100644
--- 
a/regression-test/suites/query_p0/sql_functions/window_functions/test_sum.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/window_functions/test_sum.groovy
@@ -43,5 +43,71 @@ suite("test_sum") {
     qt_sql_window_muti1 """   select multi_distinct_group_concat(v2) over() 
from multi; """
     qt_sql_window_muti2 """   select multi_distinct_sum(v1) over() from multi; 
"""
     qt_sql_window_muti3 """   select multi_distinct_count(v1) over() from 
multi; """
+
+    sql "DROP TABLE IF EXISTS 
table_20_undef_partitions2_keys3_properties4_distributed_by5"
+    sql """
+        create table 
table_20_undef_partitions2_keys3_properties4_distributed_by5 (
+        col_int_undef_signed int  null  ,
+        col_date_undef_signed date  null  ,
+        col_datetime_undef_signed datetime  null  ,
+        pk int
+        ) engine=olap
+        DUPLICATE KEY(col_int_undef_signed)
+        PARTITION BY             RANGE(col_int_undef_signed) (
+                        PARTITION p0 VALUES LESS THAN ('4'),
+                        PARTITION p1 VALUES LESS THAN ('6'),
+                        PARTITION p2 VALUES LESS THAN ('7'),
+                        PARTITION p3 VALUES LESS THAN ('8'),
+                        PARTITION p4 VALUES LESS THAN ('10'),
+                        PARTITION p5 VALUES LESS THAN ('83647'),
+                        PARTITION p100 VALUES LESS THAN ('2147483647')
+                    )
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+    """ 
+    sql """
+        insert into 
table_20_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_date_undef_signed,col_datetime_undef_signed)
 values (0,2,'2023-12-14','2003-02-28 
20:24:41'),(1,null,'2001-10-09','2004-03-02 
17:09:05'),(2,2,'2023-12-13','2009-04-11 22:14:33'),(3,5,null,'2012-05-13 
00:29:32'),(4,null,null,'2012-05-04 08:43:40'),(5,0,'2023-12-18','2010-12-10 
13:18:28'),(6,4,'2023-12-11','2006-06-24 
13:51:23'),(7,0,'2023-12-15','2006-03-10 01:56:00'),(8,null,'2023 [...]
+    """ 
+    qt_sql_window_null1 """   SELECT
+                pk,
+                col_int_undef_signed,
+                col_date_undef_signed,
+                col_datetime_undef_signed,
+                MIN(col_int_undef_signed) OVER (
+                    PARTITION BY col_int_undef_signed
+                    ORDER BY
+                        col_int_undef_signed,
+                        col_date_undef_signed,
+                        col_datetime_undef_signed,
+                        pk DESC ROWS BETWEEN 9 PRECEDING
+                        AND 9 FOLLOWING
+                ) as min
+            FROM
+                table_20_undef_partitions2_keys3_properties4_distributed_by5
+                where col_int_undef_signed is null order by pk; 
+    """
+
+    qt_sql_window_null2 """   SELECT
+                pk,
+                col_int_undef_signed,
+                col_date_undef_signed,
+                col_datetime_undef_signed,
+                MIN(col_int_undef_signed) OVER (
+                    PARTITION BY col_int_undef_signed
+                    ORDER BY
+                        col_int_undef_signed,
+                        col_date_undef_signed,
+                        col_datetime_undef_signed,
+                        pk DESC ROWS BETWEEN 9 PRECEDING
+                        AND 9 FOLLOWING
+                ) as min
+            FROM
+                table_20_undef_partitions2_keys3_properties4_distributed_by5
+            order by
+                col_int_undef_signed,
+                col_date_undef_signed,
+                col_datetime_undef_signed,
+                pk DESC;
+    """
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to