civex.match_files_to_records
Match each file to an existing child record by extracting a key value from the filename. If a matching record is found, its file field is updated (a file field's file is replaced; a file_list field gains the file, once); if not, a new record is created with the key and file field set. The field must be a file or file_list field of the schema. Reach for this when files arrive that may correspond to records created by an earlier step (e.g. civex.rows_to_records from a sample sheet), rather than always creating new records.
Plugin ID: civex.match_files_to_records
Category: outputs
Capabilities: read, write_records
Config
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
schema |
string | yes | The kind of record each file goes on: one inside the record the workflow runs on. In the YAML, schema:. |
|
pattern |
string | yes | Which part of a file's name says which record it belongs to. Build it from an example. | |
key_field |
string | yes | The field of those records the key is compared with, e.g. a selection number. | |
file_field |
string | yes | The file field of the matching record. | |
dataset |
string | no | "" | Dataset to search and create records in. Empty string falls back to the trigger record's own dataset. |
parent_record_id |
string | no | "" | Parent record ID to scope matching and creation to. Empty string falls back to the trigger record's ID. |
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
files |
files | yes | The files to put on records. Each goes on the record its name says. |
Outputs
| Name | Type | Required | Description |
|---|---|---|---|
created |
number | yes | How many records it made, because none matched. |
updated |
number | yes | How many records it gave a file. |
unmatched |
list | yes | The file names it found no key in, or whose record could not be made. |
ambiguous |
list | yes | Files left alone because another file in the same run has the same key (one record holds one file), each with the files it clashes with. |
Make the pattern read the whole number
A pattern like sample_([0-9]{2}) reads exactly two digits, so samples 14, 142
and 149 all give the key 14. Use sample_([0-9]+) (any number of digits). When
two or more files in one run give the same key, none of them is attached,
because a record holds one file and there is no telling which is meant. They
are listed in the ambiguous output, each with the files it clashes with, and
the run says how many there were.
Note
Numeric captures are normalised (e.g. "042" → "42") before matching so that integer fields match correctly.
Match photo files like sample_042_photo.jpg to Sample records with number = 42: