File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed
src/carnot/funcs/builtins Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -235,22 +235,19 @@ class SplitUDF : public udf::ScalarUDF {
235235 rapidjson::Writer<rapidjson::StringBuffer> writer (sb);
236236 writer.StartArray ();
237237
238- std::string_view s (in.data (), in.size ());
239- size_t idx = 0 ;
240- while (idx < s.size ()) {
241- auto next_idx = s.find (delimiter.data (), idx);
242- if (next_idx == std::string::npos) {
243- if (idx > 0 ) {
244- writer.String (s.substr (idx).data (), s.substr (idx).size ());
245- }
246- break ;
238+ std::vector<absl::string_view> parts = absl::StrSplit (in.data (), delimiter.data ());
239+
240+ // Verify that delimiter was found in the input string before
241+ // writing the array entries.
242+ if (parts.size () > 1 || parts[0 ] != in.data ()) {
243+ for (auto part : parts) {
244+ writer.String (part.data (), part.size ());
247245 }
248- writer.String (s.substr (idx, next_idx - idx).data (), next_idx - idx);
249- idx = next_idx + delimiter.size ();
250246 }
251247 writer.EndArray ();
252248 return sb.GetString ();
253249 }
250+
254251 static udf::ScalarUDFDocBuilder Doc () {
255252 return udf::ScalarUDFDocBuilder (
256253 " Splits a string by a delimiter and a returns JSON encoded array of strings." )
You can’t perform that action at this time.
0 commit comments