Skip to content

Commit 08b5c43

Browse files
committed
Add doc for expand
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 9cb2ccb commit 08b5c43

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

docs/user/ppl/cmd/expand.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
PPL ``expand`` command
2+
=======================
3+
4+
Description
5+
-----------
6+
7+
Using ``expand`` command to flatten an array of nested type.
8+
9+
Syntax
10+
------
11+
12+
``expand <field> [As alias]``
13+
14+
- *field*: The field to be expanded (exploded). Currently only nested arrays are supported.
15+
- *alias*: (Optional) The name to use instead of the original field name.
16+
17+
Usage Guidelines
18+
----------------
19+
20+
The expand command produces a row for each element in the specified array or map field, where:
21+
22+
- Array elements become individual rows.
23+
- When an alias is provided, the exploded values are represented under the alias instead of the original field name.
24+
- This can be used in combination with other commands, such as ``stats``, ``eval``, and ``parse`` to manipulate or extract data post-expansion.
25+
26+
Examples
27+
--------
28+
29+
Given a dataset ``move`` with the following data:
30+
```
31+
{"name":"abbas","age":24,"address":[{"city":"New york city","state":"NY","moveInDate":{"dateAndTime":"19840412T090742.000Z"}}]}
32+
{"name":"chen","age":32,"address":[{"city":"Miami","state":"Florida","moveInDate":{"dateAndTime":"19010811T040333.000Z"}},{"city":"los angeles","state":"CA","moveInDate":{"dateAndTime":"20230503T080742.000Z"}}]}
33+
```
34+
The following query expand the address field and rename it to addr:
35+
36+
PPL query::
37+
38+
PPL> source=move | expand address as addr;
39+
fetched rows / total rows = 3/3
40+
+-------+-----+-------------------------------------------------------------------------------------------+
41+
| name | age | addr |
42+
|-------+-----+-------------------------------------------------------------------------------------------|
43+
| abbas | 24 | {"city":"New york city","state":"NY","moveInDate":{"dateAndTime":"19840412T090742.000Z"}} |
44+
| chen | 32 | {"city":"Miami","state":"Florida","moveInDate":{"dateAndTime":"19010811T040333.000Z"}} |
45+
| chen | 32 | {"city":"los angeles","state":"CA","moveInDate":{"dateAndTime":"20230503T080742.000Z"}} |
46+
+-------+-----+-------------------------------------------------------------------------------------------+

0 commit comments

Comments
 (0)