Skip to content

Commit

Permalink
Adds doc and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanConfluent committed May 29, 2020
1 parent ef5ffa6 commit ddebccd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/developer-guide/ksqldb-reference/scalar-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ keywords: ksqlDB, function, scalar
- [MASK_RIGHT](#mask_right)
- [REPLACE](#replace)
- [REGEXP_EXTRACT](#regexp_extract)
- [REGEXP_SPLIT](#regexp_split)
- [SPLIT](#split)
- [SUBSTRING](#substring)
- [TRIM](#trim)
Expand Down Expand Up @@ -413,6 +414,23 @@ the entire substring is returned by default.
For example, `REGEXP_EXTRACT("(.*) (.*)", 'hello there', 2)`
returns "there".

REGEXP_SPLIT
-----

`REGEXP_SPLIT(col1, 'a.b+')`

Splits a string into an array of substrings based
on a regular expression. If there is no match,
then the original string is returned as the only
element in the array. If the regular expression is empty,
then all characters in the string are split.
If either, string or regular expression, are NULL, then a
NULL value is returned.

If the regular expression is found at the beginning or end
of the string, or there are contiguous delimiters,
then an empty space is added to the array.

SPLIT
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@
{"topic": "OUTPUT", "key": "3", "value": {"S1": "A", "S2": "A"}, "timestamp": 0},
{"topic": "OUTPUT", "key": "4", "value": {"S1": "1", "S2": "3"}, "timestamp": 0}
]
},
{
"name": "regexp_split",
"statements": [
"CREATE STREAM TEST (K STRING KEY, input_string VARCHAR) WITH (kafka_topic='test_topic', value_format='JSON');",
"CREATE STREAM OUTPUT AS SELECT K, REGEXP_SPLIT(input_string, '(ab|cd)') AS EXTRACTED FROM TEST;"
],
"inputs": [
{"topic": "test_topic", "value": {"input_string": "aabcda"}},
{"topic": "test_topic", "value": {"input_string": "aabdcda"}},
{"topic": "test_topic", "value": {"input_string": "zxy"}},
{"topic": "test_topic", "value": {"input_string": null}}
],
"outputs": [
{"topic": "OUTPUT", "value": {"EXTRACTED": ["a", "", "a"]}},
{"topic": "OUTPUT", "value": {"EXTRACTED": ["a", "d", "a"]}},
{"topic": "OUTPUT", "value": {"EXTRACTED": ["zxy"]}},
{"topic": "OUTPUT", "value": {"EXTRACTED": null}}
]
}
]
}

0 comments on commit ddebccd

Please sign in to comment.