Writing data to an output file
Suppose that you want to write the reduced data to an output file named SmallTrades.csv. You can use the FileSink operator to write data to a file. For this example, the input stream is the small data type transactions; there is no output stream for the FileSink operator.

The SPL code for the FileSink operator is shown.
Because the FileSink operator does not produce
an output stream, you specify "() as Sink
" before
the equals sign.
() as Sink = FileSink(SmallDataStream) {
param
file : "SmallTrades.csv";
format : csv;
}
In general, the FileSink operator writes tuples
to an output file specified by the file
parameter.
The format of the file is specified by the format
parameter.
For the csv
format, the FileSink operator
writes the file as a series of lines where each line is a list of comma-separated
values.
In this example, the FileSink operator performs the following steps.
- Receives a tuple from the input stream (
SmallDataStream
). - Writes the tuple as a comma-separated value to the output file
(
SmallTrades.csv
). - Repeats Steps 1 to 2 until all the tuples from the input stream are processed.