Remove IsConvertible()

This commit is contained in:
Dmitry Kardymon 2023-06-06 11:08:21 +00:00
parent c032dee3b4
commit cf886d8ced
2 changed files with 24 additions and 63 deletions

View File

@ -1443,19 +1443,22 @@ struct Transformer
vec_to.resize(size); vec_to.resize(size);
for (size_t i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
{
constexpr bool transformHasIsConvertible = requires(const Transform& t)
{
t.IsConvertible(vec_from[i], time_zone);
};
if constexpr (transformHasIsConvertible)
{ {
if constexpr (std::is_same_v<Additions, DateTimeAccurateConvertStrategyAdditions> if constexpr (std::is_same_v<Additions, DateTimeAccurateConvertStrategyAdditions>
|| std::is_same_v<Additions, DateTimeAccurateOrNullConvertStrategyAdditions>) || std::is_same_v<Additions, DateTimeAccurateOrNullConvertStrategyAdditions>)
{ {
bool checked = transform.IsConvertible(vec_from[i], time_zone); bool check_range_result = true;
if (!checked)
if constexpr (std::is_same_v<ToType, DataTypeDate>)
{
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>)
{ {
@ -1467,8 +1470,7 @@ struct Transformer
else else
{ {
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Value in column {} cannot be safely converted into type {}", throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Value in column {} cannot be safely converted into type {}",
TypeName<typename FromTypeVector::value_type>, TypeName<ValueType>); TypeName<FromType>, TypeName<ToType>);
}
} }
} }
} }
@ -1488,7 +1490,7 @@ struct DateTimeTransformImpl
static ColumnPtr execute( static ColumnPtr execute(
const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t /*input_rows_count*/, const Transform & transform = {}) 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; const ColumnPtr source_col = arguments[0].column;
if (const auto * sources = checkAndGetColumn<typename FromDataType::ColumnType>(source_col.get())) if (const auto * sources = checkAndGetColumn<typename FromDataType::ColumnType>(source_col.get()))

View File

@ -365,22 +365,11 @@ template <typename Name> struct ConvertImpl<DataTypeDate32, DataTypeDateTime, Na
/// Implementation of toDate function. /// 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> template <typename FromType, typename ToType>
struct ToDateTransform32Or64 struct ToDateTransform32Or64
{ {
static constexpr auto name = "toDate"; 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) 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. // 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 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) static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & time_zone)
{ {
// TODO: decide narrow or extended range based on FromType // TODO: decide narrow or extended range based on FromType
@ -417,11 +401,6 @@ struct ToDateTransform8Or16Signed
{ {
static constexpr auto name = "toDate"; 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 &) static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &)
{ {
if (from < 0) if (from < 0)
@ -518,22 +497,12 @@ template <typename Name> struct ConvertImpl<DataTypeFloat32, DataTypeDate32, Nam
template <typename Name> struct ConvertImpl<DataTypeFloat64, DataTypeDate32, Name, ConvertDefaultBehaviorTag> template <typename Name> struct ConvertImpl<DataTypeFloat64, DataTypeDate32, Name, ConvertDefaultBehaviorTag>
: DateTimeTransformImpl<DataTypeFloat64, DataTypeDate32, ToDate32Transform32Or64Signed<Float64, Int32>> {}; : 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> template <typename FromType, typename ToType>
struct ToDateTimeTransform64 struct ToDateTimeTransform64
{ {
static constexpr auto name = "toDateTime"; 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 &) static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &)
{ {
return static_cast<ToType>(std::min(time_t(from), time_t(0xFFFFFFFF))); return static_cast<ToType>(std::min(time_t(from), time_t(0xFFFFFFFF)));
@ -545,11 +514,6 @@ struct ToDateTimeTransformSigned
{ {
static constexpr auto name = "toDateTime"; 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 &) static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &)
{ {
if (from < 0) if (from < 0)
@ -563,11 +527,6 @@ struct ToDateTimeTransform64Signed
{ {
static constexpr auto name = "toDateTime"; 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 &) static NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl &)
{ {
if (from < 0) if (from < 0)