Import and export file rules
The formats and sizes the import and export commands take, how an import reads each kind of value, how it matches records, and what it reports when it stops.
marfa rows import, marfa rows export, marfa items import and marfa items export move one table's rows or one type's items through a file. Import a spreadsheet into a table, Import a file as items and Export rows or items to a spreadsheet show the steps, and marfa rows import --help lists every option. The rules are in the contract's CLI chapter.
Files
| Import | Export | |
|---|---|---|
| Formats | CSV, TSV, JSON (a list of objects), JSON Lines, Excel .xlsx | CSV, TSV, JSON, JSON Lines |
| Format chosen by | --format, or the file's extension | --format, or the extension of --output, or CSV |
| Text | UTF-8, or the encoding --encoding names. A byte order mark is removed | UTF-8 with no byte order mark. A CSV ends each line with CRLF |
| Size | 64 MiB, 100,000 records and 5,000,000 cells. A workbook may expand to 256 MiB | No limit |
- A workbook with several sheets needs
--sheet. - A header row that leaves a column unnamed, or names two alike, is refused.
- Text that isn't valid in its encoding is refused, never read as another encoding.
How a value is read
An import never guesses a value. A record with a value that doesn't fit its column is refused alone, with its line, its column and the reason, and the other records are saved.
| Value | Read as |
|---|---|
| Date | YYYY-MM-DD. Another layout needs --, made of YYYY, MM, DD, HH, mm and ss |
| Date and time | Needs a zone. --time-zone names the zone for times written without one |
| Text | Kept as written, leading zeros included |
| Whole number | Exact. A number past 9007199254740991 is refused: keep it as text |
| Boolean | true or false only |
| List or object | JSON text, in a CSV or TSV cell |
| Workbook date | An ISO date |
| Workbook formula | Its saved result. A formula with no saved result, or an error cell, is refused |
| Blank cell | Changes nothing, or clears the value with --blanks clear |
A new table's columns come from the file. --new-table gives each column the first kind every value fits, or string, and --kind Header=kind sets one. A column whose values read as dates in another layout stays string, and the preview prints the --kind and --date-format that make it a date column.
Matching records
| Option | Finds a record's row or item by |
|---|---|
--match-key <header> | The column's value. For rows it is a column of the table. For items it is the item's ID at the source import:<type>/<name>, where --as gives the name |
--match-id <header> | A column of Marfa IDs, as an export writes |
| Neither | Rows go only into an empty table. An item import matches a column of item IDs headed id |
- Refused records: two records with one key, a blank key, and an ID that matches no row or item.
- A column of the file that matches no column or field stops the import until
--mapsends it somewhere or--skipleaves it out. - Records that already say what Marfa holds are counted as unchanged and not written.
What an import saves
An import reads the whole file, shows a preview, and saves on a yes at a terminal or with --yes. --preview never saves. Both exit 1 when a record is refused.
- A row or item that changed after the preview is left as it is and reported as changed since the preview, and the command exits
1. For a row, that means a column the import writes. For an item, it means a field, or its tags when the file changes them. - An import can't prevent three things. Two writers that add a row with the same key at the same moment make two rows. An edit to a column the import doesn't write is kept and not reported. A write that a working copy queued offline lands later.
A stopped import
A large import is saved in several requests, so it isn't all or nothing.
- Ctrl-C stops between requests, prints what was saved and what wasn't tried, and exits
130. - After a request whose answer was lost, a row import reads what the table holds before it adds any row again. A record it can't settle is reported as one that may or may not be saved.
- The report prints the command that finishes the import when running it again can't add a record twice. A stopped import of rows with no key prints none, and says that
--match-keyprevents it. - A wait the server asks for is printed and then waited. An import stops when the wait is longer than 5 minutes.
Export
- Rows are written as
id, then the table's columns in their declared order. - Items are written as
id, the type's fields in order, thentags. Items of a subtype are left out and counted. --typeand--filterinclude archived items and leave out the bin.--viewwrites what the view's saved query lists.--guard-formulasputs an apostrophe before each text cell that starts with=,+,-,@, a tab or a carriage return, and counts them. It is refused for JSON and JSON Lines.- An unchanged export imported with
--match-id idchanges nothing.