Prerequisites
Before migrating events to records, complete the following:- Enable the
migrateandrecords-migratealpha flags in yourcdf.tomlfile:
cdf.toml
-
Provision a target stream with sufficient record and storage capacity. See Choose and size streams for planning guidance.
cdf migrate events-to-recordsvalidates stream capacity before it runs and raises an error if the stream does not exist or has insufficient capacity. -
Deploy one or more containers with
usedFor: recordin the target space.
Required capabilities
The following capabilities are required to runcdf migrate events-to-records:
Migrating events to records
Migrate human-created events (work orders, inspections, maintenance records) to data modeling nodes instead of records. See Migrating events.
cdf migrate events-to-records.
1
Create the YAML config file
Define the target stream and property mappings. See Config file.
2
Choose how to select events
Use data set selection with a
defaultMapping, or CSV file selection to map specific events, such as status events in the Kelmarsh example.3
Run `cdf migrate events-to-records`
Pass
--config-file and either --data-set-id or --mapping-file, or run without selection flags for interactive mode. See cdf migrate events-to-records --help.4
Verify the migration
Query the target stream and confirm that records exist for the selected events. See Verify the migration.
Config file
Unlike other migration commands,cdf migrate events-to-records requires a --config-file YAML that defines the target stream and property mappings.
The config file names one or more mappings by externalId and maps source event fields to record container properties. Use defaultMapping when every event in a data set shares the same mapping, or when CSV rows omit ingestionMapping.
Replace the placeholder values in the example below with your target stream, container, and field mappings.
events_to_records.config.yaml
streamExternalId: External ID of the target stream. The stream must already exist.resourceType: Must beevent.defaultMapping: MappingexternalIdto use when--data-set-idis set, or when a CSV row omitsingestionMapping.mappings: Named mappings.propertyMappingmaps source event field names to container property names.
Data set selection
To migrate all events in a data set, run:<path to config yaml> with a path relative to your Cognite Toolkit project root. Replace <data set id> with the integer internal ID of the asset-centric source data set. The config file must include defaultMapping, because all events in the data set use the same mapping.
To select the data set interactively, run:
cdf migrate events-to-records --help for details.
CSV file selection
To migrate events using a CSV mapping file, run:<path to config yaml> and <path to csv file> with paths relative to your Cognite Toolkit project root.
This CSV file migrates a Kelmarsh wind farm status event:
migration.events_to_records.csv
space: The space of the resulting record.externalId: The external ID of the resulting record.id: The integer internal ID of the source event to migrate.
ingestionMapping: MappingexternalIdfrom the config file for this row. If omitted, the config filedefaultMappingis used. Unlikecdf migrate events, there are noconsumerViewSpace,consumerViewExternalId, orconsumerViewVersioncolumns.
Verify the migration
Query the target stream and confirm that records exist for the migrated events. In CDF, open the stream in Data management, or query record count through the Streams API. Use--skip-existing to query the target stream before uploading and skip records that already exist. This helps resume a partially completed migration without creating duplicate records.
See cdf migrate events-to-records --help for the full list of options, including --dry-run, --log-dir, --yes, and --verbose.
What cdf migrate events-to-records does
When you run cdf migrate events-to-records, the migration plugin performs the following steps on batches of events:
1
Download events
The Cognite Toolkit reads events from the asset-centric
/events/byids or /events/list endpoints, depending on the selection method.2
Map event fields to record properties
The Cognite Toolkit applies the mapping from the config file
mappings section. propertyMapping maps source event field names to target container property names.
Each event uses the mapping from the CSV ingestionMapping column, the --data-set-id defaultMapping, or the config file defaultMapping.3
Write records to the target stream
The Cognite Toolkit writes migrated records to the target stream through the Streams API.
4
Skip existing records (optional)
When
--skip-existing is set, the Cognite Toolkit queries the target stream first and skips records that already exist.