Contents
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.
| 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.
NoteNormally, 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. NoteRole 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.
|
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 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.
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.
