Skip to main content

Module import

Module import 

Source
Expand description

mushroomdb import: bulk load of a nodes CSV and a relationships CSV.

The header conventions are the widely used bulk-import ones:

  • nodes: :ID (the node key), :LABEL, then property columns;
  • relationships: :START_ID, :END_ID, :TYPE, then property columns;
  • a property column may carry a type suffix: age:int, weight:float, active:boolean, tags:string[]. No suffix means a string.

The data flows through the engine’s ordinary batch path (GraphDb::ingest for nodes, GraphDb::write_batch for edges), one WAL frame and one fsync per batch, so everything the engine guarantees about a committed batch holds here. What the import adds is what it leaves out: no auto-declared foreign-key rules (AutoFk::Off), no per-row dedupe round trips beyond one key lookup, and a single snapshot at the end.

§Rules

The import never declares a rule. Rules the store already has fire on each batch exactly as they do for any other write, so the final store is the one incremental ingest of the same rows produces. The fast route is to import into a store with no rules and declare them afterwards: create_rule backfills in one pass, and the differential test in crates/cli/tests/csv_import.rs pins that the two routes derive the same edges.

§Crash safety

Every batch is one atomic WAL frame, so an import killed part-way leaves a store that opens, holding every batch that committed and none of the one in flight. Derived (rule-owned) edges are not in the WAL; they are rebuilt on open from the base data, so an interrupted import loses no base data and the derived edges are whatever the committed base data derives. The snapshot that ends a successful import is written last; an import that dies before it simply has a longer WAL to replay. The import is not all-or-nothing: batches committed before an error or a crash stay.

Structs§

BatchProgress
One committed batch, reported to the callback of run_import_with_progress.
ColumnType
A property column’s declared type: a scalar, or an array of it.
ImportInputs
The files one import reads. Any of them may be absent; at least one is needed. They load in this order: nodes (CSV, then JSONL), edges (CSV, then JSONL), rules. A JSONL path of - reads standard input.
ImportOptions
Options for run_import.
ImportReport
What an import did.
NodeSchema
A parsed nodes-file header.
PropColumn
One property column of a header.
RelSchema
A parsed relationships-file header.

Enums§

ScalarType
The scalar type of a property column.

Constants§

DEFAULT_BATCH_SIZE
Default rows per committed batch.
JSONL_PROPS_FIELD
The property of a nodes.jsonl line that holds the properties whose names the line itself uses (key, label, and this one).

Functions§

check_quoting
Check that every quote in input follows RFC 4180: a quoted field opens at the start of a field, "" is a literal quote inside it, and the closing quote is followed by a delimiter or a line end. Returns the message, with its line, for the first violation.
format_import
The summary mushroomdb import prints.
import_inputs_into
import_into for every kind of input file.
import_into
The import itself, on a store the caller holds open and takes the snapshot of: run_import_with_progress is this plus the open and the snapshot. Public so a test can read the store while the importing handle is live.
json_to_exact_value
A JSON value as a stored Value, keeping a float a float.
parse_node_header
Parse a nodes-file header. Needs exactly one :ID and one :LABEL.
parse_node_row
Parse one node row into its label and property map, key included under schema.key_field. An empty property cell is an absent property.
parse_rel_header
Parse a relationships-file header. Needs exactly one each of :START_ID, :END_ID and :TYPE.
parse_rel_row
Parse one relationship row into (type, start, end, props).
run_import
Import nodes_csv and then rels_csv into the store at db_dir (created if absent). At least one file is required.
run_import_inputs
Import every file of inputs into the store at db_dir (created if absent), then take one snapshot.
run_import_with_progress
run_import, calling on_batch after every batch that committed.