From 8645a9de6d6671b0de281d27ddd71c95d6237e50 Mon Sep 17 00:00:00 2001 From: Hu Shenggang Date: Fri, 17 Oct 2025 16:10:37 +0800 Subject: [PATCH] [fix](olap) Need to handle floating-point Infinity values in the predicate --- be/src/olap/predicate_creator.h | 37 +++++++++++++++---- be/test/olap/delete_handler_test.cpp | 9 +++-- .../conditional_functions/test_query_in.out | 14 +++++++ .../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 bd0cf761ca2353..2f2abb6ca74a46 100644 --- a/be/src/olap/predicate_creator.h +++ b/be/src/olap/predicate_creator.h @@ -17,9 +17,15 @@ #pragma once +#include + #include +#include +#include #include +#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 @@ class IntegerPredicateCreator : public PredicateCreator { 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) { - value = std::stod(condition, nullptr); - } else if constexpr (std::is_same_v) { - value = std::stof(condition, nullptr); + if constexpr (std::is_floating_point_v) { + 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 c9d94a36b6179f..cbf9d35195c6ee 100644 --- a/be/test/olap/delete_handler_test.cpp +++ b/be/test/olap/delete_handler_test.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -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 a1e7bf9f94e7e2..5146ddbea687be 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 6cd267dee716dd..96ac3c633068ac 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; """ }