You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@doris.apache.org by GitBox <gi...@apache.org> on 2019/07/09 01:32:22 UTC

[GitHub] [incubator-doris] chenhao7253886 commented on a change in pull request #1445: Add string function split_part

chenhao7253886 commented on a change in pull request #1445: Add string function split_part
URL: https://github.com/apache/incubator-doris/pull/1445#discussion_r301363914
 
 

 ##########
 File path: be/src/exprs/string_functions.cpp
 ##########
 @@ -761,4 +761,61 @@ StringVal StringFunctions::money_format(FunctionContext *context, const LargeInt
     return do_money_format(context, ss.str());
 }
 
+static int indexOf(const uint8_t* source, int sourceOffset, int sourceCount,
+                const uint8_t* target, int targetOffset, int targetCount,
+                int fromIndex) {
+    if (fromIndex >= sourceCount) {
+        return (targetCount == 0 ? sourceCount : -1);
+    }
+    if (fromIndex < 0) {
+        fromIndex = 0;
+    }
+    if (targetCount == 0) {
+        return fromIndex;
+    }
+    const uint8_t first = target[targetOffset];
+    int max = sourceOffset + (sourceCount - targetCount);
+    for (int i = sourceOffset + fromIndex; i <= max; i++) {
+        if (source[i] != first) { // Look for first character
+            while (++i <= max && source[i] != first);
+        }
+        if (i <= max) { // Found first character, now look at the rest of v2
+            int j = i + 1;
+            int end = j + targetCount - 1;
+            for (int k = targetOffset + 1; j < end && source[j] == target[k]; j++, k++);
+            if (j == end) {
+                return i - sourceOffset; // Found whole string.
+            }
+        }
+    }
+    return -1;
+}
+
+
+StringVal StringFunctions::split_part(FunctionContext* context,const StringVal& content,
+                                      const StringVal& delimiter,const IntVal& field) {
+    if (field.val <= 0) return StringVal::null();
 
 Review comment:
   What if content、delimiter or field is null?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org