In some cases you may have flat files with "empty" flat file records that do not contain any data but just e.g. the field separators like in the picture below.

You can skip these empty records, and there are two different ways to do that.

Handle Empty Records Using a Pattern

On the flat file record, specify a pattern in attribute pattern that only matches with records having data. The example below shows a flat file definition using the regular expression supposing that a record has data if it does not start with a separator.

The flat file parser aborts parsing when parsing a record that does not match any of the flat file record definitions. This is why you need to specify a dedicated class for the empty records (EmptyLine) as well.

  • Class EmptyLine has no pattern. It matches all records, including the records containing data. Therefore it is important to set the evaluation order on this record to ensure that it will be parsed last.
  • EmptyLine has no attributes defined and therefore no fields are parsed. To avoid having records without content, set ignoreEmptyRecords to true on this class.

Ignore Empty Strings and Records

You can use a combination of ignoreEmptyStrings and ignoreEmptyRecords on the flat file record to omit empty records.

  • Ignoring empty strings will lead to the Flat File adapter processing empty strings to NULL,
  • and ignoring empty records will lead to the Flat File adapter not processing a record, if it has no data.

Be aware of the fact, that a record containing only empty strings does in fact contain (empty) data - in contrast to a record composed from NULLs.
This method will also filter records that contain empty strings.

  • No labels