From cf886d8ced474a1a80a985587af251a39701d1b2 Mon Sep 17 00:00:00 2001 From: Dmitry Kardymon Date: Tue, 6 Jun 2023 11:08:21 +0000 Subject: [PATCH] Remove IsConvertible() --- src/Functions/DateTimeTransforms.h | 46 +++++++++++++++-------------- src/Functions/FunctionsConversion.h | 41 ------------------------- 2 files changed, 24 insertions(+), 63 deletions(-) diff --git a/src/Functions/DateTimeTransforms.h b/src/Functions/DateTimeTransforms.h index d154dd9ffa2..823272e0324 100644 --- a/src/Functions/DateTimeTransforms.h +++ b/src/Functions/DateTimeTransforms.h @@ -1444,31 +1444,33 @@ struct Transformer for (size_t i = 0; i < size; ++i) { - constexpr bool transformHasIsConvertible = requires(const Transform& t) + if constexpr (std::is_same_v + || std::is_same_v) { - t.IsConvertible(vec_from[i], time_zone); - }; + bool check_range_result = true; - if constexpr (transformHasIsConvertible) - { - if constexpr (std::is_same_v - || std::is_same_v) + if constexpr (std::is_same_v) { - bool checked = transform.IsConvertible(vec_from[i], time_zone); - if (!checked) + check_range_result = vec_from[i] >= 0 && vec_from[i] <= DATE_LUT_MAX_DAY_NUM; + } + else if constexpr (std::is_same_v) + { + check_range_result = vec_from[i] >= 0 && vec_from[i] <= 0xFFFFFFFFL; + } + + if (!check_range_result) + { + if (std::is_same_v) { - if (std::is_same_v) - { - vec_to[i] = 0; - if (vec_null_map_to) - (*vec_null_map_to)[i] = true; - continue; - } - else - { - throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Value in column {} cannot be safely converted into type {}", - TypeName, TypeName); - } + vec_to[i] = 0; + if (vec_null_map_to) + (*vec_null_map_to)[i] = true; + continue; + } + else + { + throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Value in column {} cannot be safely converted into type {}", + TypeName, TypeName); } } } @@ -1488,7 +1490,7 @@ struct DateTimeTransformImpl static ColumnPtr execute( const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t /*input_rows_count*/, const Transform & transform = {}) { - using Op = Transformer; + using Op = Transformer; const ColumnPtr source_col = arguments[0].column; if (const auto * sources = checkAndGetColumn(source_col.get())) diff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h index 6aa5843ff65..3a8ddcc9094 100644 --- a/src/Functions/FunctionsConversion.h +++ b/src/Functions/FunctionsConversion.h @@ -365,22 +365,11 @@ template struct ConvertImpl -static bool CheckDateRange(const FromType & value) -{ - return value >= 0 && value <= DATE_LUT_MAX_DAY_NUM; -} - template struct ToDateTransform32Or64 { static constexpr auto name = "toDate"; - static NO_SANITIZE_UNDEFINED bool IsConvertible(const FromType & from, const DateLUTImpl &) - { - return CheckDateRange(from); - } - static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & time_zone) { // since converting to Date, no need in values outside of default LUT range. @@ -395,11 +384,6 @@ struct ToDateTransform32Or64Signed { static constexpr auto name = "toDate"; - static NO_SANITIZE_UNDEFINED bool IsConvertible(const FromType & from, const DateLUTImpl &) - { - return CheckDateRange(from); - } - static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & time_zone) { // TODO: decide narrow or extended range based on FromType @@ -417,11 +401,6 @@ struct ToDateTransform8Or16Signed { static constexpr auto name = "toDate"; - static NO_SANITIZE_UNDEFINED bool IsConvertible(const FromType & from, const DateLUTImpl &) - { - return CheckDateRange(from); - } - static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &) { if (from < 0) @@ -518,22 +497,12 @@ template struct ConvertImpl struct ConvertImpl : DateTimeTransformImpl> {}; -template -static bool CheckDateTimeRange(const FromType & value) -{ - return value >= 0 && value <= 0xFFFFFFFFL; -} template struct ToDateTimeTransform64 { static constexpr auto name = "toDateTime"; - static NO_SANITIZE_UNDEFINED bool IsConvertible(const FromType & from, const DateLUTImpl &) - { - return CheckDateTimeRange(from); - } - static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &) { return static_cast(std::min(time_t(from), time_t(0xFFFFFFFF))); @@ -545,11 +514,6 @@ struct ToDateTimeTransformSigned { static constexpr auto name = "toDateTime"; - static NO_SANITIZE_UNDEFINED bool IsConvertible(const FromType & from, const DateLUTImpl &) - { - return CheckDateTimeRange(from); - } - static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &) { if (from < 0) @@ -563,11 +527,6 @@ struct ToDateTimeTransform64Signed { static constexpr auto name = "toDateTime"; - static NO_SANITIZE_UNDEFINED bool IsConvertible(const FromType & from, const DateLUTImpl &) - { - return CheckDateTimeRange(from); - } - static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &) { if (from < 0)