Skip to content

Commit 9bad864

Browse files
oeyhvagimelinatebower
authored
Update Data Prepper copy-values processor docs (#8586)
* Update copy-values processor docs Signed-off-by: Hai Yan <oeyh@amazon.com> * Update copy-values.md Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Co-authored-by: Nathan Bower <nbower@amazon.com> Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Co-authored-by: Nathan Bower <nbower@amazon.com> Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Co-authored-by: Nathan Bower <nbower@amazon.com> Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Co-authored-by: Nathan Bower <nbower@amazon.com> Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Signed-off-by: Melissa Vagi <vagimeli@amazon.com> * Update _data-prepper/pipelines/configuration/processors/copy-values.md Signed-off-by: Melissa Vagi <vagimeli@amazon.com> --------- Signed-off-by: Hai Yan <oeyh@amazon.com> Signed-off-by: Melissa Vagi <vagimeli@amazon.com> Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Co-authored-by: Nathan Bower <nbower@amazon.com>
1 parent 0eaf4fa commit 9bad864

File tree

1 file changed

+103
-21
lines changed

1 file changed

+103
-21
lines changed

_data-prepper/pipelines/configuration/processors/copy-values.md

Lines changed: 103 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,126 @@ The `copy_values` processor copies values within an event and is a [mutate event
1414

1515
You can configure the `copy_values` processor with the following options.
1616

17-
| Option | Required | Description |
18-
:--- | :--- | :---
19-
| `entries` | Yes | A list of entries to be copied in an event. |
20-
| `from_key` | Yes | The key of the entry to be copied. |
21-
| `to_key` | Yes | The key of the new entry to be added. |
22-
| `overwrite_if_to_key_exists` | No | When set to `true`, the existing value is overwritten if `key` already exists in the event. The default value is `false`. |
17+
| Option | Required | Type | Description |
18+
:--- | :--- | :--- | :---
19+
| `entries` | Yes | [entry](#entry) | A list of entries to be copied in an event. See [entry](#entry) for more information. |
20+
| `from_list` | No | String | The key for the list of objects to be copied. |
21+
| `to_list` | No | String | The key for the new list to be added. |
22+
| `overwrite_if_to_list_exists` | No | Boolean | When set to `true`, the existing value is overwritten if the `key` specified by `to_list` already exists in the event. Default is `false`. |
23+
24+
## entry
25+
26+
For each entry, you can configure the following options.
27+
28+
| Option | Required | Type | Description |
29+
:--- | :--- | :--- | :---
30+
| `from_key` | Yes | String | The key for the entry to be copied. |
31+
| `to_key` | Yes | String | The key for the new entry to be added. |
32+
| `overwrite_if_to_key_exists` | No | Boolean | When set to `true`, the existing value is overwritten if the `key` already exists in the event. Default is `false`. |
33+
2334

2435
## Usage
2536

26-
To get started, create the following `pipeline.yaml` file:
37+
The following examples show you how to use the `copy_values` processor.
38+
39+
### Example: Copy values and skip existing fields
40+
41+
The following example shows you how to configure the processor to copy values and skip existing fields:
42+
43+
```yaml
44+
...
45+
processor:
46+
- copy_values:
47+
entries:
48+
- from_key: "message1"
49+
to_key: "message2"
50+
- from_key: "message1"
51+
to_key: "message3"
52+
...
53+
```
54+
{% include copy.html %}
55+
56+
When the input event contains the following data:
57+
58+
```json
59+
{"message1": "hello", "message2": "bye"}
60+
```
61+
62+
The processor copies "message1" to "message3" but not to "message2" because "message2" already exists. The processed event contains the following data:
63+
64+
```json
65+
{"message1": "hello", "message2": "bye", "message3": "hello"}
66+
```
67+
68+
### Example: Copy values with overwrites
69+
70+
The following example shows you how to configure the processor to copy values:
2771

2872
```yaml
29-
pipeline:
30-
source:
31-
...
32-
....
73+
...
3374
processor:
3475
- copy_values:
3576
entries:
36-
- from_key: "message"
37-
to_key: "newMessage"
38-
overwrite_if_to_key_exists: true
39-
sink:
77+
- from_key: "message1"
78+
to_key: "message2"
79+
overwrite_if_to_key_exists: true
80+
- from_key: "message1"
81+
to_key: "message3"
82+
...
4083
```
4184
{% include copy.html %}
4285

43-
Next, create a log file named `logs_json.log` and replace the `path` in the file source of your `pipeline.yaml` file with that filepath. For more information, see [Configuring Data Prepper]({{site.url}}{{site.baseurl}}/data-prepper/getting-started/#2-configuring-data-prepper).
86+
When the input event contains the following data:
87+
88+
```json
89+
{"message1": "hello", "message2": "bye"}
90+
```
4491

45-
For example, before you run the `copy_values` processor, if the `logs_json.log` file contains the following event record:
92+
The processor copies "message1" to both "message2" and "message3", overwriting the existing value in "message2". The processed event contains the following data:
4693

4794
```json
48-
{"message": "hello"}
95+
{"message1": "hello", "message2": "hello", "message3": "hello"}
4996
```
5097

51-
When you run this processor, it parses the message into the following output:
98+
### Example: Selectively copy values between two lists of objects
99+
100+
The following example shows you how to configure the processor to copy values between lists:
101+
102+
```yaml
103+
...
104+
processor:
105+
- copy_values:
106+
from_list: mylist
107+
to_list: newlist
108+
entries:
109+
- from_key: name
110+
to_key: fruit_name
111+
...
112+
```
113+
{% include copy.html %}
114+
115+
When the input event contains the following data:
52116

53117
```json
54-
{"message": "hello", "newMessage": "hello"}
118+
{
119+
"mylist": [
120+
{"name": "apple", "color": "red"},
121+
{"name": "orange", "color": "orange"}
122+
]
123+
}
55124
```
56125

57-
If `newMessage` already exists, its existing value is overwritten with `value`.
126+
The processed event contains a `newlist` with selectively copied fields:
127+
128+
```json
129+
{
130+
"newlist": [
131+
{"fruit_name": "apple"},
132+
{"fruit_name": "orange"}
133+
],
134+
"mylist": [
135+
{"name": "apple", "color": "red"},
136+
{"name": "orange", "color": "orange"}
137+
]
138+
}
139+
```

0 commit comments

Comments
 (0)