Skip to content

Commit

Permalink
[Fix](bug) agg limit contains null values may cause error result (#35152
Browse files Browse the repository at this point in the history
)
  • Loading branch information
HappenLee authored May 22, 2024
1 parent b699cf3 commit 3c8a6ee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions be/src/vec/common/columns_hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/common/columns_hashing_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HashMethodBase {
}

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);
}

Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/common/hash_table/hash_map_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions regression-test/data/query_p0/aggregate/aggregate.out
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,5 @@ TESTING AGAIN
-- !subquery_without_inner_predicate --
7

-- !aggregate_limit_contain_null --
16 \N
4 changes: 4 additions & 0 deletions regression-test/suites/query_p0/aggregate/aggregate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
}

0 comments on commit 3c8a6ee

Please sign in to comment.