FlatFileWriter

Available in Community Designer

Short Description
Ports
Metadata
FlatFileWriter Attributes
Details
Examples
Best Practices
Compatibility
See also

Short Description

FlatFileWriter writes data to flat files. The output flat file can be in form of CSV (character separated values), fixed-length format or mixed-length format (combination of mixed-length and fixed-length formats).

The component supports partitioning, compression, writing to output port or to remote destination.

UniversalDataWriter is an alias for FlatFileWriter.

Component Data output Input ports Output ports Transformation Transf. required Java CTL Auto-propagated metadata
FlatFileWriterflat file10-1
no
no
no
no
no

Icon

Ports

Port typeNumberRequiredDescriptionMetadata
Input0
yes
for received data records any
Output0
no
for port writing. See Writing to Output Port. include specific byte/ cbyte/ string field

Metadata

FlatFileWriter does not propagate metadata.

The component has no metadata template.

FlatFileWriter requires string, byte or cbyte field in the output metadata.

FlatFileWriter Attributes

AttributeReqDescriptionPossible values
Basic
File URL
yes
where the received data to be written (flat file, output port, dictionary) specified, see Supported File URL Formats for Writers.  
Charset 

Character encoding of records written to the output.

The default encoding depends on DEFAULT_CHARSET_DECODER in defaultProperties.

ISO-8859-1 | UTF-8 | <other encodings>
Append 

If records are printed into an existing non-empty file, they replace the older ones by default (false).

If set to true, new records are appended to the end of the existing output file(s) content.

Some remote locations or compressed files do not support appending. See Appending to Files.

false (default) | true
Quoted strings When switched to true, all field values (except from byte and cbyte) will be quoted. If you do not set this attribute, its value is inherited from metadata on the input port (and displayed in faded grey text, see also Record Details). false | true
Quote character Specifies which kind of quotes will enclose output fields. Applies if Quoted strings is true only. By default, the value of this attribute is inherited from metadata on input port. See also Record Details. " | '
Advanced
Create directories if set to true, non-existing directories in the File URL attribute path are created false (default) | true
Write field names Field labels are not written to the output file(s) by default. If set to true, labels of individual fields are printed to the output. Please note field labels differ from field names: labels can be duplicate and you can use any character in them (e.g. accents, diacritics). See Record Pane. false (default) | true
Records per file Maximum number of records to be written to each output file. If specified, the dollar sign(s) $ (number of digits placeholder) must be part of the file name mask, see Supported File URL Formats for Writers1 - N
Bytes per file Maximum size of each output file in bytes. If specified, the dollar sign(s) $ (number of digits placeholder) must be part of the file name mask, see Supported File URL Formats for Writers To avoid splitting a record into two files, max size can be slightly overreached. 1 - N
Number of skipped records how many records/rows to be skipped before writing the first record to the output file, see Selecting Output Records. 0 (default) - N
Max number of records  how many records/rows to be written to all output files, see Selecting Output Records. 0-N
Exclude fields  Sequence of field names separated by semicolon that will not be written to the output. Can be used when the same fields serve as a part of Partition key.  
Partition key [ 1] sequence of field names separated by semicolon defining the records distribution into different output files - records with the same Partition key are written to the same output file. According to the selected Partition file tag use the proper placeholder ($ or #) in the file name mask, see Partitioning Output into Different Output Files  
Partition lookup table[ 2] ID of lookup table serving for selecting records that should be written to output file(s). See Partitioning Output into Different Output Files for more information.  
Partition file tag[ 1] By default, output files are numbered. If it is set to Key file tag, output files are named according to the values of Partition key or Partition output fields. See Partitioning Output into Different Output Files for more information. Number file tag (default) | Key file tag
Partition output fields[ 2] Fields of Partition lookup table whose values serve to name output file(s). See Partitioning Output into Different Output Files for more information.  
Partition unassigned file name Name of the file into which the unassigned records should be written if there are any. If not specified, data records whose key values are not contained in Partition lookup table are discarded. See Partitioning Output into Different Output Files for more information. 
Sorted input  In case of partitioning into multiple output files is turned on, all output files are open at once. Which could lead to undesirable memory footprint for many output files (thousands). Moreover, for example unix-based OS usually have very strict limitation of number of simultaneously open files (1024) per process. In case you run into one of these limitations, consider sorting the data according to partition key using one of our standard sorting components and set this attribute to true. The partitioning algorithm does not need to keep open all output files, just the last one is open at one time. See Partitioning Output into Different Output Files for more information. false (default) | true
Create empty files If set to false, prevents the component from creating empty output file when there are no input records.true (default) | false
Skip last record delimiter  If set to true, the last record delimiter in a file is not written. If set to false, the last record delimiter in a file is written. false (default) | true

[ 1] Either both or neither of these attributes must be specified

[ 2] Either both or neither of these attributes must be specified

Details

The type of formatting is specified in metadata for the input port data flow.

Appending to Files

Appending to files is supported, if you write data to:

  • local files

  • local zipped files

  • remote files via smb protocol

Appending to files is not supported in, if you write data to:

  • local gzipped files

  • remote files via ftp protocol

  • remote files via webdav protocol

  • remote files via Amazon S3 protocol

  • remote files via hdfs protocol

Null Values

Empty strings and null values are written to file as empty strings.

Notes and Limitations

Field Size Limitation

FlatFileWriter can write fields of a size up to 4kB.

  • To enable bigger fields to be written into a file, increase the DataFormatter.FIELD_BUFFER_LENGTH property, see Chapter 18, Engine Configuration. Enlarging this buffer does not cause any significant increase of the graph memory consumption.

  • Another way how to solve the big-fields-to-be-written issue is the utilization of the Normalizer component that can split large fields into several records.

Maps and Lists

FlatFileWriter cannot write maps and lists. If you do not need a field with map or list datatype in the output file, you can omit it using Exclude fields attribute. If you need to write the content of the map or list field, convert the field into string using Reformat first.

Examples

Writing Records to File
Producing Quoted Strings
Writing Records Without Delimiters
Writing Fixed-Length Records to Output Port

Writing Records to File

Write records to a file objects.txt using FlatFileWriter. The input metadata fields are color, shape and material.

Solution

Use attribute File URL to define path to the file to be created.

AttributeValue
File URL${DATAOUT_DIR}/objects.txt

The example of output file, delimited input metadata:

grey|cylinder|steel
brown|cube|wood
transparent|sphere|glass

The separators "|" depend on metadata on the input edge.

The example of output file, fixed input metadata:

grey           cylinder      steel
brown          cube          wood
transparent    sphere        glass

Producing Quoted Strings

Write data from the previous example to a file. Each field value has to be surrounded by quote character ' (apostrophe).

Solution

Use attributes File URL, Quoted strings and Quote character.

AttributeValue
File URL${DATAOUT_DIR}/objects-in-quotes.txt
Quoted stringstrue
Quote character'

If a string to be quoted contains a quote character, the quote character in the string is doubled. E.g. o'clock is quoted as 'o''clock'.

Writing Records Without Delimiters

This example shows writing records without writing record delimiters.

You receive output from XMLWriter in a streaming mode. The records have to be seamlessly written to the file. No delimiter should be written between the records.

Solution

The solution to the problem depends on metadata. The input metadata of FlatFileWriter must have no Record delimiter, no Default delimiter, and must use EOF as delimiter.

In FlatFileWriter, enter File URL.

The records will be written without delimiters as no delimiters are specified in metadata.

Writing Fixed-Length Records to Output Port

Write several fields of fixed-length metadata into one field of output port (provided one input record creates one output record).

Solution

Make sure that input metadata has no record delimiter set. Select metadata on the input edge and open Edit Metadata window. Select the first row in the Record pane of the editor and make sure that the Record delimiter property is empty.

Create metadata on the output edge with a single field.

Use attributes File URL and Records per file.

AttributeValue
File URLport:$0.field1:discrete
Records per file1

Best Practices

We recommend users to explicitly specify encoding of output file (with Charset attribute). It ensures better portability of the graph across systems with different default encoding.

The recommended encoding is UTF-8.

Compatibility

4.1.0-M1

Since release 4.1.0-M1 can be skipped last record delimiters in a file.

4.2.0-M1

FlatFileWriter is available since CloverETL 4.2.0-M1. In 4.2.0-M1, UniversalDataWriter was renamed to FlatFileWriter.

See also

FlatFileWriter
UniversalDataReader
Common Properties of Components
Specific Attribute Types
Common Properties of Writers
Writers Comparison