HIDDEN StructuredDataWriter
Short Description
StructuredDataWriter writes data to files (local or remote, delimited, fixed-length, or mixed) with a user-defined structure. It can also compress output files and write to an output port, or dictionary.
StructuredDataWriter
structured flat file
1-3
0-1
x
x
x
x
x
Ports
Input
0
✓
Records for body
Any
Input
1
x
Records for header
Any
Input
2
x
Records for footer
Any
Output
0
x
One field (byte
, cbyte
, string
).
Metadata
StructuredDataWriter does not propagate metadata.
StructuredDataWriter has no metadata templates.
Metadata on an output port has one field (byte
, cbyte
or string
).
StructuredDataWriter Attributes
Basic
File URL
yes
Charset
Encoding of records written to the output.
UTF-8 (default) | <other encodings>
Append
By default, new records overwrite the older ones. If set to true
, new records are appended to the older records stored in the output file(s).
false (default) | true
Body mask
A mask used to write the body of output file(s). It can be based on the records received through the first input port. For more information about the definition of Body mask and resulting output structure, see Masks and Output File Structure below.
Default Body Structure -see below (default) | user-defined
Header mask
[1]
A mask used to write the header of output file(s). It can be based on the records received through the second input port. For more information about the definition of Header mask and resulting output structure, see Masks and Output File Structure below.
empty (default) | user-defined
Footer mask
[2]
A mask used to write the footer of output file(s). It can be based on the records received through the third input port. For more information about the definition of Footer mask and resulting output structure, see Masks and Output File Structure below.
empty (default) | user-defined
Advanced
Create directories
By default, non-existing directories are not created. If set to true
, they are created.
false (default) | true
Records per file
The maximum number of records to be written to one output file.
1-N
Bytes per file
The maximum size of one output file in bytes.
1-N
Number of skipped records
0-N
Max number of records
0-N
Partition key
Partition lookup table
[1]
Partition file tag
Number file tag (default) | Key file tag
Partition output fields
[1]
Partition unassigned file name
Sorted input
false (default) | true
Create empty files
If set to false
, prevents the component from creating an empty output file when there are no input records.
true (default) | false
[1] Must be specified if the second input port is connected. However, it does not need to be based on input data records.
[2] Must be specified if third input port is connected. However, does not need to be based on input data records.
Details
StructuredDataWriter can write a header, data and a footer (exactly in this order) without need to handle graph phases.
Masks and Output File Structure
Output File Structure
An output file consists of a header, body, and footer, in this order.
Each of them is defined by specifying corresponding mask.
Having defined the mask, the mask content is written repeatedly, one mask is written for each incoming record.
If the Records per file attribute is defined, the output structure is distributed among various output files, but this attribute applies to Body mask only. The header and footer are the same for all output files.
Defining a Mask
Body mask, Header mask and Footer mask can be defined in the Mask dialog. This dialog opens after clicking a corresponding attribute row. In its window, you can see the Metadata and Mask panes.
You can define the mask either without field values or with field values.
Field values are referred using field names preceded by a dollar sign.
You do not have to map all input metadata fields.
Output can contain additional text not coming from input metadata. E.g. Return address
on figure above.
You can use StructuredDataWriter to generate XML files or to fill in the template.
Default Masks
Default Header mask is empty. But it must be defined if the second input port is connected.
Default Footer mask is empty. But it must be defined if the third input port is connected.
Default Body mask is empty. However, the resulting default body structure looks like the following:
This structure is written to output file(s) for all records.
If Records per file is set, only the specified number of records are used for body in each output file at most.
Notes and Limitations
StructuredDataWriter cannot write lists and maps.
Examples
Writing Page with Header and Footer
Legacy application requires data in the following file structure: header, up to five data records and blank line. Convert data to format accepted by the legacy application:
Solution
Connect an edge providing particular records to the first input port of StructuredDataWriter (metadata field body) and edge providing a header to the second input port (metadata field header).
Edit the attributes:
File URL
${DATOUT_DIR}/file_$$.txt
Body mask
$body
Header mask
$header
Footer mask
Records per file
5
Adjust the line break in the Body mask, Header mask and Footer mask attributes according to the input records. If input records have a line break, do not add a line break after the string $body
and $header
. If input records do not have a line break, add a line break after $body
and $header
; fill in the line break to the attribute Footer mask too.
Best Practices
We recommend users to explicitly specify Charset.
Troubleshooting
If you partition unsorted data into many output files, you may reach the limit of simultaneously opened files. This can be avoided by sorting the input and using the attribute sorted input.