BiteTheDDDDt commented on code in PR #18565:
URL: https://github.com/apache/doris/pull/18565#discussion_r1171057112


##########
be/src/vec/functions/function_cast.h:
##########
@@ -62,7 +65,91 @@ inline UInt32 extract_to_decimal_scale(const 
ColumnWithTypeAndName& named_column
     named_column.column->get(0, field);
     return field.get<UInt32>();
 }
+/** Cast from string or number to Time.
+  * In Doris, the underlying storage type of the Time class is Float64.
+  */
+struct TimeCast {
+    // Cast from string
+    // Some examples of conversions.
+    // '300' -> 00:03:00 '20:23' ->  20:23:00 '20:23:24' -> 20:23:24
+    template <typename T>
+    static bool try_parse_time(char* s, size_t len, T& x) {
+        char* first_char = s;
+        char* end_char = s + len;
+        int hour = 0, minute = 0, second = 0;
+        auto parse_from_str_to_int = [](char* begin, size_t len, auto& num) {
+            StringParser::ParseResult parse_result = 
StringParser::PARSE_SUCCESS;
+            auto int_value = StringParser::string_to_unsigned_int<uint64_t>(
+                    reinterpret_cast<char*>(begin), len, &parse_result);
+            if (UNLIKELY(parse_result != StringParser::PARSE_SUCCESS)) {
+                return false;
+            }
+            num = int_value;
+            return true;
+        };
+        char *first_colon {nullptr}, *second_colon {nullptr};
+        if ((first_colon = (char*)memchr(first_char, ':', len)) != nullptr) {

Review Comment:
   better use `If statements with initializer`
   if(x=y;x){
   }



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to