Mirexa

Wiki Guides

Bulk loading files

Loading candle history from CSV and Parquet files into Mirexa with mirexa-cli load — mapping columns, timestamps and streams, how rows are routed, what is skipped or refused, the report, and loading into a cluster.

mirexa-cli load loads candle files — CSV (plain, .gz, .zst, .tsv) and Apache Parquet — into a node or a cluster. It maps your columns onto bars, sorts out which stream each row belongs to, sends each through the write route that can store it, skips what is already stored, refuses what conflicts, and writes a report of exactly what happened. Running the same load twice loads nothing the second time and says so.

This page is the walkthrough; every flag is in the mirexa-cli load reference.

A first load

A vendor dump of one-minute bars, one stream, millisecond timestamps:

bash
./bin/cli load -stream binance:BTCUSDT:1m -ts-format unix-ms dump/*.csv.gz

With no -map, a CSV is read positionally as timestamp,open,high,low,close,volume (the same order as mirexa-cli ingest), and a Parquet file by column names (timestamp, open, high, low, close, volume). A directory argument loads every .csv, .csv.gz, .csv.zst and .parquet file in it, in name order.[1]

Rehearse first with -dry-run: it reads, maps and validates every row and reports, sending nothing. A real load needs both WRITE_CANDLES and READ_CANDLES, because it reads back what is stored; it checks the session's grant before sending anything.

Mapping columns

-map names where each field comes from, as field=source,...:[2]

Field Meaning
ts (or timestamp, time) the bar's timestamp
open, high, low, close, volume the values
exchange, symbol, timeframe the stream, per row

A source is a header name, a position #N (1-based), or a quoted constant 'binance'. -map-file reads the same pairs one per line.

bash
./bin/cli load \
    -map 'ts=open_time,open=o,high=h,low=l,close=c,volume=v,symbol=sym' \
    -exchange binance -timeframe 1m -ts-format rfc3339 vendor.parquet

Streams. Either give one stream for every row (-stream exchange:symbol:timeframe), or let rows name theirs through mapped columns, with -exchange, -symbol and -timeframe filling whatever no column provides. One file can therefore feed many streams; -parallel (default 4) streams are loaded at once.

Timestamps. -ts-format is required for CSV — unix-s, unix-ms, unix-us, unix-ns, rfc3339, or a Go time layout — because an integer read in the wrong unit is off by a factor of 1,000. A layout with no zone needs -tz (an IANA name). A Parquet TIMESTAMP column needs no format.[3] Timestamps must land on the stream's grid (Streams); a row off the grid is refused.

Headers. -header auto|yes|no (default auto); -delimiter overrides the separator (,, or tab for .tsv).

What happens to each row

For each stream, the loader reads back what the node already holds over the loaded window, then sorts every row:[4]

Row Outcome Reported as
Not stored Sent loaded
Already stored with the same values (at storage precision) Not sent skipped
Stored with different values Refused — a vendor dump never says which is right. With -correct, sent as a correction instead. refused, or corrected
An exact repeat of an earlier row in the files Not sent duplicates
Two rows for one timestamp that disagree All refused refused
Unreadable, invalid, or off the grid Refused with file and line refused
Carries more than four decimal places Sent; the store rounds it (default codec) counted in rounded

Routing. No route is the loader's own; each batch is an ordinary write:[5]

  • A stream that holds nothing is loaded through the history route, in batches of 10,000 rows, each acknowledged so nothing is left staged if the load stops.
  • Otherwise rows go as ordinary live writes, in batches spanning at most 1,024 slots, never straddling a bar already stored. A live write onto stored history restates, so a hole inside a stored chunk is filled and its gap closed.
  • A batch the node answers HistoryRequired (bars older than everything stored, or between chunks the cache cannot reach) is re-sent through the history route.
  • A batch whose outcome is ambiguous (the connection dropped mid-write) is reconciled by reading its window back, never re-sent blindly.

Every write is acknowledged: a loaded row is durable when the loader counts it.

The report

A summary goes to standard error. -report file.json (or - for standard output) writes a JSON report with, per stream: read, loaded, skipped, duplicates, refused (with each refusal's file, line and reason), rounded, corrected, history, the gaps the load closed and those still open in the loaded window, and any error that stopped the stream part way. For each stream, loaded + skipped + duplicates + refused equals read.

Exit status: 0 when everything loaded or was skipped, 2 when any row was refused, 1 when the load could not run at all (a file that cannot be opened stops the load before anything is sent).

Loading into a cluster

-addr takes a comma-separated list of any nodes of the cluster. The loader routes each stream to its partition's primary and follows redirects, and reads back from the primary (fresh reads), so its skip decisions see the latest data.

Limits

  • Candles only. There is no tick loader and no tick history route.
  • No export. mirexa-cli load loads; reading data out is a query.
  • The Parquet reader is linked into mirexa-cli for this command, never into the client libraries.
  • Each stream's rows are held in memory while that stream loads (they are read, sorted and deduplicated before sending), so a very large single-stream file needs memory in proportion (inferred from the source; unmeasured).

References

Source

Tests

Further reading

External

  • Apache Parquet file format — https://parquet.apache.org/docs/file-format/

  1. ExpandPaths and formatOf in /internal/bulkload/csv.go; DefaultMapping, DefaultNamedMapping in /internal/bulkload/mapping.go. ↩︎

  2. /internal/bulkload/mapping.go; the -map flag text in /cmd/cli/load.go. ↩︎

  3. ParseTimeFormat in /internal/bulkload/timestamp.go refuses an empty format. ↩︎

  4. loadStream, classify, dedupe in /internal/bulkload/load.go; Record.Rounded in /internal/bulkload/rows.go. ↩︎

  5. /internal/bulkload/send.go; historyBatch and liveBatch in /internal/bulkload/load.go. ↩︎