zclllyybb commented on code in PR #32065:
URL: https://github.com/apache/doris/pull/32065#discussion_r1527532294


##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -211,15 +211,222 @@ struct StrToDate {
         size_t size = loffsets.size();
         res.resize(size);
         const StringRef format_str = rewrite_specific_format(rdata.data, 
rdata.size);
-        for (size_t i = 0; i < size; ++i) {
-            const char* l_raw_str = reinterpret_cast<const 
char*>(&ldata[loffsets[i - 1]]);
-            size_t l_str_size = loffsets[i] - loffsets[i - 1];
+        const static std::string simple_format[3] = {"%Y-%m-%d", "%Y-%m-%d 
%H:%i:%s", "%H:%i:%s"};
+        static constexpr int s_days_in_month[13] = {0,  31, 28, 31, 30, 31, 30,
+                                                    31, 31, 30, 31, 30, 31};
+        const static auto str_to_int64 = [](const char* ptr, const char** 
endptr,
+                                            int64_t* ret) -> bool {
+            const static uint64_t MAX_NEGATIVE_NUMBER = 0x8000000000000000;
+            const static uint64_t ULONGLONG_MAX = ~0;
+            const static uint64_t LFACTOR2 = 100000000000ULL;
+            const char* end = *endptr;
+            uint64_t cutoff_1 = 0;
+            uint64_t cutoff_2 = 0;
+            uint64_t cutoff_3 = 0;
+            // Skip space
+            while (ptr < end && (*ptr == ' ' || *ptr == '\t')) {
+                ptr++;
+            }
+            if (ptr >= end) {
+                return false;
+            }
+            // Sign
+            bool neg = false;
+            if (*ptr == '-') {
+                neg = true;
+                ptr++;
+                cutoff_1 = MAX_NEGATIVE_NUMBER / LFACTOR2;
+                cutoff_2 = (MAX_NEGATIVE_NUMBER % LFACTOR2) / 100;
+                cutoff_3 = (MAX_NEGATIVE_NUMBER % LFACTOR2) % 100;
+            } else {
+                if (*ptr == '+') {
+                    ptr++;
+                }
+                cutoff_1 = ULONGLONG_MAX / LFACTOR2;
+                cutoff_2 = (ULONGLONG_MAX % LFACTOR2) / 100;
+                cutoff_3 = (ULONGLONG_MAX % LFACTOR2) % 100;
+            }
+            if (ptr >= end) {
+                return false;
+            }
+            // a valid input should at least contains one digit
+            if (!isdigit(*ptr)) {
+                return false;
+            }
+            // Skip '0'
+            while (ptr < end && *ptr == '0') {
+                ptr++;
+            }
+            const char* n_end = ptr + 9;
+            if (n_end > end) {
+                n_end = end;
+            }
+            uint64_t value_1 = 0;
+            while (ptr < n_end && isdigit(*ptr)) {
+                value_1 *= 10;
+                value_1 += *ptr++ - '0';
+            }
+            if (ptr == end || !isdigit(*ptr)) {
+                *endptr = ptr;
+                *ret = neg ? -value_1 : value_1;
+                return true;
+            }
+            uint64_t value_2 = 0;
+            uint64_t value_3 = 0;
+
+            // Check overflow.
+            return value_1 <= cutoff_1 &&
+                   (value_1 != cutoff_1 ||
+                    (value_2 <= cutoff_2 && (value_2 != cutoff_2 || value_3 <= 
cutoff_3)));
+        };
+        if (format_str == StringRef {simple_format[0].data(), 
simple_format[0].size()}) {

Review Comment:
   split the branches to diifferent function



##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -211,15 +211,222 @@ struct StrToDate {
         size_t size = loffsets.size();
         res.resize(size);
         const StringRef format_str = rewrite_specific_format(rdata.data, 
rdata.size);
-        for (size_t i = 0; i < size; ++i) {
-            const char* l_raw_str = reinterpret_cast<const 
char*>(&ldata[loffsets[i - 1]]);
-            size_t l_str_size = loffsets[i] - loffsets[i - 1];
+        const static std::string simple_format[3] = {"%Y-%m-%d", "%Y-%m-%d 
%H:%i:%s", "%H:%i:%s"};
+        static constexpr int s_days_in_month[13] = {0,  31, 28, 31, 30, 31, 30,
+                                                    31, 31, 30, 31, 30, 31};
+        const static auto str_to_int64 = [](const char* ptr, const char** 
endptr,

Review Comment:
   no need to move this function here



-- 
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