generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 628
adding delete_source example #11512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AntonEliatra
wants to merge
1
commit into
opensearch-project:main
Choose a base branch
from
AntonEliatra:adding-more-options-to-csv-data-prepper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
adding delete_source example #11512
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,13 @@ The following table describes the options you can use to configure the `csv` pro | |
|
|
||
| Option | Required | Type | Description | ||
| :--- | :--- | :--- | :--- | ||
| source | No | String | The field in the event that will be parsed. Default value is `message`. | ||
| quote_character | No | String | The character used as a text qualifier for a single column of data. Default value is `"`. | ||
| delimiter | No | String | The character separating each column. Default value is `,`. | ||
| delete_header | No | Boolean | If specified, the event header (`column_names_source_key`) is deleted after the event is parsed. If there is no event header, no action is taken. Default value is true. | ||
| column_names_source_key | No | String | The field in the event that specifies the CSV column names, which will be automatically detected. If there need to be extra column names, the column names are automatically generated according to their index. If `column_names` is also defined, the header in `column_names_source_key` can also be used to generate the event fields. If too few columns are specified in this field, the remaining column names are automatically generated. If too many column names are specified in this field, the CSV processor omits the extra column names. | ||
| column_names | No | List | User-specified names for the CSV columns. Default value is `[column1, column2, ..., columnN]` if there are no columns of data in the CSV record and `column_names_source_key` is not defined. If `column_names_source_key` is defined, the header in `column_names_source_key` generates the event fields. If too few columns are specified in this field, the remaining column names are automatically generated. If too many column names are specified in this field, the CSV processor omits the extra column names. | ||
| `source` | No | String | The field in the event that will be parsed. Default value is `message`. | ||
| `quote_character` | No | String | The character used as a text qualifier for a single column of data. Default value is `"`. | ||
| `delimiter` | No | String | The character separating each column. Default value is `,`. | ||
| `delete_header` | No | Boolean | If specified, the event header (`column_names_source_key`) is deleted after the event is parsed. If there is no event header, no action is taken. Default value is true. | ||
| `column_names_source_key` | No | String | The field in the event that specifies the CSV column names, which will be automatically detected. If there need to be extra column names, the column names are automatically generated according to their index. If `column_names` is also defined, the header in `column_names_source_key` can also be used to generate the event fields. If too few columns are specified in this field, the remaining column names are automatically generated. If too many column names are specified in this field, the CSV processor omits the extra column names. | ||
| `column_names` | No | List | User-specified names for the CSV columns. Default value is `[column1, column2, ..., columnN]` if there are no columns of data in the CSV record and `column_names_source_key` is not defined. If `column_names_source_key` is defined, the header in `column_names_source_key` generates the event fields. If too few columns are specified in this field, the remaining column names are automatically generated. If too many column names are specified in this field, the CSV processor omits the extra column names. | ||
| `delete_source` | No | Boolean | If `true`, deletes the configured `source` field (default `message`) after CSV parsing. Default is `false`. | ||
|
|
||
| ## Usage | ||
|
|
||
|
|
@@ -97,6 +98,107 @@ Then, the processor parses the event into the following output. Because `delete_ | |
| {"message": "1,2,3", "a": "1", "b": "2", "c": "3"} | ||
| ``` | ||
|
|
||
| ### Delete the source field after parsing | ||
|
|
||
| If you want to remove the original `message` field once columns are extracted, enable `delete_source`. See following example: | ||
|
|
||
| ```yaml | ||
| csv-pipeline-delete-source: | ||
| source: | ||
| file: | ||
| path: "/full/path/to/ingest.csv" | ||
| record_type: "event" | ||
| processor: | ||
| - csv: | ||
| column_names: ["col1", "col2"] | ||
| delete_source: true # default is false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we need the comment here. |
||
| sink: | ||
| - opensearch: | ||
| hosts: ["https://opensearch:9200"] | ||
| insecure: true | ||
| username: admin | ||
| password: admin_pass | ||
| index_type: custom | ||
| index: csv-demo-%{yyyy.MM.dd} | ||
| ``` | ||
| {% include copy.html %} | ||
|
|
||
| The documents stored in OpenSearch contain the following information: | ||
|
|
||
| ```json | ||
| { | ||
| ... | ||
| "hits" : { | ||
| "total" : { | ||
| "value" : 2, | ||
| "relation" : "eq" | ||
| }, | ||
| "max_score" : 1.0, | ||
| "hits" : [ | ||
| { | ||
| "_index" : "csv-demo-2025.11.10", | ||
| "_id" : "vTgDb5oBcoMYUXV6ocPH", | ||
| "_score" : 1.0, | ||
| "_source" : { | ||
| "col1" : "1", | ||
| "col2" : "2", | ||
| "column3" : "3" | ||
| } | ||
| }, | ||
| { | ||
| "_index" : "csv-demo-2025.11.10", | ||
| "_id" : "vjgDb5oBcoMYUXV6ocPI", | ||
| "_score" : 1.0, | ||
| "_source" : { | ||
| "col1" : "4", | ||
| "col2" : "5", | ||
| "column3" : "6" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| If the `delete_source` is set to `false`, the documents would include the `message` field, see following example: | ||
|
|
||
| ```json | ||
| { | ||
| ... | ||
| "hits" : { | ||
| "total" : { | ||
| "value" : 2, | ||
| "relation" : "eq" | ||
| }, | ||
| "max_score" : 1.0, | ||
| "hits" : [ | ||
| { | ||
| "_index" : "csv-demo-2025.11.10", | ||
| "_id" : "fpAKb5oB85vgu48rA-rD", | ||
| "_score" : 1.0, | ||
| "_source" : { | ||
| "message" : "1,2,3", | ||
| "col1" : "1", | ||
| "col2" : "2", | ||
| "column3" : "3" | ||
| } | ||
| }, | ||
| { | ||
| "_index" : "csv-demo-2025.11.10", | ||
| "_id" : "f5AKb5oB85vgu48rA-rD", | ||
| "_score" : 1.0, | ||
| "_source" : { | ||
| "message" : "4,5,6", | ||
| "col1" : "4", | ||
| "col2" : "5", | ||
| "column3" : "6" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Metrics | ||
|
|
||
| The following table describes common [Abstract processor](https://github.com/opensearch-project/data-prepper/blob/main/data-prepper-api/src/main/java/org/opensearch/dataprepper/model/processor/AbstractProcessor.java) metrics. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also elaborate on the value here. We added this to help reduce memory pressure. So if you know you are going to drop the source after this processor, you can be better memory usage since processing happens in batches.