Skip to content

Commit

Permalink
[Fix](bug) Is null predicate get error query result
Browse files Browse the repository at this point in the history
  • Loading branch information
HappenLee committed Oct 10, 2024
1 parent 0a26ad8 commit 5215135
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
28 changes: 17 additions & 11 deletions be/src/exec/olap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,25 +617,30 @@ bool ColumnValueRange<primitive_type>::convert_to_avg_range_value(
std::vector<OlapTuple>& begin_scan_keys, std::vector<OlapTuple>& end_scan_keys,
bool& begin_include, bool& end_include, int32_t max_scan_key_num) {
if constexpr (!_is_reject_split_type) {
CppType min_value = get_range_min_value();
CppType max_value = get_range_max_value();
if constexpr (primitive_type == PrimitiveType::TYPE_DATE) {
min_value.set_type(TimeType::TIME_DATE);
max_value.set_type(TimeType::TIME_DATE);
}
auto empty_range_only_null = min_value > max_value;
if (empty_range_only_null) {
// Not contain null will be disposed in `convert_to_close_range`, return eos.
DCHECK(contain_null());
}

auto no_split = [&]() -> bool {
begin_scan_keys.emplace_back();
begin_scan_keys.back().add_value(
cast_to_string<primitive_type, CppType>(get_range_min_value(), scale()),
contain_null());
end_scan_keys.emplace_back();
end_scan_keys.back().add_value(
cast_to_string<primitive_type, CppType>(get_range_max_value(), scale()));
cast_to_string<primitive_type, CppType>(get_range_max_value(), scale()),
empty_range_only_null ? true : false);
return true;
};

CppType min_value = get_range_min_value();
CppType max_value = get_range_max_value();
if constexpr (primitive_type == PrimitiveType::TYPE_DATE) {
min_value.set_type(TimeType::TIME_DATE);
max_value.set_type(TimeType::TIME_DATE);
}

if (min_value > max_value || max_scan_key_num == 1) {
if (empty_range_only_null || max_scan_key_num == 1) {
return no_split();
}

Expand Down Expand Up @@ -1028,7 +1033,8 @@ Status OlapScanKeys::extend_scan_key(ColumnValueRange<primitive_type>& range,
*eos |= range.convert_to_close_range(_begin_scan_keys, _end_scan_keys, _begin_include,
_end_include);

if (range.convert_to_avg_range_value(_begin_scan_keys, _end_scan_keys, _begin_include,
if (!(*eos) &&
range.convert_to_avg_range_value(_begin_scan_keys, _end_scan_keys, _begin_include,
_end_include, max_scan_key_num)) {
_has_range_value = true;
}
Expand Down
5 changes: 5 additions & 0 deletions regression-test/data/query_p0/scan_range/test_scan_range.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

-- !sql_2 --
1
-2147483648

-- !sql_3 --

-- !sql_4 --

-- !sql_5 --
\N

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ suite("test_scan_range", "query,p0") {
"""

sql "insert into ${tableName} values(1,1)"
sql "insert into ${tableName} values(-2147483648, -2147483648)"
sql "insert into ${tableName} values(null, null)"

qt_sql_1 "select k1 from ${tableName} where k1 > -2147483648"

Expand All @@ -42,4 +44,7 @@ suite("test_scan_range", "query,p0") {
qt_sql_3 "select k1 from ${tableName} where k1 < -2147483648"

qt_sql_4 "select k1 from ${tableName} where k1 > 2147483647"

qt_sql_5 "select k1 from ${tableName} where k1 is null"

}

0 comments on commit 5215135

Please sign in to comment.