Data points
Each output is a single CDF data point mapped to a CDF time series. If the time series doesn’t exist, it will be created.type: Required, set to datapoint.externalId: The external ID of the time series to insert the data point into.space: The name of the data modeling space to write the data points to.timestamp: The timestamp of the data point is given as a millisecond Unix timestamp.value: The data point value as a number or a string. This may also benull, but only ifstatusis specified and a variant ofBad.status: Data point status code symbol as defined in the time series docs.isStep: The value ofisStepused when creating the time series for this datapoint if it does not already exist.
Events
Each output is a single CDF event. The old event will be updated if the provided event already exists and has an external ID. Null fields will be ignored when updating events. This is almost identical to the “Create event” payload to the Cognite API. See the API docs on events for details.type: Required, set to event.externalId: Required, the external ID of the event.startTime: The start time of the event, given as a millisecond Unix timestamp.endTime: The end time of the event, given as a millisecond Unix timestamp.eventType: Thetypefield of the event in CDF.subtype: Thesubtypefield of the event in CDF.description: Thedescriptionfield of the event in CDF.metadata: An object containing key/value pairs for event metadata. Both keys and values must be strings.assetIds: A list of asset external IDs to link the event to. If the assets do not exist, they will not be created.source: Thesourcefield of the event in CDF.
CDF RAW
Each output is a single raw row, which will be ingested directly into CDF RAW. The extractor may skip ingesting raw rows that haven’t changed since they were last seen.type: Required, set to raw_row.table: The RAW table to write to.database: The RAW database to write to.key: The key of the row to be written to RAW.columns: A JSON object containing the columns to be written to RAW.
Time series
Each output is a single time series. If the provided time series external ID already exists, then the old time series will be updated. Null fields will be ignored when updating events. This is almost identical to the “Create time series” payload to the Cognite API. See the API docs on time series for details.type: Required, set to time_series.externalId: Required, the external ID of the time series.name: The name of the time series.isString: Defines whether the time series contains string values (true) or numeric values (false). This value cannot be updated. Defaults to false.metadata: An object containing key-value pairs for time series metadata. Both keys and values must be strings.unit: The physical unit of the time series as free text.unitExternalId: The physical unit of the time series as represented in the unit catalog. Only available for numeric time series.assetId: Asset external ID to link the time series. If the asset does not exist, it will not be created.isStep: Whether the time series is a step series or not.description: Free text description of the time series.securityCategories: List of security categories required to access the created time series.
Data models
Each output is a node or edge, written to a single view. Values are overwritten. Your mapping can produce a list of nodes or edges. If multiple outputs have the same external ID and space, these are combined. This lets you simultaneously ingest data into multiple views. See the API docs for details.Nodes
type: Required, set to node.externalId: Required, the external ID of the node.space: Required, the space of the node.nodeType: A direct relation to a different node representing the type of this node.externalId: Required, type external ID.space: Required, type space.
view: Required, the view being written to.externalId: Required, view external ID.space: Required, view space.version: Required, view version.
properties: Required, a (maybe empty) object containing the properties being written, see API docs for the string representation of data modeling data types.
Edges
type: Required, set to edge.externalId: Required, the external ID of the node.space: Required, the space of the node.edgeType: Required, a direct relation to a node representing the type of this edge.externalId: Required, type external ID.space: Required, type space.
view: Required, the view being written to.externalId: Required, view external ID.space: Required, view space.version: Required, view version.
properties: Required, a (maybe empty) object containing the properties being written, see API docs for the string representation of data modeling data types.startNode: Required, the start node of the edge.externalId: Required, start node external ID.space: Required, start node space.
endNode: Required, the end node of the edge.externalId: Required, end node external ID.space: Required, end node space.
Example
This section explains how you can set up your own message formats for hosted extractors in CDF using the MQTT extractor as an example. The language you must use to transform the data is inspired by JavaScript. If you want a complete overview and descriptions of all the available functions, see All built-in functions.Single data point in a message
The section below describes how to set up message formats using a broker where the data comes in as values, and the topic indicates which sensor generated the value. For example, if you have a sensor that publishes the message/myhouse/groundfloor/livingroom/temperature and you want to map this
to a target in CDF. In this example, the data is ingested as a
data point in a time series, where the content is the value, the time the message
was received as the timestamp, and the topic path as the external ID of the time
series.
These are the input objects for defining the format:
input, which is the content of the message receivedcontext, which contains information about the message, such as which topic it arrived on
value: The value of the data point.timestamp: The timestamp for the data point given as a millisecond Unix timestamp. Use the built-innow()function to get the current time on this format.externalId: The external ID of the time series to insert this data point into.type: Set todatapointto tell the extractor that this JSON object describes a data point.
Handling more data in a single message
This section describes how to set up message formats while subscribing to a topic that contains the external ID of the time series getting the data, but the message payloads are now lists of data points instead of just a single value:input object. In the last example, you used the input object
directly, as the messages had no structure. This time, you can access attributes the
same way you might be familiar with from object-oriented languages. For example
input.sensorData[0].temperature will resolve to 21.4.
To ingest this data into CDF, you must make a data point for each element in the
sensorData list. Use a map function on input.sensorData.
map takes in a function and applies that function to each element in the list.
row is a name for the input of the map function. In this
case, for the first iteration of the map the row object will look like
map function should be
value, we map it to the temperature attribute of the row object.
Similarly, for timestamp, except that we need to parse the time format from a
string to a CDF timestamp. To do this, we use the to_unix_timestamp function,
which takes in the timestamp to convert, and a description of the format.
For the external ID of the time series to use, we do the same as in the previous
example and use the topic the message arrived at. And type can just be hard
coded to datapoint since we only ingest data points in this example.
Putting that all together, we end up with the following format description:
Nested structures
Finally, let’s look at a case where the data is nested with several lists. For example, let’s consider the case where a message contains a list of time series, each with a list of data points:sensorData list in the same way as
before:
map, the timeseries object will then be
values
list. Let’s attempt to use map again to do that:
map, the datapoint object will be
location and sensor attributes on the timeseries
object from the outer loop and join them together with the concat function.
Notice that in this inner loop, both the timeseries object from the outer
map and the datapoint object from the inner map are available.
Putting this all together, we get
map always works on a list and returns a new list. Since we
want our output to be a list of data points, we need to change the outter
map to a flatmap. flatmap is similar to map, except it flattens the
output, which means that it rolls out the list of lists to just a simple list:
Cookbook
This section contains examples of common patterns in payloads, and mappings to handle them.Single data point with ID
Each message is a single data point with ID:Multiple data points, single timestamp
A relatively common pattern is that a data point contains several measurements with a single timestamp.pairs: