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

yiguolei 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 f0b2f5ba368 [Fix](bug) agg limit contains null values may cause error 
result (#35180)
f0b2f5ba368 is described below

commit f0b2f5ba368418490407989b460ec3be8e13f1db
Author: HappenLee <[email protected]>
AuthorDate: Wed May 22 10:57:57 2024 +0800

    [Fix](bug) agg limit contains null values may cause error result (#35180)
---
 be/src/vec/common/columns_hashing.h                        | 8 ++++++++
 be/src/vec/common/columns_hashing_impl.h                   | 2 +-
 be/src/vec/common/hash_table/hash_map_context.h            | 2 +-
 regression-test/data/query_p0/aggregate/aggregate.out      | 2 ++
 regression-test/suites/query_p0/aggregate/aggregate.groovy | 4 ++++
 5 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/common/columns_hashing.h 
b/be/src/vec/common/columns_hashing.h
index 83f01fdf4b2..c25c8acdb7b 100644
--- a/be/src/vec/common/columns_hashing.h
+++ b/be/src/vec/common/columns_hashing.h
@@ -136,6 +136,14 @@ struct HashMethodSingleLowNullableColumn : public 
SingleColumnMethod {
         data.lazy_emplace(std::forward<KeyHolder>(key), it, hash_value, 
std::forward<Func>(f));
         return *lookup_result_get_mapped(it);
     }
+
+    template <typename Data, typename Key>
+    ALWAYS_INLINE FindResult find_key_with_hash(Data& data, size_t i, Key key, 
size_t hash_value) {
+        if (key_column->is_null_at(i) && data.has_null_key_data()) {
+            return FindResult {&data.template get_null_key_data<Mapped>(), 
true};
+        }
+        return Base::find_key_impl(key, hash_value, data);
+    }
 };
 
 } // namespace ColumnsHashing
diff --git a/be/src/vec/common/columns_hashing_impl.h 
b/be/src/vec/common/columns_hashing_impl.h
index d0ef8a4b014..6d8ba439510 100644
--- a/be/src/vec/common/columns_hashing_impl.h
+++ b/be/src/vec/common/columns_hashing_impl.h
@@ -89,7 +89,7 @@ public:
     }
 
     template <typename Data, typename Key>
-    ALWAYS_INLINE FindResult find_key_with_hash(Data& data, size_t hash_value, 
Key key) {
+    ALWAYS_INLINE FindResult find_key_with_hash(Data& data, size_t i, Key key, 
size_t hash_value) {
         return find_key_impl(key, hash_value, data);
     }
 
diff --git a/be/src/vec/common/hash_table/hash_map_context.h 
b/be/src/vec/common/hash_table/hash_map_context.h
index f52be441dd6..0dec7eef88d 100644
--- a/be/src/vec/common/hash_table/hash_map_context.h
+++ b/be/src/vec/common/hash_table/hash_map_context.h
@@ -125,7 +125,7 @@ struct MethodBaseInner {
         if constexpr (!is_string_hash_map()) {
             prefetch<true>(i);
         }
-        return state.find_key_with_hash(*hash_table, hash_values[i], keys[i]);
+        return state.find_key_with_hash(*hash_table, i, keys[i], 
hash_values[i]);
     }
 
     template <typename State, typename F, typename FF>
diff --git a/regression-test/data/query_p0/aggregate/aggregate.out 
b/regression-test/data/query_p0/aggregate/aggregate.out
index 9f9870797a0..ffd37904994 100644
--- a/regression-test/data/query_p0/aggregate/aggregate.out
+++ b/regression-test/data/query_p0/aggregate/aggregate.out
@@ -695,3 +695,5 @@ TESTING     AGAIN
 -- !subquery_without_inner_predicate --
 7
 
+-- !aggregate_limit_contain_null --
+16     \N
diff --git a/regression-test/suites/query_p0/aggregate/aggregate.groovy 
b/regression-test/suites/query_p0/aggregate/aggregate.groovy
index 1b0987538cc..b611ff92b0e 100644
--- a/regression-test/suites/query_p0/aggregate/aggregate.groovy
+++ b/regression-test/suites/query_p0/aggregate/aggregate.groovy
@@ -304,4 +304,8 @@ suite("aggregate") {
     qt_subquery_without_inner_predicate """
         select count(*) from (select t2.c_bigint, t2.c_double, t2.c_string 
from (select c_bigint, c_double, c_string, c_date,c_timestamp, c_short_decimal 
from regression_test_query_p0_aggregate.${tableName} where c_bigint > 5000) 
t2)t1
     """
+
+    qt_aggregate_limit_contain_null """
+    select count(), cast(k12 as int) as t from baseall group by t limit 1;
+       """
 }


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

Reply via email to