xiaokang commented on code in PR #38683:
URL: https://github.com/apache/doris/pull/38683#discussion_r1705106872


##########
be/src/vec/functions/function_cast.h:
##########
@@ -856,12 +856,19 @@ struct ConvertImplFromJsonb {
                     res[i] = 0;
                     continue;
                 }
-
                 if constexpr (type_index == TypeIndex::UInt8) {
+                    // cast from json value to boolean type
                     if (value->isTrue()) {
                         res[i] = 1;
                     } else if (value->isFalse()) {
                         res[i] = 0;
+                    } else if (value->isInt()) {
+                        res[i] = ((const JsonbIntVal*)value)->val() > 0 ? 1 : 
0;

Review Comment:
   It more common to use `val() == 0 ? 0 : 1`. And `CAST(-1 AS BOOLEAN) ` 
return 1 in Doris.



##########
be/src/vec/functions/function_cast.h:
##########
@@ -856,12 +856,19 @@ struct ConvertImplFromJsonb {
                     res[i] = 0;
                     continue;
                 }
-
                 if constexpr (type_index == TypeIndex::UInt8) {
+                    // cast from json value to boolean type
                     if (value->isTrue()) {
                         res[i] = 1;
                     } else if (value->isFalse()) {
                         res[i] = 0;
+                    } else if (value->isInt()) {
+                        res[i] = ((const JsonbIntVal*)value)->val() > 0 ? 1 : 
0;
+                    } else if (value->isDouble()) {
+                        res[i] = static_cast<ColumnType::value_type>(
+                                         ((const 
JsonbDoubleVal*)value)->val()) > 0

Review Comment:
   == 0 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to