mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-19 14:11:58 +00:00
Remove IsConvertible()
This commit is contained in:
parent
c032dee3b4
commit
cf886d8ced
@ -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<Additions, DateTimeAccurateConvertStrategyAdditions>
|
||||
|| std::is_same_v<Additions, DateTimeAccurateOrNullConvertStrategyAdditions>)
|
||||
{
|
||||
t.IsConvertible(vec_from[i], time_zone);
|
||||
};
|
||||
bool check_range_result = true;
|
||||
|
||||
if constexpr (transformHasIsConvertible)
|
||||
{
|
||||
if constexpr (std::is_same_v<Additions, DateTimeAccurateConvertStrategyAdditions>
|
||||
|| std::is_same_v<Additions, DateTimeAccurateOrNullConvertStrategyAdditions>)
|
||||
if constexpr (std::is_same_v<ToType, DataTypeDate>)
|
||||
{
|
||||
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<ToType, DataTypeDateTime>)
|
||||
{
|
||||
check_range_result = vec_from[i] >= 0 && vec_from[i] <= 0xFFFFFFFFL;
|
||||
}
|
||||
|
||||
if (!check_range_result)
|
||||
{
|
||||
if (std::is_same_v<Additions, DateTimeAccurateOrNullConvertStrategyAdditions>)
|
||||
{
|
||||
if (std::is_same_v<Additions, DateTimeAccurateOrNullConvertStrategyAdditions>)
|
||||
{
|
||||
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 FromTypeVector::value_type>, TypeName<ValueType>);
|
||||
}
|
||||
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<FromType>, TypeName<ToType>);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<typename FromDataType::FieldType, typename ToDataType::FieldType, Transform, is_extended_result, Additions>;
|
||||
using Op = Transformer<FromDataType, ToDataType, Transform, is_extended_result, Additions>;
|
||||
|
||||
const ColumnPtr source_col = arguments[0].column;
|
||||
if (const auto * sources = checkAndGetColumn<typename FromDataType::ColumnType>(source_col.get()))
|
||||
|
@ -365,22 +365,11 @@ template <typename Name> struct ConvertImpl<DataTypeDate32, DataTypeDateTime, Na
|
||||
|
||||
/// Implementation of toDate function.
|
||||
|
||||
template <typename FromType>
|
||||
static bool CheckDateRange(const FromType & value)
|
||||
{
|
||||
return value >= 0 && value <= DATE_LUT_MAX_DAY_NUM;
|
||||
}
|
||||
|
||||
template <typename FromType, typename ToType>
|
||||
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 <typename Name> struct ConvertImpl<DataTypeFloat32, DataTypeDate32, Nam
|
||||
template <typename Name> struct ConvertImpl<DataTypeFloat64, DataTypeDate32, Name, ConvertDefaultBehaviorTag>
|
||||
: DateTimeTransformImpl<DataTypeFloat64, DataTypeDate32, ToDate32Transform32Or64Signed<Float64, Int32>> {};
|
||||
|
||||
template <typename FromType>
|
||||
static bool CheckDateTimeRange(const FromType & value)
|
||||
{
|
||||
return value >= 0 && value <= 0xFFFFFFFFL;
|
||||
}
|
||||
|
||||
template <typename FromType, typename ToType>
|
||||
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<ToType>(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)
|
||||
|
Loading…
Reference in New Issue
Block a user