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

panxiaolei 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 310b92d3b91 [Bug](function) process when_column is const (#55963)
310b92d3b91 is described below

commit 310b92d3b913f9deffdc4af6af8076b120ab79a1
Author: Pxl <[email protected]>
AuthorDate: Sat Sep 13 13:03:49 2025 +0800

    [Bug](function) process when_column is const (#55963)
    
    process when_column is const
---
 be/src/vec/exprs/vcase_expr.h                      |  18 +++++-
 .../test_conditional_function.out                  | Bin 3456 -> 4260 bytes
 .../test_conditional_function.groovy               |  68 +++++++++++++++++++++
 3 files changed, 83 insertions(+), 3 deletions(-)

diff --git a/be/src/vec/exprs/vcase_expr.h b/be/src/vec/exprs/vcase_expr.h
index b651c1136cd..3cef1704bd0 100644
--- a/be/src/vec/exprs/vcase_expr.h
+++ b/be/src/vec/exprs/vcase_expr.h
@@ -229,10 +229,22 @@ private:
         IndexType* __restrict then_idx_ptr = then_idx.data();
         for (IndexType i = 0; i < when_columns.size(); i++) {
             IndexType column_idx = i + 1;
-            if (when_columns[i]->is_nullable()) {
+            auto [raw_when_column, is_consts] = 
unpack_if_const(when_columns[i]);
+
+            if (is_consts) {
+                if (raw_when_column->get_bool(0)) {
+                    for (int row_idx = 0; row_idx < rows_count; row_idx++) {
+                        then_idx_ptr[row_idx] |= (!then_idx_ptr[row_idx]) * 
column_idx;
+                    }
+                    break;
+                }
+                continue;
+            }
+
+            if (raw_when_column->is_nullable()) {
                 const auto* column_nullable_ptr =
                         assert_cast<const ColumnNullable*, 
TypeCheckOnRelease::DISABLE>(
-                                when_columns[i].get());
+                                raw_when_column.get());
                 const auto* __restrict cond_raw_data =
                         assert_cast<const ColumnUInt8*, 
TypeCheckOnRelease::DISABLE>(
                                 
column_nullable_ptr->get_nested_column_ptr().get())
@@ -258,7 +270,7 @@ private:
             } else {
                 const auto* __restrict cond_raw_data =
                         assert_cast<const ColumnUInt8*, 
TypeCheckOnRelease::DISABLE>(
-                                when_columns[i].get())
+                                raw_when_column.get())
                                 ->get_data()
                                 .data();
                 for (int row_idx = 0; row_idx < rows_count; row_idx++) {
diff --git 
a/regression-test/data/query_p0/sql_functions/conditional_functions/test_conditional_function.out
 
b/regression-test/data/query_p0/sql_functions/conditional_functions/test_conditional_function.out
index 244c1484055..06b97b773d1 100644
Binary files 
a/regression-test/data/query_p0/sql_functions/conditional_functions/test_conditional_function.out
 and 
b/regression-test/data/query_p0/sql_functions/conditional_functions/test_conditional_function.out
 differ
diff --git 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_conditional_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_conditional_function.groovy
index 15a07a91b77..9e1336a39ff 100644
--- 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_conditional_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_conditional_function.groovy
@@ -195,4 +195,72 @@ suite("test_conditional_function") {
 
     sql "set enable_decimal256=false"
     qt_test "select array_cum_sum(k2) from t2 where k1=1;"
+
+    sql "drop table if exists 
table_200_undef_partitions2_keys3_properties4_distributed_by5;"
+    sql """
+create table table_200_undef_partitions2_keys3_properties4_distributed_by5 (
+col_date_undef_signed_not_null date  not null ,
+col_bigint_undef_signed_not_null bigint  not null ,
+col_int_undef_signed int  null ,
+col_int_undef_signed_not_null int  not null ,
+col_bigint_undef_signed bigint  null ,
+col_date_undef_signed date  null ,
+col_varchar_10__undef_signed varchar(10)  null ,
+col_varchar_10__undef_signed_not_null varchar(10)  not null ,
+col_varchar_1024__undef_signed varchar(1024)  null ,
+col_varchar_1024__undef_signed_not_null varchar(1024)  not null ,
+pk int
+) engine=olap
+UNIQUE KEY(col_date_undef_signed_not_null, col_bigint_undef_signed_not_null)
+PARTITION BY             RANGE(col_date_undef_signed_not_null) (
+                FROM ('2023-12-09') TO ('2024-03-09') INTERVAL 1 DAY,
+                FROM ('2025-02-16') TO ('2025-03-09') INTERVAL 1 DAY,
+                FROM ('2025-06-18') TO ('2025-06-20') INTERVAL 1 DAY,
+                FROM ('2026-01-01') TO ('2026-03-09') INTERVAL 1 DAY,
+                FROM ('2027-01-01') TO ('2027-02-09') INTERVAL 1 DAY
+            )
+        
+distributed by hash(col_bigint_undef_signed_not_null) buckets 30
+properties("enable_unique_key_merge_on_write" = "true", "replication_num" = 
"1");
+    """
+    sql """
+insert into 
table_200_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_int_undef_signed_not_null,col_bigint_undef_signed,col_bigint_undef_signed_not_null,col_date_undef_signed,col_date_undef_signed_not_null,col_varchar_10__undef_signed,col_varchar_10__undef_signed_not_null,col_varchar_1024__undef_signed,col_varchar_1024__undef_signed_not_null)
 values 
(0,-10,-10,null,2645586035756450619,'2023-12-10','2024-02-18','y','b',null,'h'),(1,5,2,-2690774847697924751,
 [...]
+    """
+    sql "drop table if exists 
table_50_undef_partitions2_keys3_properties4_distributed_by54"
+    sql """
+create table table_50_undef_partitions2_keys3_properties4_distributed_by54 (
+col_date_undef_signed_not_null date  not null ,
+col_bigint_undef_signed_not_null bigint  not null ,
+col_int_undef_signed int  null ,
+col_int_undef_signed_not_null int  not null ,
+col_bigint_undef_signed bigint  null ,
+col_date_undef_signed date  null ,
+col_varchar_10__undef_signed varchar(10)  null ,
+col_varchar_10__undef_signed_not_null varchar(10)  not null ,
+col_varchar_1024__undef_signed varchar(1024)  null ,
+col_varchar_1024__undef_signed_not_null varchar(1024)  not null ,
+pk int
+) engine=olap
+UNIQUE KEY(col_date_undef_signed_not_null, col_bigint_undef_signed_not_null)
+PARTITION BY             RANGE(col_date_undef_signed_not_null) (
+                PARTITION p0 VALUES LESS THAN ('2023-12-11'),
+                PARTITION p1 VALUES LESS THAN ('2023-12-15'),
+                PARTITION p2 VALUES LESS THAN ('2023-12-16'),
+                PARTITION p3 VALUES LESS THAN ('2023-12-25'),
+                PARTITION p4 VALUES LESS THAN ('2024-01-18'),
+                PARTITION p5 VALUES LESS THAN ('2026-02-18'),
+                PARTITION p6 VALUES LESS THAN ('5024-02-18'),
+                PARTITION p100 VALUES LESS THAN ('9999-12-31')
+            )
+        
+distributed by hash(col_bigint_undef_signed_not_null) buckets 30
+properties("enable_unique_key_merge_on_write" = "true", "replication_num" = 
"1");
+    """
+
+    sql """
+insert into 
table_50_undef_partitions2_keys3_properties4_distributed_by54(pk,col_int_undef_signed,col_int_undef_signed_not_null,col_bigint_undef_signed,col_bigint_undef_signed_not_null,col_date_undef_signed,col_date_undef_signed_not_null,col_varchar_10__undef_signed,col_varchar_10__undef_signed_not_null,col_varchar_1024__undef_signed,col_varchar_1024__undef_signed_not_null)
 values 
(0,-4,0,-4166296231541746094,9091136508347176422,'2023-12-15','2024-02-18','v','b','d','n'),(1,3,2,332544340
 [...]
+    """
+    qt_test """
+SELECT TO_DATE ( table1 . `col_date_undef_signed_not_null` ) AS field1, MAX( 
distinct table1 . `col_int_undef_signed_not_null` ) AS field2, ( TO_DATE (CASE 
table1 . col_date_undef_signed_not_null WHEN table1 . 
col_date_undef_signed_not_null THEN DATE_ADD( table1 . 
`col_date_undef_signed_not_null` , INTERVAL 3 YEAR ) WHEN table1 . 
col_date_undef_signed THEN '2024-01-31' WHEN '2025-02-18' THEN '2024-02-18' 
WHEN '2008-09-25' THEN DATE_SUB( table1 . `col_date_undef_signed` , INTERVAL 7 
DAY ) [...]
+    """
 }


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

Reply via email to