CSV File Writer Output Adapter

Introduction

The CSV File Writer adapter is suitable for saving tuples to comma-separated value (CSV) format files.

There are a number of options that help the user control how and when files are created, how big files may be, and how strings are are saved in the file.

Hint: In the StreamBase application that contains the CSV File Writer adapter, if the output CSV file will be used by an application that requires a specific order of fields, and the fields in the stream's tuples do not match that order, you can use a Map operator to arrange the fields as needed.

Properties

Property Description Default
File Name Name of file to write to. If this adapter is configured with a maximum file size, then this filename is appended with the date and time if the maximum file size is reached.

Note

Normally, the file is written to the directory that the application is in, which is the default working directory for running StreamBase applications.

To change the target directory, you can either add relative or absolute path information with to the file name, or edit the launch configuration used with your application to change the working directory (as described in Editing Launch Configurations.)

sample.csv
Max File Size Maximum size, in bytes, of the file on disk. If the file reaches this limit, it is renamed with the current timestamp and new data is written to the current name specified in the File Name property. 0 (no rollover)
Max Roll Seconds

The maximum number of seconds before file names are rolled over as described above.

Note

Role Period and Max Roll Seconds properties are mutually exclusive.

0 (no rollover)
Roll Period The rolling of the file can be done Weekly, Daily and Hourly.
  • Weekly rolling is done at 12:00 AM on every Monday. If the program started in between the week the rolling will be done from next Monday at 12:00 AM onwards. When rolling is done the file is renamed by appending with the previous weeks starting date (Monday) in the format 'yyyyMMdd'.

  • Daily rolling is done at 12:00 AM on every day. If the program started in the day, file rolling will be done at 12:00 AM from the next day onwards. When rolling is done the file is renamed by appending with the date in the format 'yyyyMMdd'.

  • Hourly rolling is done for every hour.(Eg.1:00 AM,2:00AM.....). If the program starts at 1:20 PM the rolling will be done at 2:00 PM onwards every hour. When rolling is done the file is renamed by appending with the timestamp in the format 'yyyyMMddHHmm'.

None
Flush Interval How often, in seconds, to force tuples to disk. Set this value to zero to flush immediately. 1
Sync on flush Checkbox. If checked, StreamBase syncs operating system buffers to the file system on flush, to make sure that all changes are written. Using this options incurs a significant performance penalty. false (unchecked)
Include Header In File Include an optional row at the top of each file with the name of each column. true
If File Doesn't Exist Action to take if the specified CSV file does not exist when the adapter is started: Create new file or Fail. Create new file
If File Exists Action to take if the specified CSV file already exists when the adapter is started: Append to existing file, Truncate existing file, or Fail. Append to existing file
Field Delimiter Character used to mark the end of one field and the beginning of another. Control characters can be entered as &#ddd; where ddd is the character's ASCII value. , (comma)
String Quote Character Character to use to quote strings when they contain the field delimiter. "
String Quote Option Determines when string fields are quoted in the CSV file: Quote if necessary, Always quote, or Never quote. Quote if necessary
Null Value Representation String to write when a field is null. null
Throttle Error Messages Only show a given error message once. false

Typechecking and Error Handling

Typechecking fails in the following circumstances:

  • The File Name is null or a zero length string.

  • The Flush Interval is less than zero.

  • The Max File Size is less than zero.

  • More than one string quote character is specified.

  • More than one field delimiter is specified.

  • An illegal string quote option is specified.

  • The Max Roll Seconds value greater than zero and the Roll Period option selected is other than None.

Suspend/Resume Behavior

On suspend, this adapter stops processing tuples, flushes all tuples to disk, and closes the current CSV file.

On resumption, it reopens the current CSV file and begins processing tuples again.