|
1 | 1 | [](https://circleci.com/gh/elasticio/csv-component)
|
2 | 2 | # CSV Component
|
3 | 3 |
|
| 4 | +## Table of Contents |
| 5 | +* [Description](#description) |
| 6 | +* [How works](#how-works) |
| 7 | +* [Requirements](#requirements) |
| 8 | +* [Environment variables](#environment-variables) |
| 9 | +* [Credentials](#credentials) |
| 10 | +* [Actions](#actions) |
| 11 | + * [Read CSV attachment](#read-CSV-attachment) |
| 12 | + * [Create CSV From Message Stream](#create-CSV-from-message-stream) |
| 13 | + * [Create CSV From JSON Array](#create-CSV-from-JSON-array) |
| 14 | +* [Limitations](#limitations) |
| 15 | + |
4 | 16 | ## Description
|
5 | 17 |
|
6 | 18 | A component to read and write Comma Separated Values (CSV) files.
|
@@ -45,139 +57,70 @@ To configure this action the following fields can be used:
|
45 | 57 | * `Delimiter` - The delimiting character. Leave blank to auto-detect from a list of most common delimiters.
|
46 | 58 | * `Convert Data types` - numeric, date and boolean data will be converted to their type instead of remaining strings, false by default.
|
47 | 59 |
|
48 |
| -### Write CSV attachment |
49 |
| - |
50 |
| -* `Include Header` - this select configures output behavior of the component. If option is `Yes` or no value chosen than header of csv file will be written to attachment, this is default behavior. If value `No` selected than csv header will be omitted from attachment. |
51 |
| - |
52 |
| -This action will combine multiple incoming events into a CSV file until there is a gap |
53 |
| -of more than 10 seconds between events. Afterwards, the CSV file will be closed |
54 |
| -and attached to the outgoing message. |
55 |
| - |
56 |
| -As part of the component setup, one must specify the columns of the CSV file. |
57 |
| -These columns will be published as the header in the first row. For each incoming |
58 |
| -event, the value for each header will be `stringified` and written as the value |
59 |
| -for that cell. All other properties will be ignored. For example, headers |
60 |
| -`foo,bar` along with the following JSON events: |
61 |
| - |
62 |
| -``` |
63 |
| -{"foo":"myfoo", "bar":"mybar"} |
64 |
| -{"foo":"myfoo", "bar":[1,2]} |
65 |
| -{"bar":"mybar", "baz":"mybaz"} |
66 |
| -``` |
67 |
| - |
68 |
| -will produce the following `.csv` file: |
69 |
| - |
70 |
| -``` |
71 |
| -foo,bar |
72 |
| -myfoo,mybar |
73 |
| -myfoo,"[1,2]" |
74 |
| -,mybar |
75 |
| -``` |
76 |
| - |
77 |
| -When columns are added in the UI, you will be presented with an opportunity to |
78 |
| -provide a JSONata expression per column. If you require number formatting that |
79 |
| -is specific to a locale, the JSONata expression should handle that concern. |
80 |
| - |
81 |
| -The output of the CSV Write component will be a message with an attachment. In |
82 |
| -order to access this attachment, the component following the CSV Write must be |
83 |
| -able to handle file attachments. |
84 |
| - |
85 |
| -### Write CSV attachment from JSON Object |
86 |
| - |
87 |
| -* `Include Header` - this select configures output behavior of the component. If option is `Yes` or no value chosen than header of csv file will be written to attachment, this is default behavior. If value `No` selected than csv header will be omitted from attachment. |
88 |
| -* `Separator` - this select configures type of CSV delimiter in an output file. There are next options: `Comma (,)`, `Semicolon (;)`, `Space ( )`, `Tab (\t)`, `Pipe (¦)`. |
| 60 | +### Create CSV From Message Stream |
89 | 61 |
|
90 | 62 | This action will combine multiple incoming events into a CSV file until there is a gap
|
91 | 63 | of more than 10 seconds between events. Afterwards, the CSV file will be closed
|
92 | 64 | and attached to the outgoing message.
|
93 | 65 |
|
94 |
| -This action will convert an incoming array into a CSV file by following approach: |
95 |
| - |
96 |
| -* Header inherits names of keys from the input message; |
97 |
| -* Payload will store data from Values of relevant Keys (Columns); |
98 |
| -* Undefined values of a JSON Object won't be joined to result set (`{ key: undefined }`); |
99 |
| -* False values of a JSON Object will be represented as empty string (`{ key: false }` => `""`). |
100 |
| - |
101 |
| -Requirements: |
102 |
| - |
103 |
| -* The inbound message is an JSON Object, wrapped by 'inputObject' object; |
104 |
| -* This JSON object has plain structure without nested levels (structured types `objects` and `arrays` are not supported as values). Only primitive types are supported: `strings`, `numbers`, `booleans` and `null`. Otherwise, the error message will be thrown: `Inbound message should be a plain Object. At least one of entries is not a primitive type`. |
105 |
| - |
106 |
| -The keys of an input JSON will be published as the header in the first row. For each incoming |
107 |
| -event, the value for each header will be `stringified` and written as the value |
108 |
| -for that cell. All other properties will be ignored. For example, headers |
109 |
| -`foo,bar` along with the following JSON events: |
| 66 | +#### Config Fields |
110 | 67 |
|
111 |
| -``` |
112 |
| -{"inputObject": {"foo":"myfoo", "bar":"mybar"}} |
113 |
| -{"inputObject": {"foo":"myfoo", "bar":[1,2]}} |
114 |
| -{"inputObject": {"bar":"mybar", "baz":"mybaz"}} |
115 |
| -``` |
| 68 | +* `Upload CSV as file to attachments` - If checked store the generated CSV data as an attachment. If unchecked, place the CSV as a string in the outbound message. |
| 69 | +* `Separator` - A single char used to delimit the CSV file. Default to `,` |
| 70 | +* `Column Order` - A string delimited with the separator indicating which columns & in what order the columns should appear in the resulting file. If omitted, the column order in the resulting file will not be deterministic. Columns names will be trimmed (removed spaces in beginning and end of column name, for example: 'col 1,col 2 ,col 3, col 4' => ['col 1', 'col 2', 'col 3', 'col 4']) |
116 | 71 |
|
117 |
| -will produce the following `.csv` file: |
| 72 | +#### Input Metadata |
118 | 73 |
|
119 |
| -``` |
120 |
| -foo,bar |
121 |
| -myfoo,mybar |
122 |
| -myfoo,"[1,2]" |
123 |
| -,mybar |
124 |
| -``` |
| 74 | +* `Include Headers` - Indicates if a header row should be included in the generated file. |
| 75 | +* `Input Object` - Object to be written as a row in the CSV file. If the Column Order is specified, then individual properties can be specified. |
125 | 76 |
|
126 |
| -The output of the CSV Write component will be a message with an attachment. In |
127 |
| -order to access this attachment, the component following the CSV Write must be |
128 |
| -able to handle file attachments. |
| 77 | +#### Output Metadata |
129 | 78 |
|
130 |
| -### Write CSV attachment from JSON Array |
| 79 | +* If **Upload CSV as file to attachments** is checked: |
| 80 | + * `csvString` - The output CSV as a string inline in the body |
131 | 81 |
|
132 |
| -* `Include Header` - this select configures output behavior of the component. If option is `Yes` or no value chosen than header of csv file will be written to attachment, this is default behavior. If value `No` selected than csv header will be omitted from attachment. |
133 |
| -* `Separator` - this select configures type of CSV delimiter in an output file. There are next options: `Comma (,)`, `Semicolon (;)`, `Space ( )`, `Tab (\t)`, `Pipe (¦)`. |
| 82 | +* If **Upload CSV as file to attachments** is not checked: |
| 83 | + * `attachmentUrl` - A URL to the CSV output |
| 84 | + * `type` - Always set to `.csv` |
| 85 | + * `size` - Size in bytes of the resulting CSV file |
| 86 | + * `attachmentCreationTime` - When the attachment was generated |
| 87 | + * `attachmentExpiryTime` - When the attachment is set to expire |
| 88 | + * `contentType` - Always set to `text/csv` |
134 | 89 |
|
135 |
| -This action will convert an incoming array into a CSV file by following approach: |
| 90 | +### Create CSV From JSON Array |
136 | 91 |
|
137 |
| -* Header inherits names of keys from the input message; |
138 |
| -* Payload will store data from Values of relevant Keys (Columns); |
139 |
| -* Undefined values of a JSON Object won't be joined to result set (`{ key: undefined }`); |
140 |
| -* False values of a JSON Object will be represented as empty string (`{ key: false }` => `""`). |
| 92 | +This action will convert an incoming array into a CSV file |
141 | 93 |
|
142 |
| -Requirements: |
| 94 | +#### Config Fields |
143 | 95 |
|
144 |
| -* The inbound message is an JSON Array of Objects with identical structure, wrapped by 'inputArray' object; |
145 |
| -* Each JSON object for a message has plain structure without nested levels (structured types `objects` and `arrays` are not supported as values). Only primitive types are supported: `strings`, `numbers`, `booleans` and `null`. Otherwise, the error message will be thrown: `Inbound message should be a plain Object. At least one of entries is not a primitive type`. |
| 96 | +* `Upload CSV as file to attachments` - If checked store the generated CSV data as an attachment. If unchecked, place the CSV as a string in the outbound message. |
| 97 | +* `Separator` - A single char used to delimit the CSV file. Default to `,` |
| 98 | +* `Column Order` - A string delimited with the separator indicating which columns & in what order the columns should appear in the resulting file. If omitted, the column order in the resulting file will not be deterministic. |
146 | 99 |
|
147 |
| -The keys of an input JSON will be published as the header in the first row. For each incoming |
148 |
| -event, the value for each header will be `stringified` and written as the value |
149 |
| -for that cell. All other properties will be ignored. For example, headers |
150 |
| -`foo,bar` along with the following JSON events: |
| 100 | +#### Input Metadata |
151 | 101 |
|
152 |
| -``` |
153 |
| -{ |
154 |
| - "inputArray": [ |
155 |
| - {"foo":"myfoo", "bar":"mybar"} |
156 |
| - {"foo":"myfoo", "bar":[1,2]} |
157 |
| - {"bar":"mybar", "baz":"mybaz"} |
158 |
| - ] |
159 |
| -} |
160 |
| -``` |
| 102 | +* `Include Headers` - Indicates if a header row should be included in the generated file. |
| 103 | +* `Input Array` - Array of objects to be written as rows in the CSV file. (One row per object + headers) If the Column Order is specified, then individual properties can be specified. The component will throw an error when the array is empty. |
161 | 104 |
|
162 |
| -will produce the following `.csv` file: |
| 105 | +#### Output Metadata |
163 | 106 |
|
164 |
| -``` |
165 |
| -foo,bar |
166 |
| -myfoo,mybar |
167 |
| -myfoo2,[1,2]" |
168 |
| -,mybar |
169 |
| -``` |
| 107 | +* If **Upload CSV as file to attachments** is checked: |
| 108 | + * `csvString` - The output CSV as a string inline in the body |
170 | 109 |
|
171 |
| -The output of the CSV Write component will be a message with an attachment. There will be one CSV file generated per incoming message. In |
172 |
| -order to access this attachment, the component following the CSV Write must be |
173 |
| -able to handle file attachments. |
| 110 | +* If **Upload CSV as file to attachments** is not checked: |
| 111 | + * `attachmentUrl` - A URL to the CSV output |
| 112 | + * `type` - Always set to `.csv` |
| 113 | + * `size` - Size in bytes of the resulting CSV file |
| 114 | + * `attachmentCreationTime` - When the attachment was generated |
| 115 | + * `attachmentExpiryTime` - When the attachment is set to expire |
| 116 | + * `contentType` - Always set to `text/csv` |
174 | 117 |
|
175 |
| -### Limitations |
| 118 | +## Limitations |
176 | 119 |
|
177 |
| -#### General |
| 120 | +### General |
178 | 121 |
|
179 |
| -1. You may get `Component run out of memory and terminated.` error during run-time, that means that component needs more memory, please add |
| 122 | +* You may get `Component run out of memory and terminated.` error during run-time, that means that component needs more memory, please add |
180 | 123 | `EIO_REQUIRED_RAM_MB` environment variable with an appropriate value (e.g. value `1024` means that 1024 MB will be allocated) for the component in this case.
|
181 |
| -2. You may get `Error: write after end` error, as a current workaround try increase value of environment variable: `TIMEOUT_BETWEEN_EVENTS`. |
182 |
| -3. Maximal possible size for an attachment is 10 MB. |
183 |
| -4. Attachments mechanism does not work with [Local Agent Installation](https://docs.elastic.io/getting-started/local-agent.html) |
| 124 | +* Maximal possible size for an attachment is 10 MB. |
| 125 | +* Attachments mechanism does not work with [Local Agent Installation](https://docs.elastic.io/getting-started/local-agent.html) |
| 126 | +* Inbound message in `Message Stream` and each element of `JSON Array` should be a plain Object, if value not a primitive type it will be set as `[object Object]` |
0 commit comments