[fix][vectorized] Fix error cast to boolean (#8345)
This commit is contained in:
@ -138,6 +138,13 @@ struct ConvertImpl {
|
||||
vec_to[i] = static_cast<ToFieldType>(vec_from[i]);
|
||||
}
|
||||
|
||||
// TODO: support boolean cast more reasonable
|
||||
if constexpr (std::is_same_v<uint8_t, ToFieldType>) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
vec_to[i] = static_cast<bool>(vec_to[i]);
|
||||
}
|
||||
}
|
||||
|
||||
block.replace_by_position(result, std::move(col_to));
|
||||
} else {
|
||||
return Status::RuntimeError(
|
||||
@ -315,6 +322,11 @@ bool try_parse_impl(typename DataType::FieldType& x, ReadBuffer& rb, const DateL
|
||||
return try_read_float_text(x, rb);
|
||||
}
|
||||
|
||||
// uint8_t now use as boolean in doris
|
||||
if constexpr (std::is_same_v<typename DataType::FieldType, uint8_t>) {
|
||||
return try_read_bool_text(x, rb);
|
||||
}
|
||||
|
||||
if constexpr (std::is_integral_v<typename DataType::FieldType>) {
|
||||
return try_read_int_text(x, rb);
|
||||
}
|
||||
|
||||
@ -294,6 +294,23 @@ bool read_decimal_text_impl(T& x, ReadBuffer& buf) {
|
||||
return ans;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool try_read_bool_text(T& x, ReadBuffer& buf) {
|
||||
if (read_int_text_impl<T>(x, buf)) {
|
||||
return x == 0 || x == 1;
|
||||
}
|
||||
|
||||
StringParser::ParseResult result;
|
||||
x = StringParser::string_to_bool(buf.position(), buf.count(), &result);
|
||||
if (UNLIKELY(result != StringParser::PARSE_SUCCESS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only to match the is_all_read() check to prevent return null
|
||||
buf.position() = buf.end();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool try_read_int_text(T& x, ReadBuffer& buf) {
|
||||
return read_int_text_impl<T>(x, buf);
|
||||
|
||||
Reference in New Issue
Block a user