This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch dev-1.0.0
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git

commit 15b09d1692c10a58225569d2d2e34ffd41ec4d42
Author: HappenLee <[email protected]>
AuthorDate: Sun Mar 6 13:47:46 2022 +0800

    [fix][vectorized] Fix error cast to boolean (#8345)
---
 be/src/vec/functions/function_cast.h | 12 ++++++++++++
 be/src/vec/io/io_helper.h            | 17 +++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/be/src/vec/functions/function_cast.h 
b/be/src/vec/functions/function_cast.h
index 053d44c..144b782 100644
--- a/be/src/vec/functions/function_cast.h
+++ b/be/src/vec/functions/function_cast.h
@@ -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);
     }
diff --git a/be/src/vec/io/io_helper.h b/be/src/vec/io/io_helper.h
index 99253c9..dafbed6 100644
--- a/be/src/vec/io/io_helper.h
+++ b/be/src/vec/io/io_helper.h
@@ -295,6 +295,23 @@ bool read_decimal_text_impl(T& x, ReadBuffer& buf) {
 }
 
 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);
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to