Read CSV files in Apache NiFi
How the NiFi CSVReader parses CSV and TSV into records, which settings decide whether your data survives intact, and when to leave files as plain content instead.
Apache NiFi reads CSV through a controller service called CSVReader, which record-oriented processors use to turn delimited text into structured records. This review covers what that conversion changes, which settings decide whether the data keeps its meaning, and when you should not parse the file at all. It relies on NiFi's documented behavior and general CSV principles. No benchmark or test results were supplied, so performance and version-specific behavior are marked as things to verify in your own environment.
Is the CSVReader the right choice for your flow?
Use CSVReader when you need to work with the contents of a CSV or TSV file: filter rows, convert to JSON, Avro or Parquet, validate fields, run SQL-style queries, or load rows into a database. The main benefit is that one reader configuration can be shared by many processors, and those processors handle all the rows in a file as a single record set instead of splitting the file into one FlowFile per line.
The main tradeoff is that parsing reinterprets the text. Delimiters, quoting, headers, null markers and data types all become decisions that can quietly change values if they are set wrong. A misconfigured reader often does not fail. It can produce well-formed records that hold the wrong data.
Leave the file as plain content when NiFi only needs to move, archive, compress, encrypt or route it by attributes such as filename. Parsing adds no value in those cases and adds a risk of altering the bytes if the file is written back out. Plain handling is also the safer default when the file's dialect is unknown and the downstream system already parses CSV itself.
What reading a CSV file actually changes
In NiFi, reading and parsing are separate steps. A processor such as GetFile, or the ListFile and FetchFile pair, brings the file in as FlowFile content and leaves the bytes untouched. Parsing happens only when a record-aware processor, such as ConvertRecord, QueryRecord, UpdateRecord, ValidateRecord, SplitRecord or PutDatabaseRecord, is configured to use a CSVReader. The reader splits each line into fields according to the configured format and maps those fields to a schema.
The stored characters change only when a record writer serializes the records again. Even if you use CSVRecordSetWriter to write CSV back out, the output is a new rendering rather than the original file. Quoting style, line endings, header text, null representation and number or date formatting can all differ from the input, even when every value is logically the same.
Settings that determine meaning
- Schema Access Strategy: decides where field names and types come from. You can take string fields from the header line, infer a schema from the data, or supply an explicit schema by name, as text, or from a schema registry.
- CSV Format: presets such as RFC 4180, Microsoft Excel, Tab-Delimited and MySQL, plus Custom Format, which lets you set the value separator, quote character, escape character and other options yourself.
- Value Separator: a comma for CSV, a tab for TSV, or another delimiter that appears in your data.
- Treat First Line as Header and Ignore CSV Header Column Names: decide whether the first line is data and whether its names override the schema.
- Quote Character and Escape Character: decide whether a delimiter or line break inside a field stays inside that field.
- Null String and Trim Fields: decide which text counts as missing and whether surrounding whitespace is kept.
- Character Set: must match the file's real encoding or non-ASCII text will be misread.
- Date, Time and Timestamp Format: decide how text is parsed into temporal types when the schema calls for them.
The exact property names and options available depend on your NiFi version, including which parser implementations the reader offers. Check the CSVReader documentation that ships with your installation rather than relying on any single description.
Header strings versus inferred or explicit schemas
| Approach | What you get | Main risk |
| String fields from header | Every column is a string named after the header | Downstream systems must cast types themselves |
| Inferred schema | Types guessed from the data | Guesses may not match intent, for example codes with leading zeros read as numbers |
| Explicit schema | Names and types you define | Must be kept in sync when the file layout changes |
For data you will load into typed systems, an explicit schema is the most predictable option. Reading header fields as strings is the most conservative choice for exploration, because it keeps the original text of every value. Inference is convenient, but review its results against representative files before relying on it, especially for identifiers, postal codes, phone numbers and mixed-type columns. Whether a given inferred type drops leading zeros or changes precision should be confirmed with your own sample data. The supplied material does not establish it.
A basic example flow
A common pattern for reading a CSV file and converting it to JSON uses three processors and two controller services. The property values below are illustrative and assume a comma-delimited file with a header row in UTF-8. They are not a tested configuration.
ListFile -> watches an input directory
FetchFile -> loads each listed file as FlowFile content
ConvertRecord
Record Reader: CSVReader
Record Writer: JsonRecordSetWriter
CSVReader
Schema Access Strategy : Use String Fields From Header
CSV Format : Custom Format
Value Separator : ,
Treat First Line as Header : true
Quote Character : "
Character Set : UTF-8
For a TSV file, change the value separator to a tab or pick the tab-delimited format preset. To filter or reshape rows before writing, replace ConvertRecord with QueryRecord or UpdateRecord, using the same reader.
Will the output stay usable downstream?
The parsed data is only as reliable as the match between the reader settings and the actual file. These are the most common places where meaning or usability breaks:
- Embedded delimiters and line breaks: quoted fields can legitimately contain commas or newlines. A record reader with the correct quote character handles them. Line-based splitting with SplitText does not, and will cut such records apart.
- Encoding and byte order marks: a file saved with a byte order mark or in a legacy encoding can corrupt the first header name or non-ASCII characters if the character set is wrong. Test with real exports from the source system.
- Inconsistent rows: rows with more or fewer fields than the header, duplicate header names, or blank trailing lines can produce errors or misaligned values. Route failures to a separate relationship so you can inspect them instead of losing them.
- Null versus empty: decide whether an empty field means an empty string or a missing value, and set the null string to match what downstream systems expect.
- Re-serialized output: if the destination needs the original file byte for byte, for audit or checksum reasons, keep a copy of the unparsed content. A written record set is not a substitute for it.
Some destinations, such as spreadsheet tools, specific databases or a partner's import routine, may have their own CSV expectations. Their compatibility should be confirmed against that destination's documentation or a scoped test with a sample file. One successful import does not prove the configuration works for every consumer.
Gaps in this review
No version-specific release notes, throughput measurements, memory figures or test results were available for this article. Claims about performance on large files, the exact set of parser options, and how type inference treats particular values in your NiFi release should be checked against the documentation bundled with your installation and against a small, representative test flow before going to production.