elasticio / csv-component

CSV Reading and Writing component for elastic.io platform
Apache License 2.0
3 stars 7 forks source link

CircleCI

DEPRECATED COMPONENT. USE https://github.com/elasticio/csv-component-v3 instead

CSV Component

Description

A component to read and write Comma Separated Values (CSV) files.

How works

The component can read the CSV file from a remote URL or from the message attachment. It can also write a CSV file from the incoming events.

Requirements

Environment variables

Name Mandatory Description Values
EIO_REQUIRED_RAM_MB false Value of allocated memory to component Recommended: 512/1024
REQUEST_TIMEOUT false HTTP request timeout in milliseconds Default value: 10000
REQUEST_RETRY_DELAY false Delay between retry attempts in milliseconds Default value: 7000
REQUEST_MAX_RETRY false Number of HTTP request retry attempts Default value: 7
REQUEST_MAX_CONTENT_LENGTH false Max size of http request in bytes Default value: 10485760
TIMEOUT_BETWEEN_EVENTS false Number of milliseconds write action wait before creating separate attachments Default value: 10000

Credentials

The component does not require credentials to function.

Triggers

Read CSV file from URL

This trigger will fetch the CSV file from a given URL. The address must be accessible to the component. The fetched CSV file will be placed in the attachment part of the outgoing message.

Actions

Read CSV attachment

This action will read the CSV attachment of the incoming message or from the specified URL and output a JSON object. To configure this action the following fields can be used:

Write CSV attachment

This action will combine multiple incoming events into a CSV file until there is a gap of more than 10 seconds between events. Afterwards, the CSV file will be closed and attached to the outgoing message.

As part of the component setup, one must specify the columns of the CSV file. These columns will be published as the header in the first row. For each incoming event, the value for each header will be stringified and written as the value for that cell. All other properties will be ignored. For example, headers foo,bar along with the following JSON events:

{"foo":"myfoo", "bar":"mybar"}
{"foo":"myfoo", "bar":[1,2]}
{"bar":"mybar", "baz":"mybaz"}

will produce the following .csv file:

foo,bar
myfoo,mybar
myfoo,"[1,2]"
,mybar

When columns are added in the UI, you will be presented with an opportunity to provide a JSONata expression per column. If you require number formatting that is specific to a locale, the JSONata expression should handle that concern.

The output of the CSV Write component will be a message with an attachment. In order to access this attachment, the component following the CSV Write must be able to handle file attachments.

Write CSV attachment from JSON Object

This action will combine multiple incoming events into a CSV file until there is a gap of more than 10 seconds between events. Afterwards, the CSV file will be closed and attached to the outgoing message.

This action will convert an incoming array into a CSV file by following approach:

Requirements:

The keys of an input JSON will be published as the header in the first row. For each incoming event, the value for each header will be stringified and written as the value for that cell. All other properties will be ignored. For example, headers foo,bar along with the following JSON events:

{"inputObject": {"foo":"myfoo", "bar":"mybar"}}
{"inputObject": {"foo":"myfoo", "bar":[1,2]}}
{"inputObject": {"bar":"mybar", "baz":"mybaz"}}

will produce the following .csv file:

foo,bar
myfoo,mybar
myfoo,"[1,2]"
,mybar

The output of the CSV Write component will be a message with an attachment. In order to access this attachment, the component following the CSV Write must be able to handle file attachments.

Write CSV attachment from JSON Array

This action will convert an incoming array into a CSV file by following approach:

Requirements:

The keys of an input JSON will be published as the header in the first row. For each incoming event, the value for each header will be stringified and written as the value for that cell. All other properties will be ignored. For example, headers foo,bar along with the following JSON events:

{
    "inputArray": [
        {"foo":"myfoo", "bar":"mybar"}
        {"foo":"myfoo", "bar":[1,2]}
        {"bar":"mybar", "baz":"mybaz"}
    ]
}

will produce the following .csv file:

foo,bar
myfoo,mybar
myfoo2,[1,2]"
,mybar

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 order to access this attachment, the component following the CSV Write must be able to handle file attachments.

Limitations

General

  1. You may get Component run out of memory and terminated. error during run-time, that means that component needs more memory, please add 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.
  2. You may get Error: write after end error, as a current workaround try increase value of environment variable: TIMEOUT_BETWEEN_EVENTS.
  3. Maximal possible size for an attachment is 10 MB.
  4. Attachments mechanism does not work with Local Agent Installation