Read

The Read Stage can be used to read Sources, combine the values into an object, and optionally include the input event value. The Read Stage can pass parameters to Sources using static data or data from the input event.

This is useful for looking up data across sources. For example, an event may represent the state of a machine and include a batch identifier. The Read Stage can use the batchId to lookup batch information in the MES (ex. SQL) and then mix the result data with the raw event data.

Read Stage

Input Event Value

Specifies whether or not the input event.value should be included with the output value.

Option Description
Keep (Inline) Keeps the input value attributes in the output event inlined with the data read from the sources. No hierarchy is added.
Keep (With Key) Keeps the input value attributes in the output event under the attribute name provided by the Input Event Key. This adds one level of hierarchy to the output value.
Drop Drops the input value from the output value.

See examples below for how these settings impact the output event.

Sources

One or more sources to read. Each source has the following configuration.

Setting Description
Merge Read Value Controls how the read value is placed in the output value. Options are Inline, or With Key.
Reference A reference to the Source to read. References support passing parameters from the event (ex. Connection.mes.sqlInput(batchId={{event.value.batchId}})

Each source is read in parallel, and the stage completes when all sources have been read.

Example

Assume an event enters the stage in the following shape.

json
{
  "machineId": 123,
  "temp": 108.2,
  "pressure": 90.2
}

Assume the stage is configured to read two other sources, with the Merged Read Value set as described below.

mes: {{Connection.sql.input(machineid={{event.value.machineId}})}} | Inline erp: {{Connection.rest.erp}} | With Key set to “erp”

Below are example output events given the Input Event Value setting.

json
// Keep (Inline)
{
  "machineId": 123,       // input value is inline
  "temp": 108.2,
  "pressure": 90.2,
  "operatorId": 555,      // mes read is inline
  "startTime": 8720,
  "erp": {                // erp is under 'erp' key
    "orderId": 8820
  }
}

// Keep (With Key). Assume the key is `machine`
{
  "machine": {            // input value is under 'machine' key
    "machineId": 123,
    "temp": 108.2,
    "pressure": 90.2
  },
  "operatorId": 555,      // mes data is inline
  "startTime": 8720,
  "erp": {                // erp is under 'erp' key
    "orderId": 8820
  }
}

// Drop
{
  // event value is omitted
  "operatorId": 555,      // mes data is inline
  "startTime": 8720,
  "erp": {                // erp is under 'erp' key
    "orderId": 8820
  }
}

Read Stage Errors

If all sources are read and there is an attribute name conflict in the resulting output value, the stage produces an error. For example, if the input event has an attribute named myAttribute and is set to Inline, and a source reads data back that has an attribute named myAttribute and is also set to Inline, this produces a stage error. To resolve this, use a unique key for the input value or source.