Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix](bug) Is null predicate get error query result #41668

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant boolean literal in ternary expression result [readability-simplify-boolean-expr]

Suggested change
empty_range_only_null ? true : false);
static_cast<bool>(empty_range_only_null));

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"

}
Loading