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

yiguolei 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 72e264dd59 [fix](executor)fix error when FixedContainer with null 
(#22850)
72e264dd59 is described below

commit 72e264dd599b9a5b571c8b055ba0b32348c726a4
Author: Mryange <[email protected]>
AuthorDate: Fri Aug 11 17:20:50 2023 +0800

    [fix](executor)fix error when FixedContainer with null (#22850)
---
 be/src/exprs/create_predicate_function.h           |  4 +-
 be/src/exprs/hybrid_set.h                          |  5 +-
 be/src/vec/functions/in.h                          | 22 ++++++++-
 regression-test/data/correctness/test_in_null.out  | 29 +++++++++++
 .../suites/correctness/test_in_null.groovy         | 56 ++++++++++++++++++++++
 5 files changed, 112 insertions(+), 4 deletions(-)

diff --git a/be/src/exprs/create_predicate_function.h 
b/be/src/exprs/create_predicate_function.h
index 93ed3a459b..4dbd1be7e2 100644
--- a/be/src/exprs/create_predicate_function.h
+++ b/be/src/exprs/create_predicate_function.h
@@ -162,7 +162,9 @@ inline auto create_set(PrimitiveType type) {
 }
 
 inline auto create_set(PrimitiveType type, size_t size) {
-    if (size == 1) {
+    if (size == 0) {
+        return create_set<0>(type);
+    } else if (size == 1) {
         return create_set<1>(type);
     } else if (size == 2) {
         return create_set<2>(type);
diff --git a/be/src/exprs/hybrid_set.h b/be/src/exprs/hybrid_set.h
index fa7bd97176..c158b9ab52 100644
--- a/be/src/exprs/hybrid_set.h
+++ b/be/src/exprs/hybrid_set.h
@@ -43,7 +43,7 @@ public:
 
     class Iterator;
 
-    FixedContainer() : _size(0) { static_assert(N >= 1 && N <= 
FIXED_CONTAINER_MAX_SIZE); }
+    FixedContainer() : _size(0) { static_assert(N >= 0 && N <= 
FIXED_CONTAINER_MAX_SIZE); }
 
     ~FixedContainer() = default;
 
@@ -61,6 +61,9 @@ public:
 
     // Use '|' instead of '||' has better performance by test.
     ALWAYS_INLINE bool find(const T& value) const {
+        if constexpr (N == 0) {
+            return false;
+        }
         if constexpr (N == 1) {
             return (value == _data[0]);
         }
diff --git a/be/src/vec/functions/in.h b/be/src/vec/functions/in.h
index ea20f6bd62..18a5f86e1a 100644
--- a/be/src/vec/functions/in.h
+++ b/be/src/vec/functions/in.h
@@ -89,6 +89,24 @@ public:
 
     bool use_default_implementation_for_nulls() const override { return false; 
}
 
+    // size of [ in ( 1 , 2  , 3 , null) ]  is 3
+    size_t get_size_with_out_null(FunctionContext* context) {
+        if ((context->get_num_args() - 1) > FIXED_CONTAINER_MAX_SIZE) {
+            return context->get_num_args() - 1;
+        }
+        size_t sz = 0;
+        for (int i = 1; i < context->get_num_args(); ++i) {
+            const auto& const_column_ptr = context->get_constant_col(i);
+            if (const_column_ptr != nullptr) {
+                auto const_data = const_column_ptr->column_ptr->get_data_at(0);
+                if (const_data.data != nullptr) {
+                    sz++;
+                }
+            }
+        }
+        return sz;
+    }
+
     Status open(FunctionContext* context, FunctionContext::FunctionStateScope 
scope) override {
         if (scope == FunctionContext::THREAD_LOCAL) {
             return Status::OK();
@@ -104,8 +122,8 @@ public:
             // the StringValue's memory is held by FunctionContext, so we can 
use StringValueSet here directly
             
state->hybrid_set.reset(create_string_value_set((size_t)(context->get_num_args()
 - 1)));
         } else {
-            state->hybrid_set.reset(create_set(context->get_arg_type(0)->type,
-                                               
(size_t)(context->get_num_args() - 1)));
+            state->hybrid_set.reset(
+                    create_set(context->get_arg_type(0)->type, 
get_size_with_out_null(context)));
         }
 
         for (int i = 1; i < context->get_num_args(); ++i) {
diff --git a/regression-test/data/correctness/test_in_null.out 
b/regression-test/data/correctness/test_in_null.out
new file mode 100644
index 0000000000..f359b90ce1
--- /dev/null
+++ b/regression-test/data/correctness/test_in_null.out
@@ -0,0 +1,29 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select1 --
+\N     \N
+0      \N
+1      \N
+2      \N
+3      \N
+
+-- !select2 --
+\N     \N
+0      \N
+1      \N
+2      true
+3      \N
+
+-- !select3 --
+\N     \N
+0      \N
+1      \N
+2      \N
+3      \N
+
+-- !select4 --
+\N     \N
+0      \N
+1      \N
+2      true
+3      \N
+
diff --git a/regression-test/suites/correctness/test_in_null.groovy 
b/regression-test/suites/correctness/test_in_null.groovy
new file mode 100644
index 0000000000..f1e08f38b1
--- /dev/null
+++ b/regression-test/suites/correctness/test_in_null.groovy
@@ -0,0 +1,56 @@
+// 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_in_null") {
+     sql """ DROP TABLE IF EXISTS db """
+     sql """
+        CREATE TABLE IF NOT EXISTS db(
+              `id` INT NULL ,
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY HASH(`id`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "storage_format" = "V2"
+        );
+    """
+    sql """ INSERT INTO db VALUES(1); """
+    sql """ INSERT INTO db VALUES(2); """
+    sql """ INSERT INTO db VALUES(3); """
+    sql """ INSERT INTO db VALUES(0); """
+    sql """ INSERT INTO db VALUES(NULL); """
+    
+
+    sql """
+        set enable_nereids_planner=false;
+    """
+    qt_select1 """
+        select id,id IN (NULL)  from db order by id;
+    """
+    qt_select2 """
+        select id,id in (2,null)  from db order by id;
+    """
+    sql """
+        set enable_nereids_planner=true;
+    """
+    qt_select3 """
+        select id,id IN (NULL)  from db order by id;
+    """ 
+    qt_select4 """
+        select id,id in (2,null)  from db order by id;
+    """
+}
\ No newline at end of file


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

Reply via email to