[Bug](function) change log fatal to log warning to avoid code dump on nullable double column cast to decimal column (#13819)

This commit is contained in:
Pxl
2022-11-01 09:54:35 +08:00
committed by GitHub
parent 7f2166b1fd
commit 164ca1e1a8
2 changed files with 13 additions and 9 deletions

View File

@ -37,8 +37,9 @@ std::string DataTypeDecimal<T>::do_get_name() const {
template <typename T>
bool DataTypeDecimal<T>::equals(const IDataType& rhs) const {
if (auto* ptype = typeid_cast<const DataTypeDecimal<T>*>(&rhs))
if (auto* ptype = typeid_cast<const DataTypeDecimal<T>*>(&rhs)) {
return scale == ptype->get_scale();
}
return false;
}
@ -154,7 +155,7 @@ T DataTypeDecimal<T>::parse_from_string(const std::string& str) const {
T value = StringParser::string_to_decimal<__int128>(str.c_str(), str.size(), precision, scale,
&result);
if (result != StringParser::PARSE_SUCCESS) {
LOG(FATAL) << "Failed to parse string of decimal";
LOG(WARNING) << "Failed to parse string of decimal";
}
return value;
}
@ -169,10 +170,11 @@ DataTypePtr create_decimal(UInt64 precision_value, UInt64 scale_value) {
LOG(FATAL) << "Negative scales and scales larger than precision are not supported";
}
if (precision_value <= max_decimal_precision<Decimal32>())
if (precision_value <= max_decimal_precision<Decimal32>()) {
return std::make_shared<DataTypeDecimal<Decimal32>>(precision_value, scale_value);
else if (precision_value <= max_decimal_precision<Decimal64>())
} else if (precision_value <= max_decimal_precision<Decimal64>()) {
return std::make_shared<DataTypeDecimal<Decimal64>>(precision_value, scale_value);
}
return std::make_shared<DataTypeDecimal<Decimal128>>(precision_value, scale_value);
}
@ -210,7 +212,7 @@ void convert_to_decimal(T* from_value, T* to_value, int32_t from_scale, int32_t
static_cast<T>(DataTypeDecimal<Decimal<T>>::get_scale_multiplier(
to_scale - from_scale)),
*to_value)) {
LOG(FATAL) << "Decimal convert overflow";
LOG(WARNING) << "Decimal convert overflow";
}
}
}

View File

@ -376,19 +376,21 @@ convert_to_decimal(const typename FromDataType::FieldType& value, UInt32 scale)
if constexpr (std::is_floating_point_v<FromFieldType>) {
if (!std::isfinite(value)) {
LOG(FATAL) << "Decimal convert overflow. Cannot convert infinity or NaN to decimal";
LOG(WARNING) << "Decimal convert overflow. Cannot convert infinity or NaN to decimal";
}
auto out = value * ToDataType::get_scale_multiplier(scale);
if (out <= static_cast<FromFieldType>(std::numeric_limits<ToNativeType>::min()) ||
out >= static_cast<FromFieldType>(std::numeric_limits<ToNativeType>::max())) {
LOG(FATAL) << "Decimal convert overflow. Float is out of Decimal range";
LOG(WARNING) << "Decimal convert overflow. Float is out of Decimal range";
}
return out;
} else {
if constexpr (std::is_same_v<FromFieldType, UInt64>)
if (value > static_cast<UInt64>(std::numeric_limits<Int64>::max()))
if constexpr (std::is_same_v<FromFieldType, UInt64>) {
if (value > static_cast<UInt64>(std::numeric_limits<Int64>::max())) {
return convert_decimals<DataTypeDecimal<Decimal128>, ToDataType>(value, 0, scale);
}
}
return convert_decimals<DataTypeDecimal<Decimal64>, ToDataType>(value, 0, scale);
}
}