Skip to content

Commit f787653

Browse files
authored
[fix](olap) Need to handle floating-point Infinity values in the predicate (apache#57100)
### What problem does this PR solve? ```text #0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=140649357411904) at ./nptl/pthread_kill.c:44 #1 __pthread_kill_internal (signo=6, threadid=140649357411904) at ./nptl/pthread_kill.c:78 #2 __GI___pthread_kill (threadid=140649357411904, signo=signo@entry=6) at ./nptl/pthread_kill.c:89 #3 0x00007feca2a42476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 #4 0x00007feca2a287f3 in __GI_abort () at ./stdlib/abort.c:79 #5 0x000055cd63341b52 in __gnu_cxx::__verbose_terminate_handler() () #6 0x000055cd6333fe26 in __cxxabiv1::__terminate(void (*)()) () #7 0x000055cd6333fe79 in std::terminate() () #8 0x000055cd6333ffc3 in __cxa_throw () #9 0x000055cd6339556a in std::__throw_out_of_range(char const*) () #10 0x000055cd5a9a7a68 in __gnu_cxx::__stoa<double, double, char> (__str=0x7fe842726fc0 "9.", '9' <repeats 15 times>, "1e-309", __idx=0x0, __convf=<optimized out>, __name=<optimized out>) at /usr/local/ldb-toolchain-v0.26/bin/../lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/ext/string_conversions.h:90 #11 std::__cxx11::stod (__str=..., __idx=0x0) at /usr/local/ldb-toolchain-v0.26/bin/../lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/basic_string.h:4490 #12 doris::IntegerPredicateCreator<(doris::PrimitiveType)9, (doris::PredicateType)1, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::convert (condition=...) at /root/doris_branch-4.0/doris/be/src/olap/predicate_creator.h:68 #13 doris::IntegerPredicateCreator<(doris::PrimitiveType)9, (doris::PredicateType)1, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::create (this=<optimized out>, column=..., index=1, conditions=..., opposite=false, arena=...) at /root/doris_branch-4.0/doris/be/src/olap/predicate_creator.h:59 #14 0x000055cd5a3dd63b in doris::create_predicate<(doris::PredicateType)1, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (column=..., index=1, conditions=..., opposite=false, arena=...) at /root/doris_branch-4.0/doris/be/src/olap/predicate_creator.h:270 #15 doris::create_comparison_predicate<(doris::PredicateType)1> (column=..., index=1, condition=..., opposite=false, arena=...) at /root/doris_branch-4.0/doris/be/src/olap/predicate_creator.h:278 #16 0x000055cd5a3dd435 in doris::parse_to_predicate (column=..., index=1, condition=..., arena=..., opposite=false) at /root/doris_branch-4.0/doris/be/src/olap/predicate_creator.h:326 #17 0x000055cd5afc2759 in doris::TabletReader::_init_conditions_param (this=this@entry=0x7fe842e1a800, read_params=...) at /root/doris_branch-4.0/doris/be/src/olap/tablet_reader.cpp:549 #18 0x000055cd5afc1022 in doris::TabletReader::_init_params (this=this@entry=0x7fe842e1a800, read_params=...) at /root/doris_branch-4.0/doris/be/src/olap/tablet_reader.cpp:304 #19 0x000055cd5afbfe00 in doris::TabletReader::init (this=0x7fe842e1a800, read_params=...) at /root/doris_branch-4.0/doris/be/src/olap/tablet_reader.cpp:127 #20 0x000055cd5f019d0f in doris::vectorized::BlockReader::init (this=0x4c1b, read_params=...) at /root/doris_branch-4.0/doris/be/src/vec/olap/block_reader.cpp:206 apache#21 0x000055cd5f79a3f4 in doris::vectorized::OlapScanner::open (this=0x7febe2c16010, state=<optimized out>) at /root/doris_branch-4.0/doris/be/src/vec/exec/scan/olap_scanner.cpp:278 apache#22 0x000055cd5e05303a in doris::vectorized::ScannerScheduler::_scanner_scan (ctx=..., scan_task=...) at /root/doris_branch-4.0/doris/be/src/vec/exec/scan/scanner_scheduler.cpp:182 apache#23 0x000055cd5e0549e5 in doris::vectorized::ScannerScheduler::submit(std::shared_ptr<doris::vectorized::ScannerContext>, std::shared_ptr<doris::vectorized::ScanTask>)::$_0::operator()() const::{lambda()#1}::operator()() const::{lambda()#1}::operator()() const (this=<optimized out>) at /root/doris_branch-4.0/doris/be/src/vec/exec/scan/scanner_scheduler.cpp:96 apache#24 doris::vectorized::ScannerScheduler::submit(std::shared_ptr<doris::vectorized::ScannerContext>, std::shared_ptr<doris::vectorized::ScanTask>)::$_0::operator()() const::{lambda()#1}::operator()() const (this=0x7febe321dac0) at /root/doris_branch-4.0/doris/be/src/vec/exec/scan/scanner_scheduler.cpp:95 apache#25 std::__invoke_impl<bool, doris::vectorized::ScannerScheduler::submit(std::shared_ptr<doris::vectorized::ScannerContext>, std::shared_ptr<doris::vectorized::ScanTask>)::$_0::operator()() const::{lambda()#1}&>(std::__invoke_other, doris::vectorized::ScannerScheduler::submit(std::shared_ptr<doris::vectorized::ScannerContext>, std::shared_ptr<doris::vectorized::ScanTask>)::$_0::operator()() const::{lambda()#1}&) (__f=...) at /usr/local/ldb-toolchain-v0.26/bin/../lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/invoke.h:63 apache#26 std::__invoke_r<bool, doris::vectorized::ScannerScheduler::submit(std::shared_ptr<doris::vectorized::ScannerContext>, std::shared_ptr<doris::vectorized::ScanTask>)::$_0::operator()() const::{lambda()#1}&>(doris::vectorized::ScannerScheduler::submit(std::shared_ptr<doris::vectorized::ScannerContext>, std::shared_ptr<doris::vectorized::ScanTask>)::$_0::operator()() const::{lambda()#1}&) (__fn=...) at /usr/local/ldb-toolchain-v0.26/bin/../lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/invoke.h:116 apache#27 std::_Function_handler<bool (), doris::vectorized::ScannerScheduler::submit(std::shared_ptr<doris::vectorized::ScannerContext>, std::shared_ptr<doris::vectorized::ScanTask>)::$_0::operator()() const::{lambda()#1}>::_M_invoke(std::_Any_data const&) ( __functor=...) at /usr/local/ldb-toolchain-v0.26/bin/../lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/std_function.h:292 apache#28 0x000055cd5b4ab5d5 in doris::ThreadPool::dispatch_thread (this=0x7fec35e01800) at /root/doris_branch-4.0/doris/be/src/util/threadpool.cpp:614 apache#29 0x000055cd5b4a06fc in std::function<void ()>::operator()() const (this=0x4a17) at /usr/local/ldb-toolchain-v0.26/bin/../lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/std_function.h:593 apache#30 doris::Thread::supervise_thread (arg=0x7fec35872110) at /root/doris_branch-4.0/doris/be/src/util/thread.cpp:460 apache#31 0x00007feca2a94ac3 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442 apache#32 0x00007feca2b26850 in __closefrom_fallback (from=-823527648, dirfd_fallback=<optimized out>) at ../sysdeps/unix/sysv/linux/closefrom_fallback.c:45 apache#33 0x0000000000000000 in ?? () ``` Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
1 parent a301e31 commit f787653

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

be/src/olap/predicate_creator.h

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717

1818
#pragma once
1919

20+
#include <fast_float/fast_float.h>
21+
2022
#include <charconv>
23+
#include <stdexcept>
24+
#include <string>
2125
#include <type_traits>
2226

27+
#include "common/exception.h"
28+
#include "common/status.h"
2329
#include "exec/olap_utils.h"
2430
#include "exprs/create_predicate_function.h"
2531
#include "exprs/hybrid_set.h"
@@ -33,7 +39,10 @@
3339
#include "runtime/primitive_type.h"
3440
#include "util/date_func.h"
3541
#include "util/string_util.h"
42+
#include "vec/common/string_ref.h"
3643
#include "vec/data_types/data_type.h"
44+
#include "vec/functions/cast/cast_parameters.h"
45+
#include "vec/functions/cast/cast_to_basic_number_common.h"
3746

3847
namespace doris {
3948
#include "common/compile_check_begin.h"
@@ -65,15 +74,29 @@ class IntegerPredicateCreator : public PredicateCreator<ConditionType> {
6574
private:
6675
static CppType convert(const std::string& condition) {
6776
CppType value = 0;
68-
// because std::from_chars can't compile on macOS
69-
if constexpr (std::is_same_v<CppType, double>) {
70-
value = std::stod(condition, nullptr);
71-
} else if constexpr (std::is_same_v<CppType, float>) {
72-
value = std::stof(condition, nullptr);
77+
if constexpr (std::is_floating_point_v<CppType>) {
78+
vectorized::CastParameters params;
79+
if (vectorized::CastToFloat::from_string(StringRef {condition.data(), condition.size()},
80+
value, params)) {
81+
return value;
82+
} else {
83+
throw Exception(
84+
ErrorCode::INVALID_ARGUMENT,
85+
fmt::format("convert string to number failed, str: {} to float/double",
86+
condition));
87+
}
7388
} else {
74-
std::from_chars(condition.data(), condition.data() + condition.size(), value);
89+
auto ret =
90+
std::from_chars(condition.data(), condition.data() + condition.size(), value);
91+
if (ret.ptr == condition.data() + condition.size()) {
92+
return value;
93+
} else {
94+
throw Exception(
95+
ErrorCode::INVALID_ARGUMENT,
96+
fmt::format("convert string to number failed, str: {}, error: [{}] {}",
97+
condition, ret.ec, std::make_error_code(ret.ec).message()));
98+
}
7599
}
76-
return value;
77100
}
78101
};
79102

be/test/olap/delete_handler_test.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <gen_cpp/olap_file.pb.h>
2626
#include <gtest/gtest-message.h>
2727
#include <gtest/gtest-test-part.h>
28+
#include <gtest/gtest.h>
2829
#include <unistd.h>
2930

3031
#include <cstdlib>
@@ -1064,8 +1065,8 @@ TEST_F(TestDeleteHandler, ValueWithQuote) {
10641065

10651066
add_delete_predicate(del_predicate, 2);
10661067

1067-
auto res = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5);
1068-
EXPECT_EQ(Status::OK(), res);
1068+
EXPECT_ANY_THROW(
1069+
auto st = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5));
10691070
}
10701071

10711072
TEST_F(TestDeleteHandler, ValueWithoutQuote) {
@@ -1076,8 +1077,8 @@ TEST_F(TestDeleteHandler, ValueWithoutQuote) {
10761077

10771078
add_delete_predicate(del_predicate, 2);
10781079

1079-
auto res = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5);
1080-
EXPECT_EQ(Status::OK(), res);
1080+
EXPECT_ANY_THROW(
1081+
auto res = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5));
10811082
}
10821083

10831084
TEST_F(TestDeleteHandler, InitSuccess) {

regression-test/data/query_p0/sql_functions/conditional_functions/test_query_in.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,17 @@ jj -28532
9797
false 1 1989 1001 11011902 123.123 true 1989-03-21 1989-03-21T13:00 wangjuoo4 0.1 6.333 string12345 170141183460469231731687303715884105727
9898
false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk 78945.0 3654.0 string12345 0
9999

100+
-- !in33 --
101+
1 1e+308
102+
2 Infinity
103+
3 9.999999999999999e-309
104+
105+
-- !in34 --
106+
1 1e+308
107+
108+
-- !in35 --
109+
2 Infinity
110+
111+
-- !in36 --
112+
3 9.999999999999999e-309
113+

regression-test/suites/query_p0/sql_functions/conditional_functions/test_query_in.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,17 @@ suite("test_query_in", "query,p0") {
6161
qt_in31 """select * from (select 'jj' as kk1, sum(k2) from ${tableName2} where k10 = '2015-04-02' group by kk1)tt
6262
where kk1 = 'jj'"""
6363
qt_in32 """select * from ${tableName1} where cast(k1 as char) in (1, -1, 5, 0.1, 3.000) order by k1, k2, k3, k4"""
64+
65+
sql """ drop table if exists double_test_out_of_range; """
66+
sql """
67+
create table double_test_out_of_range (
68+
id int,
69+
v double
70+
) properties("replication_num" = "1");
71+
"""
72+
sql """ insert into double_test_out_of_range values (1, 1e308), (2, 1e309), (3, 1e-308); """
73+
qt_in33 """ select * from double_test_out_of_range order by id; """
74+
qt_in34 """ select * from double_test_out_of_range where v = 1e308; """
75+
qt_in35 """ select * from double_test_out_of_range where v = 1e309; """
76+
qt_in36 """ select * from double_test_out_of_range where v = 1e-308; """
6477
}

0 commit comments

Comments
 (0)