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

jianliangqi 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 4d9b6c272d0 [Fix](vcompound pred) Corrected evaluation for compound 
predicates with constant columns (#28421)
4d9b6c272d0 is described below

commit 4d9b6c272d014e459b4bd5bc4f26513ba7f63659
Author: airborne12 <[email protected]>
AuthorDate: Fri Dec 15 10:10:48 2023 +0800

    [Fix](vcompound pred) Corrected evaluation for compound predicates with 
constant columns (#28421)
---
 be/src/vec/exprs/vcompound_pred.h                  |  6 ++-
 .../data/query_p0/test_constant_fold.out           |  7 +++
 .../suites/query_p0/test_constant_fold.groovy      | 52 ++++++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/exprs/vcompound_pred.h 
b/be/src/vec/exprs/vcompound_pred.h
index 3acbc1a1645..2ede99cae63 100644
--- a/be/src/vec/exprs/vcompound_pred.h
+++ b/be/src/vec/exprs/vcompound_pred.h
@@ -61,7 +61,8 @@ public:
         int lhs_id = -1;
         int rhs_id = -1;
         RETURN_IF_ERROR(_children[0]->execute(context, block, &lhs_id));
-        ColumnPtr lhs_column = block->get_by_position(lhs_id).column;
+        ColumnPtr lhs_column =
+                
block->get_by_position(lhs_id).column->convert_to_full_column_if_const();
         size_t size = lhs_column->size();
         bool lhs_is_nullable = lhs_column->is_nullable();
         auto [lhs_data_column, lhs_null_map] =
@@ -88,7 +89,8 @@ public:
         auto get_rhs_colum = [&]() {
             if (rhs_id == -1) {
                 RETURN_IF_ERROR(_children[1]->execute(context, block, 
&rhs_id));
-                rhs_column = block->get_by_position(rhs_id).column;
+                rhs_column =
+                        
block->get_by_position(rhs_id).column->convert_to_full_column_if_const();
                 rhs_is_nullable = rhs_column->is_nullable();
                 auto rhs_nullable_column = 
_get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
                 rhs_data_column = rhs_nullable_column.first;
diff --git a/regression-test/data/query_p0/test_constant_fold.out 
b/regression-test/data/query_p0/test_constant_fold.out
new file mode 100644
index 00000000000..5eca9777bc7
--- /dev/null
+++ b/regression-test/data/query_p0/test_constant_fold.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+0
+
+-- !select --
+0
+
diff --git a/regression-test/suites/query_p0/test_constant_fold.groovy 
b/regression-test/suites/query_p0/test_constant_fold.groovy
new file mode 100644
index 00000000000..bb8026ccd37
--- /dev/null
+++ b/regression-test/suites/query_p0/test_constant_fold.groovy
@@ -0,0 +1,52 @@
+// 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.
+
+suite("test_constant_fold", "query") {
+    // define a sql table
+    def testTable = "test_constant_fold_fuzzy"
+
+    sql """
+            CREATE TABLE IF NOT EXISTS ${testTable} (
+                c0 BOOLEAN
+            )
+            AGGREGATE KEY(c0)
+            DISTRIBUTED BY HASH (c0)
+            BUCKETS 28
+            PROPERTIES (
+                "replication_num" = "1"
+            );
+            """
+    // prepare data
+    sql """ INSERT INTO ${testTable} VALUES (false) """
+    sql """ INSERT INTO ${testTable} VALUES (true) """
+
+    sql """ set enable_fold_constant_by_be=true """
+
+    qt_select """ SELECT SUM(count) FROM
+                (SELECT CAST((NOT ((1378719999)||(CASE ${testTable}.c0  WHEN 
${testTable}.c0 THEN -388844163  WHEN ${testTable}.c0 THEN 1455674610 ELSE 
671348352 END ))) IS NOT NULL AND
+                (NOT ((1378719999)||(CASE ${testTable}.c0  WHEN 
${testTable}.c0 THEN -388844163  WHEN ${testTable}.c0 THEN 1455674610 ELSE 
671348352 END ))) AS INT) as count
+                FROM ${testTable}) as res;
+              """
+
+    sql """ set enable_fold_constant_by_be=false """
+
+    qt_select """ SELECT SUM(count) FROM
+                (SELECT CAST((NOT ((1378719999)||(CASE ${testTable}.c0  WHEN 
${testTable}.c0 THEN -388844163  WHEN ${testTable}.c0 THEN 1455674610 ELSE 
671348352 END ))) IS NOT NULL AND
+                (NOT ((1378719999)||(CASE ${testTable}.c0  WHEN 
${testTable}.c0 THEN -388844163  WHEN ${testTable}.c0 THEN 1455674610 ELSE 
671348352 END ))) AS INT) as count
+                FROM ${testTable}) as res;
+              """
+}


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

Reply via email to