You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2025/10/22 02:00:07 UTC

(doris) branch master updated: [fix](olap) Need to handle floating-point Infinity values in the predicate (#57100)

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

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new f7876530964 [fix](olap) Need to handle floating-point Infinity values in the predicate (#57100)
f7876530964 is described below

commit f78765309644f84c1e09300719725cd54e1d41c9
Author: Jerry Hu <hu...@selectdb.com>
AuthorDate: Wed Oct 22 10:00:00 2025 +0800

    [fix](olap) Need to handle floating-point Infinity values in the predicate (#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
    #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
    #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
    #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
    #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
    #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
    #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
    #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
    #28 0x000055cd5b4ab5d5 in doris::ThreadPool::dispatch_thread (this=0x7fec35e01800) at /root/doris_branch-4.0/doris/be/src/util/threadpool.cpp:614
    #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
    #30 doris::Thread::supervise_thread (arg=0x7fec35872110) at /root/doris_branch-4.0/doris/be/src/util/thread.cpp:460
    #31 0x00007feca2a94ac3 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
    #32 0x00007feca2b26850 in __closefrom_fallback (from=-823527648, dirfd_fallback=<optimized out>) at ../sysdeps/unix/sysv/linux/closefrom_fallback.c:45
    #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:
    https://github.com/apache/doris-website/pull/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 -->
---
 be/src/olap/predicate_creator.h                    | 37 ++++++++++++++++++----
 be/test/olap/delete_handler_test.cpp               |  9 +++---
 .../conditional_functions/test_query_in.out        | 14 ++++++++
 .../conditional_functions/test_query_in.groovy     | 13 ++++++++
 4 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/be/src/olap/predicate_creator.h b/be/src/olap/predicate_creator.h
index bd0cf761ca2..2f2abb6ca74 100644
--- a/be/src/olap/predicate_creator.h
+++ b/be/src/olap/predicate_creator.h
@@ -17,9 +17,15 @@
 
 #pragma once
 
+#include <fast_float/fast_float.h>
+
 #include <charconv>
+#include <stdexcept>
+#include <string>
 #include <type_traits>
 
+#include "common/exception.h"
+#include "common/status.h"
 #include "exec/olap_utils.h"
 #include "exprs/create_predicate_function.h"
 #include "exprs/hybrid_set.h"
@@ -33,7 +39,10 @@
 #include "runtime/primitive_type.h"
 #include "util/date_func.h"
 #include "util/string_util.h"
+#include "vec/common/string_ref.h"
 #include "vec/data_types/data_type.h"
+#include "vec/functions/cast/cast_parameters.h"
+#include "vec/functions/cast/cast_to_basic_number_common.h"
 
 namespace doris {
 #include "common/compile_check_begin.h"
@@ -65,15 +74,29 @@ public:
 private:
     static CppType convert(const std::string& condition) {
         CppType value = 0;
-        // because std::from_chars can't compile on macOS
-        if constexpr (std::is_same_v<CppType, double>) {
-            value = std::stod(condition, nullptr);
-        } else if constexpr (std::is_same_v<CppType, float>) {
-            value = std::stof(condition, nullptr);
+        if constexpr (std::is_floating_point_v<CppType>) {
+            vectorized::CastParameters params;
+            if (vectorized::CastToFloat::from_string(StringRef {condition.data(), condition.size()},
+                                                     value, params)) {
+                return value;
+            } else {
+                throw Exception(
+                        ErrorCode::INVALID_ARGUMENT,
+                        fmt::format("convert string to number failed, str: {} to float/double",
+                                    condition));
+            }
         } else {
-            std::from_chars(condition.data(), condition.data() + condition.size(), value);
+            auto ret =
+                    std::from_chars(condition.data(), condition.data() + condition.size(), value);
+            if (ret.ptr == condition.data() + condition.size()) {
+                return value;
+            } else {
+                throw Exception(
+                        ErrorCode::INVALID_ARGUMENT,
+                        fmt::format("convert string to number failed, str: {}, error: [{}] {}",
+                                    condition, ret.ec, std::make_error_code(ret.ec).message()));
+            }
         }
-        return value;
     }
 };
 
diff --git a/be/test/olap/delete_handler_test.cpp b/be/test/olap/delete_handler_test.cpp
index c9d94a36b61..cbf9d35195c 100644
--- a/be/test/olap/delete_handler_test.cpp
+++ b/be/test/olap/delete_handler_test.cpp
@@ -25,6 +25,7 @@
 #include <gen_cpp/olap_file.pb.h>
 #include <gtest/gtest-message.h>
 #include <gtest/gtest-test-part.h>
+#include <gtest/gtest.h>
 #include <unistd.h>
 
 #include <cstdlib>
@@ -1064,8 +1065,8 @@ TEST_F(TestDeleteHandler, ValueWithQuote) {
 
     add_delete_predicate(del_predicate, 2);
 
-    auto res = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5);
-    EXPECT_EQ(Status::OK(), res);
+    EXPECT_ANY_THROW(
+            auto st = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5));
 }
 
 TEST_F(TestDeleteHandler, ValueWithoutQuote) {
@@ -1076,8 +1077,8 @@ TEST_F(TestDeleteHandler, ValueWithoutQuote) {
 
     add_delete_predicate(del_predicate, 2);
 
-    auto res = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5);
-    EXPECT_EQ(Status::OK(), res);
+    EXPECT_ANY_THROW(
+            auto res = _delete_handler.init(tablet->tablet_schema(), get_delete_predicates(), 5));
 }
 
 TEST_F(TestDeleteHandler, InitSuccess) {
diff --git a/regression-test/data/query_p0/sql_functions/conditional_functions/test_query_in.out b/regression-test/data/query_p0/sql_functions/conditional_functions/test_query_in.out
index a1e7bf9f94e..5146ddbea68 100644
--- a/regression-test/data/query_p0/sql_functions/conditional_functions/test_query_in.out
+++ b/regression-test/data/query_p0/sql_functions/conditional_functions/test_query_in.out
@@ -97,3 +97,17 @@ jj	-28532
 false	1	1989	1001	11011902	123.123	true	1989-03-21	1989-03-21T13:00	wangjuoo4	0.1	6.333	string12345	170141183460469231731687303715884105727
 false	3	1989	1002	11011905	24453.325	false	2012-03-14	2000-01-01T00:00	yunlj8@nk	78945.0	3654.0	string12345	0
 
+-- !in33 --
+1	1e+308
+2	Infinity
+3	9.999999999999999e-309
+
+-- !in34 --
+1	1e+308
+
+-- !in35 --
+2	Infinity
+
+-- !in36 --
+3	9.999999999999999e-309
+
diff --git a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_query_in.groovy b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_query_in.groovy
index 6cd267dee71..96ac3c63306 100644
--- a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_query_in.groovy
+++ b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_query_in.groovy
@@ -61,4 +61,17 @@ suite("test_query_in", "query,p0") {
     qt_in31 """select * from (select 'jj' as kk1, sum(k2) from ${tableName2} where k10 = '2015-04-02' group by kk1)tt
             where kk1 = 'jj'"""
     qt_in32 """select * from ${tableName1} where cast(k1 as char) in (1, -1, 5, 0.1, 3.000) order by k1, k2, k3, k4"""
+
+    sql """ drop table if exists double_test_out_of_range; """
+    sql """
+        create table double_test_out_of_range (
+            id int,
+            v double
+        ) properties("replication_num" = "1");
+    """
+    sql """ insert into double_test_out_of_range values (1, 1e308), (2, 1e309), (3, 1e-308); """
+    qt_in33 """ select * from double_test_out_of_range order by id; """
+    qt_in34 """ select * from double_test_out_of_range where v = 1e308; """
+    qt_in35 """ select * from double_test_out_of_range where v = 1e309; """
+    qt_in36 """ select * from double_test_out_of_range where v = 1e-308; """
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org