Skip to content

Commit 45ccc8a

Browse files
github-actions[bot]Naarcha-AWSkolchfa-awsnatebower
committed
SubList function documentation (#9718)
* SubList function documentation * Sublist function documentation Signed-off-by: Sai charan raj Gudala <s.charancherry22@gmail.com> * Add writer edits. Break up examples. Use function in pipeline. Signed-off-by: Naarcha-AWS <97990722+Naarcha-AWS@users.noreply.github.com> * Apply suggestions from code review Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Update _data-prepper/pipelines/sublist.md Signed-off-by: Nathan Bower <nbower@amazon.com> --------- Signed-off-by: Sai charan raj Gudala <s.charancherry22@gmail.com> Signed-off-by: Naarcha-AWS <97990722+Naarcha-AWS@users.noreply.github.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Signed-off-by: Nathan Bower <nbower@amazon.com> Co-authored-by: Naarcha-AWS <97990722+Naarcha-AWS@users.noreply.github.com> Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Co-authored-by: Nathan Bower <nbower@amazon.com> (cherry picked from commit a2dd9ba) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7fba371 commit 45ccc8a

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

_data-prepper/pipelines/functions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ OpenSearch Data Prepper offers a range of built-in functions that can be used wi
1717
- [`hasTags()`]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/has-tags/)
1818
- [`join()`]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/join/)
1919
- [`length()`]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/length/)
20+
- [`subList()`]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/sublist/)
2021
- [`startsWith()`]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/startswith/)
22+

_data-prepper/pipelines/sublist.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
layout: default
3+
title: subList()
4+
parent: Functions
5+
grand_parent: Pipelines
6+
nav_order: 35
7+
---
8+
9+
# subList(<key>, <start_index, inclusive>, <end_index, exclusive>)
10+
11+
The `subList()` function extracts a sublist from a list field in an event. It takes the following arguments:
12+
13+
- A JSON pointer to an event field containing a list
14+
- A start index (inclusive)
15+
- An end index (exclusive)
16+
17+
The function returns the portion of the list between the specified start and end indexes. If the end index is `-1`, the function extracts elements from the start index to the end of the list.
18+
19+
20+
## Examples
21+
22+
The following examples show how the `sublist()` function works.
23+
24+
### add_entries processor
25+
26+
You can use `subList()` in the `add_entries` processor, as shown in the following example.
27+
28+
The function uses the following input to extract a sublist:
29+
30+
```
31+
input: {"my_list": [ 0, 1, 2, 3, 4, 5, 6]}
32+
```
33+
34+
Then, the following configuration uses the `add_entries` processor to extract a sublist from `my_list`, starting at index `1` and ending before index `4`:
35+
36+
```yaml
37+
add_entries:
38+
entries:
39+
- key: "my_list"
40+
value_expression: '/subList(/my_list, 1, 4)'
41+
overwrite_if_key_exists: true
42+
```
43+
{% include copy.html %}
44+
45+
The following output shows the resulting list after extracting elements from index `1` to `3` and overwriting the original list:
46+
47+
```
48+
output: my_list: [1, 2, 3]
49+
```
50+
51+
### Specific ranges
52+
53+
Each of the following examples demonstrates how the `subList()` function extracts a specific range of elements from a list.
54+
55+
The following example extracts elements from index `0` to `2` (excluding index `3`), resulting in the first three elements of the list:
56+
57+
```json
58+
{
59+
"event": {
60+
"/my_list": [0, 1, 2, 3, 4, 5, 6]
61+
},
62+
"expression": "subList(/my_list, 4, -1)",
63+
"expected_output": [4, 5, 6]
64+
}
65+
```
66+
{% include copy.html %}
67+
68+
The following example uses `-1` as the end index, which specifies to include all elements from index `4` to the end of the list:
69+
70+
```json
71+
{
72+
"event": {
73+
"/my_list": [0, 1, 2, 3, 4, 5, 6]
74+
},
75+
"expression": "subList(/my_list, 4, -1)",
76+
"expected_output": [4, 5, 6]
77+
}
78+
```
79+
{% include copy.html %}

0 commit comments

Comments
 (0)