diff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h index 85d95f47f06..75b4a33bc1c 100644 --- a/src/Functions/FunctionsConversion.h +++ b/src/Functions/FunctionsConversion.h @@ -576,77 +576,82 @@ template struct ConvertImpl +template struct FormatImpl { - static bool execute(const typename DataType::FieldType x, WriteBuffer & wb, const DataType *, const DateLUTImpl *) + template + static ReturnType execute(const typename DataType::FieldType x, WriteBuffer & wb, const DataType *, const DateLUTImpl *) { writeText(x, wb); - return true; + return ReturnType(true); } }; -template -struct FormatImpl +template <> +struct FormatImpl { - static bool execute(const DataTypeDate::FieldType x, WriteBuffer & wb, const DataTypeDate *, const DateLUTImpl *) + template + static ReturnType execute(const DataTypeDate::FieldType x, WriteBuffer & wb, const DataTypeDate *, const DateLUTImpl *) { writeDateText(DayNum(x), wb); - return true; + return ReturnType(true); } }; -template -struct FormatImpl +template <> +struct FormatImpl { - static bool execute(const DataTypeDateTime::FieldType x, WriteBuffer & wb, const DataTypeDateTime *, const DateLUTImpl * time_zone) + template + static ReturnType execute(const DataTypeDateTime::FieldType x, WriteBuffer & wb, const DataTypeDateTime *, const DateLUTImpl * time_zone) { writeDateTimeText(x, wb, *time_zone); - return true; + return ReturnType(true); } }; -template -struct FormatImpl +template <> +struct FormatImpl { - static bool execute(const DataTypeDateTime64::FieldType x, WriteBuffer & wb, const DataTypeDateTime64 * type, const DateLUTImpl * time_zone) + template + static ReturnType execute(const DataTypeDateTime64::FieldType x, WriteBuffer & wb, const DataTypeDateTime64 * type, const DateLUTImpl * time_zone) { writeDateTimeText(DateTime64(x), type->getScale(), wb, *time_zone); - return true; + return ReturnType(true); } }; template -struct FormatImpl, false> +struct FormatImpl> { - static bool execute(const FieldType x, WriteBuffer & wb, const DataTypeEnum * type, const DateLUTImpl *) + template + static ReturnType execute(const FieldType x, WriteBuffer & wb, const DataTypeEnum * type, const DateLUTImpl *) { - StringRef res; - bool is_ok = type->getNameForValue(x, res); - if (is_ok) - writeString(res, wb); - return is_ok; + static constexpr bool throw_exception = std::is_same_v; + + if constexpr (throw_exception) + { + writeString(type->getNameForValue(x), wb); + } + else + { + StringRef res; + bool is_ok = type->getNameForValue(x, res); + if (is_ok) + writeString(res, wb); + return ReturnType(is_ok); + } } }; template -struct FormatImpl, true> +struct FormatImpl> { - static bool execute(const FieldType x, WriteBuffer & wb, const DataTypeEnum * type, const DateLUTImpl *) - { - writeString(type->getNameForValue(x), wb); - return true; - } -}; - -template -struct FormatImpl, throws> -{ - static bool execute(const FieldType x, WriteBuffer & wb, const DataTypeDecimal * type, const DateLUTImpl *) + template + static ReturnType execute(const FieldType x, WriteBuffer & wb, const DataTypeDecimal * type, const DateLUTImpl *) { writeText(x, type->getScale(), wb); - return true; + return ReturnType(true); } }; @@ -716,12 +721,12 @@ struct ConvertImpl::execute(vec_from[i], write_buffer, &type, time_zone); + bool is_ok = FormatImpl::template execute(vec_from[i], write_buffer, &type, time_zone); null_map->getData()[i] |= !is_ok; } else { - FormatImpl::execute(vec_from[i], write_buffer, &type, time_zone); + FormatImpl::template execute(vec_from[i], write_buffer, &type, time_zone); } writeChar(0, write_buffer); offsets_to[i] = write_buffer.count();