Skip to content

Commit

Permalink
Enable and update parse doctest
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <joshuali925@gmail.com>
  • Loading branch information
joshuali925 committed Mar 3, 2022
1 parent f9cbbe5 commit 578c6b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/category.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"user/ppl/cmd/dedup.rst",
"user/ppl/cmd/eval.rst",
"user/ppl/cmd/fields.rst",
"user/ppl/cmd/parse.rst",
"user/ppl/cmd/rename.rst",
"user/ppl/cmd/search.rst",
"user/ppl/cmd/sort.rst",
Expand Down
34 changes: 25 additions & 9 deletions docs/user/ppl/cmd/parse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ The regular expression is used to match the whole text field of each document wi
Example 1: Create the new field
===============================

The example shows how to create new field ``host`` for each document. ``host`` will be the host name after ``@`` in ``email`` field.
The example shows how to create new field ``host`` for each document. ``host`` will be the host name after ``@`` in ``email`` field. Parsing a null field will return an empty string.

PPL query::

os> source=accounts | parse email '.+@(?<host>.+)' | fields email, host ;
fetched rows / total rows = 4/4
+--------------------------+-------------+
| email | host |
|--------------------------+-------------|
| amberduke@pyrami.com | pyrami.com |
| hattiebond@netagy.com | netagy.com |
| nanettebates@quility.com | quility.com |
| daleadams@boink.com | boink.com |
+--------------------------+-------------+
+-----------------------+------------+
| email | host |
|-----------------------+------------|
| amberduke@pyrami.com | pyrami.com |
| hattiebond@netagy.com | netagy.com |
| null | |
| daleadams@boink.com | boink.com |
+-----------------------+------------+


Example 2: Override the existing field
Expand All @@ -63,6 +63,22 @@ PPL query::
| Hutchinson Court |
+------------------+

Example 3: Filter and sort by casted parsed field
=================================================

The example shows how to sort street numbers that are higher than 500 in ``address`` field.

PPL query::

os> source=accounts | parse address '(?<streetNumber>\d+) (?<street>.+)' | where cast(streetNumber as int) > 500 | sort num(streetNumber) | fields streetNumber, street ;
fetched rows / total rows = 3/3
+----------------+----------------+
| streetNumber | street |
|----------------+----------------|
| 671 | Bristol Street |
| 789 | Madison Street |
| 880 | Holmes Lane |
+----------------+----------------+

Limitation
==========
Expand Down

0 comments on commit 578c6b2

Please sign in to comment.