graflo.hq.bulk.fold¶
Fold staged runs by identity in DuckDB: one row per vertex and per edge.
The rules are the upsert's, applied once to the whole load (the file backend's read-side fold applies the same ones):
- per field, the value of the latest row (largest
seq) that carries it; a field a later row lacks keeps its earlier value; merge: unionfields take the members of every row inseqorder, each once, nulls dropped;- an edge's endpoint documents fold the same way as its properties.
Rows whose key occurs once pass through; only repeated keys are exploded into
one row per field and reduced. Edges whose endpoint is not a folded vertex are
rejected with their reason, as are edges owned through an owner_field whose
owner is not a folded vertex. DuckDB spills to the staging directory under the
memory limit it is given.
Output, in the staging directory: folded/<slot>.jsonl.zst sorted by key
(an edge run split into cells is a directory instead, see
:func:folded_cell), rejects/, and counts.json.
Attributes¶
COUNTS = 'counts.json'
module-attribute
¶
FOLDED = 'folded'
module-attribute
¶
Classes¶
FoldCounts
¶
Bases: BaseModel
Every run of a fold, vertices first.
Source code in graflo/hq/bulk/fold.py
RunCounts
¶
Bases: BaseModel
One run's rows: staged, after the fold, rejected, and its dense-id range.
Source code in graflo/hq/bulk/fold.py
Attributes¶
buckets = None
class-attribute
instance-attribute
¶
Buckets per endpoint of an edge run split into cells.
dense = None
class-attribute
instance-attribute
¶
folded
instance-attribute
¶
rejected
instance-attribute
¶
slot
instance-attribute
¶
staged
instance-attribute
¶
type
instance-attribute
¶
Functions:¶
counts_json(staging_dir)
¶
fold(staging_dir, *, dense_ids=False, edge_buckets=None, memory_limit=None, threads=None)
¶
Fold every staged run of staging_dir; write the folded runs and counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
staging_dir
|
Path
|
A directory a :class: |
required |
dense_ids
|
bool
|
Number every folded vertex |
False
|
edge_buckets
|
int | None
|
Split each edge run into cells by a hash of its source and target keys into this many buckets each. |
None
|
memory_limit
|
str | None
|
DuckDB's memory limit ( |
None
|
threads
|
int | None
|
DuckDB worker threads; its default when omitted. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The |
Source code in graflo/hq/bulk/fold.py
folded_cell(staging_dir, slot, cell)
¶
The files of one cell (source bucket, target bucket) of an edge run.