Process CSV with Embulk
A practical review of using Embulk to parse, type and convert CSV and TSV files: what it changes in your data, where meaning can drift, and when a simpler tool is the better choice.
Short verdict
Embulk suits repeatable, configuration-driven CSV jobs: loading many files the same way every time, converting CSV to TSV or another delimiter, or moving delimited data into a database or storage system through a plugin. Its main benefit is that parsing rules, column types and output formatting live in one reviewable config file instead of in ad hoc manual steps. The decisive tradeoff is that Embulk does not copy text through untouched. It parses each record into typed columns and writes it back out, so numbers, timestamps, empty values and quoting can come out different from how they went in. For a one-off conversion of a small file, or when the output must match the input character for character, a plain-text approach is usually safer and quicker. That could be a spreadsheet export, a small script, or Embulk with every column kept as a string.
What Embulk is, and how it differs from a simple converter
Embulk is an open-source bulk data loader built around plugins. A job reads input through an input plugin, such as local files, and interprets the bytes with a parser, such as the bundled CSV parser. It can optionally modify records with filters, then serializes them with a formatter and writes them through an output plugin. A basic text converter swaps one delimiter for another. Embulk instead turns every row into a record with named, typed columns, and that is the source of both its strengths and its risks.
In this context, 'transformation' means parsing and re-serializing delimited data. It does not mean reversing characters, mirroring glyphs or substituting styled Unicode characters. The stored characters of string values are normally carried across as they are. Values that you type as numbers or timestamps are rebuilt from their parsed meaning, though, so their text form can change.
A typical CSV-to-TSV job
The usual workflow has three steps. First, write a small seed config that points at the input files. Second, let Embulk guess the parser settings. Third, preview the parsed records before running the full job. The commands look like this:
embulk guess seed.yml -o config.yml
embulk preview config.yml
embulk run config.yml
Below is an illustrative config that reads comma-separated files with a header row and writes tab-separated output. The column names and formats are examples, not taken from any real dataset. Check option names against the documentation for the Embulk version you have installed, because plugin handling and defaults have changed between releases.
in:
type: file
path_prefix: ./data/orders_
parser:
type: csv
charset: UTF-8
newline: CRLF
delimiter: ','
quote: '"'
escape: '"'
skip_header_lines: 1
columns:
- {name: id, type: long}
- {name: postal_code, type: string}
- {name: amount, type: double}
- {name: ordered_at, type: timestamp, format: '%Y-%m-%d %H:%M:%S'}
out:
type: file
path_prefix: ./out/orders_
file_ext: tsv
formatter:
type: csv
delimiter: "\t"
header_line: true
quote_policy: MINIMAL
In this example, postal_code is declared as a string on purpose, as the next section explains.
What the job actually changes
Each column type affects your data differently:
| Column handling | What is stored in the output | Risk to meaning |
| string | The parsed text value, re-quoted according to the output quote policy | Low. Watch whitespace trimming on unquoted fields and how empty values are treated |
| long | An integer rebuilt from the parsed number | Leading zeros are lost, so identifiers such as postal codes or account numbers can be corrupted |
| double | A floating-point number written back as text | Decimal places, trailing zeros or exact representation can change; this matters for money |
| timestamp | A point in time re-formatted on output | Output format and time zone may differ from the input unless you set them explicitly in the formatter |
| boolean | A normalized true/false value | Source spellings such as yes/no or 1/0 may not round-trip as written |
| null handling | Values matching the configured null string become null | The difference between an empty string and a missing value can be blurred |
Delimiters and quoting are rewritten too. The output quote policy decides whether every field is quoted or only the fields that need it. Fields containing the new delimiter, quote characters or line breaks must be quoted or escaped to stay intact. This matters most when converting to TSV, because tabs inside a source field are easy to miss.
Character encoding is decoded on input and encoded again on output. A wrong input charset can damage text before any other step runs. Embulk does not reverse, mirror or restyle characters, but a mis-declared encoding produces garbled text that only looks like substitution.
Where meaning can drift
- Guessed types: the guess step infers types from sample rows. It can label an identifier column as a number or miss rare formats that appear later in the file. Review the generated columns before you rely on them.
- Invalid records: depending on settings, a row that does not fit the declared schema either stops the job or is skipped. Skipping keeps the run going but can silently drop data, so check record counts.
- Ragged rows: rows with extra or missing columns are handled according to options that allow extra or optional columns. Leaving those options loose can hide upstream problems.
- Time zones: timestamps without an explicit zone are interpreted using a default zone, and output is formatted with a default zone unless you configure one. That can shift displayed times.
- Headers: the input header is skipped by line count, not matched by name, and the output header comes from your column definitions. If column order changes upstream, labels and values can fall out of alignment without any error.
Will the output stay usable after sharing?
The output is ordinary delimited plain text, so copying, searching and editing work as they do for any CSV or TSV file. No visual-only styling is involved, and reading order is simply row by row, left to right in the file. Whether the result opens cleanly in a particular destination is a separate question. Spreadsheet applications, database import tools and analytics platforms each have their own rules for encoding detection, byte-order marks, delimiter detection and line endings. No scoped tests for specific destinations were available for this review. Do not assume that a file which opens correctly in one application will behave the same in another.
Accessibility depends on how the destination presents the table. A screen reader reads a delimited file opened as raw text very differently from the same data shown as a structured table. No assistive-technology testing was available here. If the output is meant for people rather than systems, provide it in a format whose table structure the receiving application exposes properly, and check it in that application.
Keep a plain-text, untyped copy alongside the converted output when the data serves as a record of what was received. That is easiest with every column defined as string, or by keeping the original file. Typed conversion is useful for loading data, but it is not a faithful archive.
When to choose something simpler
- A single small file that needs a delimiter change once: a spreadsheet export or a short script is less setup.
- Output that must match the input exactly apart from the delimiter: declare all columns as string in Embulk, or use a tool that does not parse values into types.
- Files with inconsistent structure from row to row: a typed, schema-based loader will fight the data, and cleaning it first in plain text may be easier.
- Recurring loads of many files with the same layout, or loads into databases and storage through plugins: this is where Embulk's config-driven approach pays off.
Evidence gaps
This review describes the documented design of Embulk's CSV parser and formatter and general principles of delimited data. No measurements, benchmarks, version-specific test runs or destination compatibility tests were supplied, so nothing here should be read as a verified performance or compatibility result. Before adopting Embulk for important data, run a preview and a small test job on a representative sample. Compare row counts and spot-check typed columns against the source. Confirm option names and defaults in the documentation for your installed version.