Class TextDelimited is a sub-class of {@link TextLine}. It provides direct support for delimited text files, like TAB (\t) or COMMA (,) delimited files. It also optionally allows for quoted values.
TextDelimited may also be used to skip the "header" in a file, where the header is defined as the very first line in every input file. That is, if the byte offset of the current line from the input is zero (0), that line will be skipped.
It is assumed if sink/source {@code fields} is set to either {@link Fields#ALL} or {@link Fields#UNKNOWN} and{@code skipHeader} or {@code hasHeader} is {@code true}, the field names will be retrieved from the header of the file and used during planning. The header will parsed with the same rules as the body of the file.
By default headers are not skipped.
TextDelimited may also be used to write a "header" in a file. The fields names for the header are taken directly from the declared fields. Or if the declared fields are {@link Fields#ALL} or {@link Fields#UNKNOWN}, the resolved field names will be used, if any.
By default headers are not written.
If {@code hasHeaders} is set to {@code true} on a constructor, both {@code skipHeader} and {@code writeHeader} willbe set to {@code true}.
By default this {@link cascading.scheme.Scheme} is both {@code strict} and {@code safe}.
Strict meaning if a line of text does not parse into the expected number of fields, this class will throw a {@link TapException}. If strict is {@code false}, then {@link Tuple} will be returned with {@code null} valuesfor the missing fields.
Safe meaning if a field cannot be coerced into an expected type, a {@code null} will be used for the value.If safe is {@code false}, a {@link TapException} will be thrown.
Also by default, {@code quote} strings are not searched for to improve processing speed. If a file isCOMMA delimited but may have COMMA's in a value, the whole value should be surrounded by the quote string, typically double quotes ( {@literal "}).
Note all empty fields in a line will be returned as {@code null} unless coerced into a new type.
This Scheme may source/sink {@link Fields#ALL}, when given on the constructor the new instance will automatically default to strict == false as the number of fields parsed are arbitrary or unknown. A type array may not be given either, so all values will be returned as Strings.
By default, all text is encoded/decoded as UTF-8. This can be changed via the {@code charsetName} constructorargument.
To override field and line parsing behaviors, sub-class {@link DelimitedParser} or provide a{@link cascading.scheme.util.FieldTypeResolver} implementation.
Note that there should be no expectation that TextDelimited, or specifically {@link DelimitedParser}, can handle all delimited and quoted combinations reliably. Attempting to do so would impair its performance and maintainability.
Further, it can be safely said any corrupted files will not be supported for obvious reasons. Corrupted files may result in exceptions or could cause edge cases in the underlying java regular expression engine.
A large part of Cascading was designed to help users cleans data. Thus the recommendation is to create Flows that are responsible for cleansing large data-sets when faced with the problem
DelimitedParser maybe sub-classed and extended if necessary.
@see TextLine