Add split function
CompletedCurrently you must use a javascript call to split a string. This does not get pushed down to the source and is very slow.
-
Comment actionsOfficial comment
Hi all,
I'm happy to report that we now released the SPLIT_PART function as part of LDW 2.3.8.
Best
Niklas
-
Here is a split function implemented as a user-defined procedure. It is implemented quite quick and dirty, for example i did not try what happens if Input is NULL. But you dont need javascript. Usage example:
call "mySchema.split"(
"string_to_split" => 'foobar',
"split_expression" => 'o'
);;CREATE procedure "mySchema"."split" (
IN string_to_split string not null Options (Annotation 'string to split'),
IN split_expression string not null Options (Annotation 'expression where to split the string')
) RETURNS (
array_of_strings object
) Options (Annotation 'Split a string at a given expression. Example: split(foobar, o) -> [f, bar]')as
begin
declare object array_of_strings = array();
declare string rest_of_string = string_to_split;
declare string first_part;
declare string second_part;
while (locate(split_expression, rest_of_string) > 0)
begin
first_part = substring(rest_of_string from 1 for (locate(split_expression, rest_of_string) - 1)); /* kann leerer String sein */
second_part = substring(rest_of_string, locate(split_expression, rest_of_string) + length(split_expression)); /* kann null sein */
if (first_part <> '') /* erste Zeichen von rest_of_string sind nicht die split_expression */
begin
array_of_strings = array_add(array_of_strings, first_part);
end
rest_of_string = second_part;
end
if (rest_of_string is not null) /* erste Zeichen von rest_of_string sind nicht die split_expression */
begin
array_of_strings = array_add(array_of_strings, rest_of_string);
end
/* Leerer Input-String -> Leeres Array */
if (length(string_to_split) = 0)
begin
select array();
end
select array_of_strings;
end;
Please sign in to leave a comment.
Comments
3 comments