Skip to content
Merged
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
37 changes: 30 additions & 7 deletions be/src/olap/predicate_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -65,15 +74,29 @@ class IntegerPredicateCreator : public PredicateCreator<ConditionType> {
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;
}
};

Expand Down
9 changes: 5 additions & 4 deletions be/test/olap/delete_handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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; """
}
Loading