Previewing a mapping over a sample
Once a config is valid (see Checking a config before it is staged), preview_candidate runs a captured file of source records through the config's mapping, offline, and reports where it leaves gaps. The command form is:
python -m engine.mapping_preview_cli CONFIG NODE_TYPE_DIR SAMPLE
It uses the same transform a Node uses, with no database, broker, network or token. The sample is a JSON array or JSON lines file, and it is treated as the section's primary record.
The report finds seven kinds of gap:
- a subscribed key that nothing projects;
- a rule that no record can reach, because an earlier rule takes every record it would (see A rule that is never reached);
- a record that no rule matches;
- a canonical field left empty;
- a record field that nothing reads;
- a required event field left empty (only with
--event-type, which brings the event schema); - a flagged event: one whose own
statusisflagged, or, with--event-type, one that fails that event type's schema.
It also prints one note, which is not a gap: a rule set with no catch-all.
Options
--sectionnames the connector section (opcua,mqtt,database_logorrest). It can be left off when the config has exactly one.--identity-fieldis needed unless the Node Type fixes one (MES and Production Scheduling do).--shared-dirnames the shared fragments directory, if the config uses one.--event-typeapplies that event type's schema to each event and flags the ones that fail it. A Node does not apply one for MES today, so it is off unless asked for.
The report and its exit codes
The report names fields and counts them. It never prints a sample value or a value of the config, and it lists at most 20 records and 50 names in one place.
| Exit code | Meaning |
|---|---|
| 0 | No gaps. The note about a missing catch-all can still be printed. |
| 1 | A gap or a flagged event, including a rule that is never reached. |
| 2 | The config, Node Type directory or sample could not be used. |
A sample file is read by engine/sample_file.py, which allows at most 10 MiB and 10 000 records. The report itself is built by engine/gap_report.py.
A rule that is never reached
Rules are tried in order, and a when entry matches only an equal value. So a rule is never used when every entry of an earlier rule's when is among its own: any record that matches the later rule has already matched the earlier one. An earlier rule with an empty when does this to every rule after it.
rule 1 is never reached: rule 0 matches every record it would
- Rules are named by position, counting from 0. This is the count the offline check uses in
state_transition_rules.2.when. The report never prints awhen,thenorliteralsvalue. - The check reads the rules alone, so it does not depend on which records the sample holds. It runs for every section that has
state_transition_rules. - Equality is the transform's own, so the report and a Node agree.
1andTrueare the same value to both, and4and"4"are not. - A rule that is never reached is a gap: exit code 1. Move the more specific rule above the broader one, or delete it.
A rule set with no catch-all
A rule set in which no rule has an empty when prints a note, after the records:
note: no rule has an empty when, so a record no rule matches passes through unchanged
It is a note and not a gap, and it leaves the exit code alone. Whether a record that matches no rule should pass through unchanged is a choice for the site, and a trailing when={} rule is how to make the other choice (see section 4 of the Data Transformation Layer). A record that matches no rule is still counted as unmatched, and that is a gap. A section with a field_map and no rules prints no note.
Writing a source key once
To avoid writing a source key twice (once in the list a connector subscribes to, once in field_map), write one SourceKeyEntry per key and pass them to expand_source_keys.
- It returns both lists from the one set of entries, and refuses a subscribed key that nothing projects.
config_fragment()gives the primary record's keys to merge into the connector section. An OPC UA additional record'sextra_fieldsare inrecord_extra_fields, because the record's ownnode_idis yours to give.- It changes no config form. The result is the same
source_keysorextra_fieldsandfield_mapthat a config already holds.
A database_log sample
For a database_log section, a sample record is one row. It is keyed by the section's declared column names and holds the values as the connector converts them:
- timestamps as ISO 8601 UTC text;
numericas a string;byteaas base64;NULLasnull.
See database-log-scanning.md for the conversions. The easiest way to capture a row is --db-sample on the connection check (Checking a config before it is staged), which prints the newest row in that form.
The preview reports a source key that nothing projects, as for any section. A name the mapping reads that is not one of the section's columns is a finding of the offline check, because every row would give it as null. The preview shows it only as an empty field, when the sample file has no such key.
Release: v0.11.0